playMaker

Show Posts

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.


Messages - Duffer

Pages: [1] 2
1
Not really sure about github or how to do that?

Happy for someone to stick the actions on ecosystem for me?

2
And here are the 4 GO Search matching Count FSM Actions...

Code: [Select]
using UnityEngine;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Finds any GameObject(s) with a Name that contains a particular String and stores the count of them in an FSM Int.")]
    public class CountGameObjectsWithNameContaining : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Find any GameObject(s) with a Name containing this string and Count the number of them.")]
        [VariableType(VariableType.String)]
        public FsmString withNameContaining;

        [UIHint(UIHint.Variable)]
        [Tooltip("If this bool is set to True then the String search is case insensitive.")]
        [VariableType(VariableType.Bool)]
        public FsmBool caseInsensitive;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Int of the Count of the found GameObject(s).")]
        [VariableType(VariableType.Int)]
        public FsmInt store;

        private string t1;
        private string t2;

        public override void Reset ()
        {
            withNameContaining = null;
            store = null;
        }

        public override void OnEnter ()
        {
            Find();
            Finish();
        }

        void Find ()
        {
            t1 = withNameContaining.Value;
            t2 = t1.ToUpper();

            if (!string.IsNullOrEmpty(withNameContaining.Value))
            {
                if (caseInsensitive.Value == true)
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.ToUpper().Contains(t2)).ToList();
                    store.Value = taggedObjects.Count;
                }
                else
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.Contains(t1)).ToList();
                    store.Value = taggedObjects.Count;
                }

            }
        }

        public override string ErrorCheck ()
        {
            if (string.IsNullOrEmpty(withNameContaining.Value))
            {
                return "Specify String to be found within GameObject(s') Name(s).";
            }
            return null;
        }
    }
}

Code: [Select]
using UnityEngine;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Count any GameObject(s) with a Name that contains a particular String and stores the count of them in an FSM Int.")]
    public class CountGameObjectsWithNameContaining2 : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Count any GameObject(s) with a Name containing two Strings.  First this String...")]
        [VariableType(VariableType.String)]
        public FsmString withNameContaining;

        [UIHint(UIHint.Variable)]
        [Tooltip("And with the GameObject(s) having a Name containing this String too.")]
        [VariableType(VariableType.String)]
        public FsmString withNameContaining2;

        [UIHint(UIHint.Variable)]
        [Tooltip("If this bool is set to True then the String search is case insensitive.")]
        [VariableType(VariableType.Bool)]
        public FsmBool caseInsensitive;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Integer Count of found GameObject(s).")]
        [VariableType(VariableType.Int)]
        public FsmInt store;

        private string t1;
        private string t12;
        private string t2;
        private string t22;

        public override void Reset ()
        {
            withNameContaining = null;
            withNameContaining2 = null;
            store = null;
        }

        public override void OnEnter ()
        {
            Find();
            Finish();
        }

        void Find ()
        {
            t1 = withNameContaining.Value;
            t12 = withNameContaining2.Value;
            t2 = t1.ToUpper();
            t22 = t12.ToUpper();

            if (!string.IsNullOrEmpty(withNameContaining.Value) && !string.IsNullOrEmpty(withNameContaining2.Value))
            {
                if (caseInsensitive.Value == true)
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.ToUpper().Contains(t2) && g.name.ToUpper().Contains(t22)).ToList();
                    store.Value = taggedObjects.Count;
                }
                else
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.Contains(t1) && g.name.Contains(t12)).ToList();
                    store.Value = taggedObjects.Count;
                }

            }
        }

        public override string ErrorCheck ()
        {
            if (string.IsNullOrEmpty(withNameContaining.Value) || string.IsNullOrEmpty(withNameContaining2.Value))
            {
                return "Specify BOTH the Strings to be found within GameObject(s') Name(s).";
            }
            return null;
        }
    }
}

Code: [Select]
using UnityEngine;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Finds any GameObject(s) with a Tag that contains a particular String and stores the count of them in an FSM Int.")]
    public class CountGameObjectsWithTagContaining : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Find any GameObject(s) with a Tag containing this string and Count the number of them.")]
        [VariableType(VariableType.String)]
        public FsmString withTagContaining;

        [UIHint(UIHint.Variable)]
        [Tooltip("If this bool is set to True then the String search is case insensitive.")]
        [VariableType(VariableType.Bool)]
        public FsmBool caseInsensitive;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Int of the Count of the found GameObject(s).")]
        [VariableType(VariableType.Int)]
        public FsmInt store;

        private string t1;
        private string t2;

        public override void Reset ()
        {
            withTagContaining = null;
            store = null;
        }

        public override void OnEnter ()
        {
            Find();
            Finish();
        }

        void Find ()
        {
            t1 = withTagContaining.Value;
            t2 = t1.ToUpper();

            if (!string.IsNullOrEmpty(withTagContaining.Value))
            {
                if (caseInsensitive.Value == true)
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.ToUpper().Contains(t2)).ToList();
                    store.Value = taggedObjects.Count;
                }
                else
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.Contains(t1)).ToList();
                    store.Value = taggedObjects.Count;
                }

            }
        }

        public override string ErrorCheck ()
        {
            if (string.IsNullOrEmpty(withTagContaining.Value))
            {
                return "Specify String to be found within GameObject(s') Tag(s).";
            }
            return null;
        }
    }
}

Code: [Select]
using UnityEngine;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Count any GameObject(s) with a Tag that contains a particular String and stores the count of them in an FSM Int.")]
    public class CountGameObjectsWithTagContaining2 : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Count any GameObject(s) with a Tag containing two Strings.  First this String...")]
        [VariableType(VariableType.String)]
        public FsmString withTagContaining;

        [UIHint(UIHint.Variable)]
        [Tooltip("And with the GameObject(s) having a Tag containing this String too.")]
        [VariableType(VariableType.String)]
        public FsmString withTagContaining2;

        [UIHint(UIHint.Variable)]
        [Tooltip("If this bool is set to True then the String search is case insensitive.")]
        [VariableType(VariableType.Bool)]
        public FsmBool caseInsensitive;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Integer Count of found GameObject(s).")]
        [VariableType(VariableType.Int)]
        public FsmInt store;

        private string t1;
        private string t12;
        private string t2;
        private string t22;

        public override void Reset ()
        {
            withTagContaining = null;
            withTagContaining2 = null;
            store = null;
        }

        public override void OnEnter ()
        {
            Find();
            Finish();
        }

        void Find ()
        {
            t1 = withTagContaining.Value;
            t12 = withTagContaining2.Value;
            t2 = t1.ToUpper();
            t22 = t12.ToUpper();

            if (!string.IsNullOrEmpty(withTagContaining.Value) && !string.IsNullOrEmpty(withTagContaining2.Value))
            {
                if (caseInsensitive.Value == true)
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.ToUpper().Contains(t2) && g.tag.ToUpper().Contains(t22)).ToList();
                    store.Value = taggedObjects.Count;
                }
                else
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.Contains(t1) && g.tag.Contains(t12)).ToList();
                    store.Value = taggedObjects.Count;
                }

            }
        }

        public override string ErrorCheck ()
        {
            if (string.IsNullOrEmpty(withTagContaining.Value) || string.IsNullOrEmpty(withTagContaining2.Value))
            {
                return "Specify BOTH the Strings to be found within GameObject(s') Tag(s).";
            }
            return null;
        }
    }
}

Enjoy!

3
Get the count of the number of children GOs under a GO including granchildren, great granchildren etc

4
Share New Actions / Get Game Object Path
« on: March 18, 2017, 02:38:17 AM »
Hopefully this Action will return a String variable of the Path of a GameObject.

Code: [Select]
using UnityEngine;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Returns the String of the Path of the selected GameObject.")]
public class GetGameObjectPath : FsmStateAction
{

        [RequiredField]
        [Tooltip("The GameObject from which you return a String of its Path.")]
        public FsmOwnerDefault gameObject;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the final String of the GO's Path in a variable.")]
        public FsmString storeResult;

        private string result;
        private Transform tf;
        private string name;

        public override void Reset()
{
gameObject = null;
storeResult = null;
}

public override void OnEnter()
{
Find();
Finish();
}

void Find()
{
            var go1 = Fsm.GetOwnerDefaultTarget(gameObject);
            tf = go1.transform;
            result = tf.name;
            while (tf.parent != null)
            {
                tf = tf.parent;
                result = tf.name + "/" + result;
            }
            storeResult.Value = result;
        }
}
}

6
Can this be done with standard playmaker action?

Also can you jump straight to a grandchild GO?

7
Pre-release Discussion / Re: "Collections" Actions
« on: March 16, 2017, 12:21:51 AM »
@Jean,

Excellent.  Thanks.

8
Hi All,

I am rather the noob here.  I posted a question and then went on to try and answer it myself here http://hutonggames.com/playmakerforum/index.php?topic=14545.msg67587#msg67587.

Rather than having to find GOs by either their Name(s) or their Tags, thought it would be nifty if you could generate/store an FSM Array of all GOs with a Name containing a particular substring OR (separate Action) all GOs with Tags containing a particular substring.

Then I went one better and thought about it potentially looking for two substrings within GO Name(s) or two substrings within GO Tag(s)...

Thought that would make Naming and Tagging of GOs a lot more versatile?  Also, you needn't then worry about MultiName or MultiTag functionality... ;)

I also added a bool (for all then 8 FSM actions) which if set to true makes the string search case insensitive...

I also added similar Count FSM Actions so you can count the number of GOs meeting the criteria (ie. containing one or two substrings in their Name or one or two substrings in their Tag)...

.... they work!  (No need for multi tags or similar anymore!  Huzzah!)

Here is the code for all EIGHT of the Custom Actions.  I have tested them and they do seem to work.

Code: [Select]
using UnityEngine;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Finds any GameObject(s) with a Name that contains a particular String and stores them in an FSM Array.")]
    public class FindGameObjectsWithNameContaining : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Find any GameObject(s) with a Name containing this string.")]
        [VariableType(VariableType.String)]
        public FsmString withNameContaining;

        [UIHint(UIHint.Variable)]
        [Tooltip("If this bool is set to True then the String search is case insensitive.")]
        [VariableType(VariableType.Bool)]
        public FsmBool caseInsensitive;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Array of found GameObject(s).")]
        [VariableType(VariableType.Array)]
        public FsmArray store;

        private string t1;
        private string t2;

        public override void Reset ()
        {
            withNameContaining = null;
            store = null;
        }

        public override void OnEnter ()
        {
            Find();
            Finish();
        }

        void Find ()
        {
            t1 = withNameContaining.Value;
            t2 = t1.ToUpper();

            if (!string.IsNullOrEmpty(withNameContaining.Value))
            {
                if (caseInsensitive.Value == true)
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.ToUpper().Contains(t2)).ToList();
                    store.Values = taggedObjects.ToArray();
                }
                else
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.Contains(t1)).ToList();
                    store.Values = taggedObjects.ToArray();
                }

            }
        }

        public override string ErrorCheck ()
        {
            if (string.IsNullOrEmpty(withNameContaining.Value))
            {
                return "Specify String to be found within GameObject(s') Name(s).";
            }
            return null;
        }
    }
}

Code: [Select]
using UnityEngine;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Finds any GameObject(s) with a Name that contains a particular String and stores them in an FSM Array.")]
    public class FindGameObjectsWithNameContaining2 : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Find any GameObject(s) with a Name containing two Strings.  First this String...")]
        [VariableType(VariableType.String)]
        public FsmString withNameContaining;

        [UIHint(UIHint.Variable)]
        [Tooltip("And with the GameObject(s) having a Name containing this string too.")]
        [VariableType(VariableType.String)]
        public FsmString withNameContaining2;

        [UIHint(UIHint.Variable)]
        [Tooltip("If this bool is set to True then the String search is case insensitive.")]
        [VariableType(VariableType.Bool)]
        public FsmBool caseInsensitive;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Array of found GameObject(s).")]
        [VariableType(VariableType.Array)]
        public FsmArray store;

        private string t1;
        private string t12;
        private string t2;
        private string t22;

        public override void Reset ()
        {
            withNameContaining = null;
            withNameContaining2 = null;
            store = null;
        }

        public override void OnEnter ()
        {
            Find();
            Finish();
        }

        void Find ()
        {
            t1 = withNameContaining.Value;
            t12 = withNameContaining2.Value;
            t2 = t1.ToUpper();
            t22 = t12.ToUpper();

            if (!string.IsNullOrEmpty(withNameContaining.Value)  && !string.IsNullOrEmpty(withNameContaining2.Value))
            {
                if (caseInsensitive.Value == true)
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.ToUpper().Contains(t2) && g.name.ToUpper().Contains(t22)).ToList();
                    store.Values = taggedObjects.ToArray();
                }
                else
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.Contains(t1) && g.name.Contains(t12)).ToList();
                    store.Values = taggedObjects.ToArray();
                }

            }
        }

        public override string ErrorCheck ()
        {
            if (string.IsNullOrEmpty(withNameContaining.Value) || string.IsNullOrEmpty(withNameContaining2.Value))
            {
                return "Specify BOTH the Strings to be found within GameObject(s') Name(s).";
            }
            return null;
        }
    }
}

Code: [Select]
using UnityEngine;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Finds any GameObjects(s) with a Tag that contains a particular String and stores them in an FSM Array.")]
    public class FindGameObjectsWithTagContaining : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Find any GameObject(s) with a Tag containing this string.")]
        [VariableType(VariableType.String)]
        public FsmString withTagContaining;

        [UIHint(UIHint.Variable)]
        [Tooltip("If this bool is set to True then the String search is case insensitive.")]
        [VariableType(VariableType.Bool)]
        public FsmBool caseInsensitive;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Array of found GameObject(s).")]
        [VariableType(VariableType.Array)]
        public FsmArray store;

        private string t1;
        private string t2;

        public override void Reset ()
        {
            withTagContaining = null;
            store = null;
        }

        public override void OnEnter ()
        {
            Find();
            Finish();
        }

        void Find ()
        {
            t1 = withTagContaining.Value;
            t2 = t1.ToUpper();

            if (!string.IsNullOrEmpty(withTagContaining.Value))
            {
                if (caseInsensitive.Value == true)
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.ToUpper().Contains(t2)).ToList();
                    store.Values = taggedObjects.ToArray();
                }
                else
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.Contains(t1)).ToList();
                    store.Values = taggedObjects.ToArray();
                }

            }
        }

        public override string ErrorCheck ()
        {
            if (string.IsNullOrEmpty(withTagContaining.Value))
            {
                return "Specify String to be found within GameObject(s') Tag(s).";
            }
            return null;
        }
    }
}

Code: [Select]
using UnityEngine;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Finds any GameObject(s) with a Tag that contains a particular String and stores them in an FSM Array.")]
    public class FindGameObjectsWithTagContaining2 : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Find any GameObject(s) with a Tag containing two Strings.  First this String...")]
        [VariableType(VariableType.String)]
        public FsmString withTagContaining;

        [UIHint(UIHint.Variable)]
        [Tooltip("And with the GameObject(s) having a Tag containing this string too.")]
        [VariableType(VariableType.String)]
        public FsmString withTagContaining2;

        [UIHint(UIHint.Variable)]
        [Tooltip("If this bool is set to True then the String search is case insensitive.")]
        [VariableType(VariableType.Bool)]
        public FsmBool caseInsensitive;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Array of found GameObject(s).")]
        [VariableType(VariableType.Array)]
        public FsmArray store;

        private string t1;
        private string t12;
        private string t2;
        private string t22;

        public override void Reset ()
        {
            withTagContaining = null;
            withTagContaining2 = null;
            store = null;
        }

        public override void OnEnter ()
        {
            Find();
            Finish();
        }

        void Find ()
        {
            t1 = withTagContaining.Value;
            t12 = withTagContaining2.Value;
            t2 = t1.ToUpper();
            t22 = t12.ToUpper();

            if (!string.IsNullOrEmpty(withTagContaining.Value)  && !string.IsNullOrEmpty(withTagContaining2.Value))
            {
                if (caseInsensitive.Value == true)
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.ToUpper().Contains(t2) && g.tag.ToUpper().Contains(t22)).ToList();
                    store.Values = taggedObjects.ToArray();
                }
                else
                {
                    var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.Contains(t1) && g.tag.Contains(t12)).ToList();
                    store.Values = taggedObjects.ToArray();
                }

            }
        }

        public override string ErrorCheck ()
        {
            if (string.IsNullOrEmpty(withTagContaining.Value) || string.IsNullOrEmpty(withTagContaining2.Value))
            {
                return "Specify BOTH the Strings to be found within GameObject(s') Tag(s).";
            }
            return null;
        }
    }
}

Sorry will have to post the Counting actions below...

Enjoy!

9
Playmaker Help / Re: Unity Array to Playmaker Array in Custom Action
« on: March 12, 2017, 09:06:13 AM »
I've ploughed ahead in the absence of an immediate response (very impatient, aren't I!).

So I was looking at a Playmaker Custom Action to produce an Array of all GameObjects in Scene or Build or Resources with a Name that contains a certain string (or is a certain string) (case sensitive).

I came up with something - I'd be grateful if someone could check and point out if they thing it would work well or has flaws...

Anyways, here it is:-

Code: [Select]
using UnityEngine;
//using System;
//using System.Collections;
//using System.Collections.Generic;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Finds any GameObject(s) with a Name that contains a particular String and stores them in a FSM Array.")]
public class FindGameObjectsWithNameContaining : FsmStateAction
{
        [UIHint(UIHint.FsmString)]
        [Tooltip("Find any GameObject(s) with a Name containing this string (Case sensitive).")]
        [VariableType(VariableType.String)]
        public FsmString withNameContaining;

[RequiredField]
[UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Array of found GameObject(s).")]
        [VariableType(VariableType.Array)]
        public FsmArray store;
        public override void Reset()
{
withNameContaining = null;
store = null;
}

public override void OnEnter()
{
Find();
Finish();
}

void Find()
{
            if (!string.IsNullOrEmpty(withNameContaining.Value))
            {
                var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.name.Contains(withNameContaining.Value)).ToList();
                store.Values = taggedObjects.ToArray();
            }
        }

public override string ErrorCheck()
{
if (string.IsNullOrEmpty(withNameContaining.Value))
{
    return "Specify String to be found within GameObject(s') Name(s).";
}
return null;
}
}
}

And notwithstanding the use of Lists, I'm not sure I actually need the bit of the code which goes:-
Code: [Select]
using System;
using System.Collections;
using System.Collections.Generic;

???

If the above code is good for a Custom Action to find any GameObjects with a Name which includes a certain string (???), then it follows that the following Custom Action script would then be good to find any GameObjects with a Tag which includes a certain string?:-

Code: [Select]
using UnityEngine;
//using System;
//using System.Collections;
//using System.Collections.Generic;
using System.Linq;

#pragma warning disable 168

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Finds any GameObject(s) with a Tag that contains a particular String and stores them in a FSM Array.")]
public class FindGameObjectsWithTagContaining : FsmStateAction
{
        [UIHint(UIHint.FsmString)]
        [Tooltip("Find any GameObject(s) with a Tag containing this string (Case sensitive).")]
        [VariableType(VariableType.String)]
        public FsmString withTagContaining;

[RequiredField]
[UIHint(UIHint.Variable)]
        [Tooltip("Store the result in an FSM Array of found GameObject(s).")]
        [VariableType(VariableType.Array)]
        public FsmArray store;

        public override void Reset()
{
withTagContaining = null;
store = null;
}

public override void OnEnter()
{
Find();
Finish();
}

void Find()
{
            if (!string.IsNullOrEmpty(withTagContaining.Value))
            {
                var taggedObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(g => g.tag.Contains(withTagContaining.Value)).ToList();
                store.Values = taggedObjects.ToArray();
            }
        }

public override string ErrorCheck()
{
if (string.IsNullOrEmpty(withTagContaining.Value))
{
    return "Specify String to be found within GameObject(s') Tag(s).";
}
return null;
}
}
}

It seems to work...  :)

10
Playmaker Help / Re: Unity Array to Playmaker Array in Custom Action
« on: March 12, 2017, 02:55:34 AM »
@ All,

I did find this code for a custom action which helps my thinking A LOT... :-
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
/*--- __ECO__ __ACTION__ __BETA__ ---*/

using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Array)]
[Tooltip("Get all children of a gameobject and save them in an Array.")]
public class GetGameObjectChildrenInArray : FsmStateAction
{
[RequiredField]
[Tooltip("The gameObject Variable to get its children from.")]
public FsmOwnerDefault gameObject;

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The Array Variable to use.")]
public FsmArray array;

[UIHint(UIHint.Layer)]
[Tooltip("Only consider objects from these layers.")]
public FsmInt[] layerMask;

[Tooltip("Invert the mask, so you pick from all layers except those defined above.")]
public FsmBool invertMask;

[UIHint(UIHint.Tag)]
[Tooltip("Filter by Tag")]
public FsmString withTag;

public override void Reset ()
{
gameObject = null;
array = null;
withTag = "Untagged";
layerMask = null;
invertMask = null;

}

// Code that runs on entering the state.
public override void OnEnter ()
{
DoGetChilds ();
Finish ();
}

private void DoGetChilds ()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;

int _layerMask = ActionHelpers.LayerArrayToLayerMask(layerMask, invertMask.Value);


List<GameObject> _list = new List<GameObject>();

foreach (Transform child in go.transform)
{
bool _valid = true;
// tag filtering
if (! string.IsNullOrEmpty(withTag.Value) || withTag.Value != "UnTagged")
{
_valid = child.tag == withTag.Value;

}

// layer filtering, if still valid
if (_valid) _valid = (_layerMask & (1 << child.gameObject.layer)) > 0 ;


if (_valid) _list.Add(child.gameObject);
}

array.Values = _list.ToArray();
}

}
}

So it's that last array.Values = _list.ToArray(); which helps the most.

If I am reading that correctly, an fsm array uses .Values rather than, as with other fsm variables a .Value.  Also, it would seem I can just transpose across any old (same variable type) unity array - and I can (if the List<T>) is simple also copy across an unity List<T> if we're just talking about a single variable (unity variable) List...?

Please someone tell me if I am wrong in some way...?

11
Playmaker Help / Unity Array to Playmaker Array in Custom Action
« on: March 12, 2017, 01:14:43 AM »
Hi,

Trying to figure this out.  Creating custom action to create unity array of gameobjects filtered on basic their name contains in part a string and then pass that unity array to a playmaker fsm array.

Could someone post some helpful pseudo code on that?

12
Pre-release Discussion / Re: "Collections" Actions
« on: March 10, 2017, 05:16:04 AM »
Hi Jean,

I'll be honest.  I could do with some help for the script for the custom action to grab values from say a public array of strings and, for the sake of simplicity a List of strings too, in a monobehaviour class linked to a GO.

Pretend the following mono class is sitting as a component on the same GO:-

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class RPGBaseInfo : MonoBehaviour {

    public bool template = false;
    public bool hidden = false;

    public string title = "default name";

    public string[] descriptors;

    public List<string> knicknames = new List<string>();
}

What would the Custom Action scripts look like to access both values in the Array and then in the List?

[edit] ignore bit about Arrays... can now see how to do that with Get Property action.  More interested in Lists...


13
Hi Jean,

Forgive my dumbness!  Now see how to lift those variables from the relevant GO monobehavior class.... thanks!

14
Maybe im not using it correctly.

So I've created a monobehavior class called RPGBaseInfo.

Within that class I've created a public string title; variable.

I've dragged that on to a empty gameobject I've created in scene.

I've created an fsm on the go and in the first state I want to add an action to garner the value of that string to an fsm string variable  (keeping it simple).

But Get Property doesn't seem to recognise either the above class or title public variable when i drag in the go at the start of the Get Property action?

15
I must admit I thought the Unity.Object Get Property action did this... but i dont think it does now.  Nor does the Get Component action.

If I am wrong on this and/or there is an easy way to achieve this (rather than putting Fsm Variables on the GO in the first place) then please someone explain (in detail please!).

Otherwise, I think variations of this potential Action are a must-have enhancement?


Pages: [1] 2