1
Action Requests / Re: get File Name From Path
« on: June 06, 2019, 10:46:06 AM »
It works great. Thank you Jean!

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Count the number of pixels of a certain color")]
[HelpUrl("http://hutonggames.com/playmakerforum/index.php?topic=11929.0")]
public class CountColoredPixelsInTextures : ArrayListActions
{
[ActionSection("Input")]
public FsmTexture texture;
public FsmColor colorToCount;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmInt storeResult;
[ActionSection("Event")]
[UIHint(UIHint.FsmEvent)]
public FsmEvent doneEvent;
[UIHint(UIHint.FsmEvent)]
[Tooltip("The event if error")]
public FsmEvent failureEvent;
private Color[] pix;
private Texture2D targetmaskedTexture;
public override void Reset()
{
storeResult = null;
failureEvent = null;
doneEvent= null;
texture = null;
}
public override void OnEnter()
{
bool noError = false;
if (texture.IsNone){
Debug.LogWarning("<color=#6B8E23ff>No texture. Please review!</color>", this.Owner);
noError = true;
}
targetmaskedTexture = null;
targetmaskedTexture = texture.Value as Texture2D;
try
{
targetmaskedTexture.GetPixel(0, 0);
}
catch(UnityException)
{
Debug.LogWarning("<color=#6B8E23ff>Please enable read/write on texture </color>"+"[" + texture.Value.name + "]", this.Owner);
noError = true;
}
if (noError == true){
Fsm.Event(failureEvent);
return;
}
else {
storeResult.Value = 0;
pix = targetmaskedTexture.GetPixels(0);
for (int i = 0; i < pix.Length; i++)
{
if (colorToCount.Value == pix[i]) {
storeResult.Value = storeResult.Value + 1;
}
}
pix = new Color[0];
}
Fsm.Event(doneEvent);
return;
}
}
}
// (c) Jean Fabre, 2011-2013 All rights reserved.
// http://www.fabrejean.net
// INSTRUCTIONS
// Drop a PlayMakerArrayList script onto a GameObject, and define a unique name for reference if several PlayMakerArrayList coexists on that GameObject.
// In this Action interface, link that GameObject in "arrayListObject" and input the reference name if defined.
// Note: You can directly reference that GameObject or store it in an Fsm variable or global Fsm variable
// credits: action created by LampRabbit: http://hutonggames.com/playmakerforum/index.php?topic=3982.msg18550#msg18550
using System;
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Store mesh vertex positions into an arrayList")]
public class ArrayListGetVertexPositions2 : ArrayListActions
{
[ActionSection("Set up")]
[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;
[Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component ( necessary if several component coexists on the same GameObject")]
public FsmString reference;
[ActionSection("Source")]
[Tooltip("the GameObject to get the mesh from")]
[CheckForComponent(typeof(MeshFilter))]
public FsmGameObject mesh;
public bool worldSpace;
public override void Reset()
{
gameObject = null;
reference = null;
mesh = null;
worldSpace = false;
}
public override void OnEnter()
{
if ( SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
getVertexPositions();
Finish();
}
public void getVertexPositions()
{
if (! isProxyValid())
return;
proxy.arrayList.Clear();
GameObject _go = mesh.Value;
if (_go==null)
{
return;
}
MeshFilter _mesh = _go.GetComponent<MeshFilter>();
if (_mesh ==null)
{
return;
}
if (worldSpace)
{
for (int i = 0; i < _mesh.mesh.vertices.Length; i++)
{
proxy.arrayList.Add(_mesh.transform.TransformPoint(_mesh.mesh.vertices[i]));
}
}
else
{
proxy.arrayList.InsertRange(0, _mesh.mesh.vertices);
}
}
}
}
// (c) Jean Fabre, 2011-2013 All rights reserved.
// http://www.fabrejean.net
// INSTRUCTIONS
// Drop a PlayMakerArrayList script onto a GameObject, and define a unique name for reference if several PlayMakerArrayList coexists on that GameObject.
// In this Action interface, link that GameObject in "arrayListObject" and input the reference name if defined.
// Note: You can directly reference that GameObject or store it in an Fsm variable or global Fsm variable
// credits: action created by LampRabbit: http://hutonggames.com/playmakerforum/index.php?topic=3982.msg18550#msg18550
using System;
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Store mesh vertex positions into an arrayList")]
public class ArrayListGetVertexPositions : ArrayListActions
{
[ActionSection("Set up")]
[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;
[Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component ( necessary if several component coexists on the same GameObject")]
public FsmString reference;
[ActionSection("Source")]
[Tooltip("the GameObject to get the mesh from")]
[CheckForComponent(typeof(MeshFilter))]
public FsmGameObject mesh;
public override void Reset()
{
gameObject = null;
reference = null;
mesh = null;
}
public override void OnEnter()
{
if ( SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
getVertexPositions();
Finish();
}
public void getVertexPositions()
{
if (! isProxyValid())
return;
proxy.arrayList.Clear();
GameObject _go = mesh.Value;
if (_go==null)
{
return;
}
MeshFilter _mesh = _go.GetComponent<MeshFilter>();
if (_mesh ==null)
{
return;
}
proxy.arrayList.Clear();
for (int i = 0; i < _mesh.mesh.vertices.Length; i++) {
proxy.arrayList.Add(_mesh.transform.TransformPoint(_mesh.mesh.vertices[i]));
}
//proxy.arrayList.InsertRange(0,_mesh.mesh.vertices);
}
}
}
string onlyFileName = System.IO.Path.GetFileName(entirePath);
public void closestColor3(Color32 target){
float hue1 = getHue (target.r, target.g, target.b);
var num1 = ColorNum(target);
float minimaDiferenciaColores = 10000;
string key="";
int flag = 0;
int index = 0;
Color valor; Color32 valor32; Color colorParecido = new Color();
foreach (DictionaryEntry colorDeLaLista in listaNcs.hashTable) {
flag++;
float Rvalor = float.Parse (colorDeLaLista.Value.ToString ().Substring (5, 5));
float Gvalor = float.Parse (colorDeLaLista.Value.ToString ().Substring (12, 5));
float Bvalor = float.Parse (colorDeLaLista.Value.ToString ().Substring (19, 5));
valor = new Color (Rvalor,Gvalor,Bvalor);
valor32 = (Color32)valor;
float diferenciaColores = Math.Abs(ColorNum(valor) - num1) + getHueDistance(getHue(valor32.r, valor32.g, valor32.b), hue1);
if (diferenciaColores < minimaDiferenciaColores) {
minimaDiferenciaColores = diferenciaColores;
key = colorDeLaLista.Key.ToString ();
index = flag;
colorParecido = valor;
}
}
img_NCS.color = colorParecido;
txt_NCS.text = key;
}
foreach (DictionaryEntry colorInTheList in NcsList.hashTable) {
Debug.Log(colorInTheList.Value) //it prints RGBA(0,0,0,0) the color!
Color32 colorValue = colorInTheList.Value
}
ArgumentException: Object type HutongGames.PlayMaker.FsmString cannot be converted to target type: HutongGames.PlayMaker.FsmEvent
Parameter name: val
System.Reflection.MonoField.SetValue (System.Object obj, System.Object val, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoField.cs:133)
System.Reflection.FieldInfo.SetValue (System.Object obj, System.Object value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/FieldInfo.cs:150)
HutongGames.PlayMakerEditor.ActionEditor.DoVariableSelection (System.Object userdata) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/ActionEditor.cs:2826)
UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, Int32 selected) (at C:/buildslave/unity/build/artifacts/generated/common/editor/GenericMenuBindings.gen.cs:122)