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.


Topics - Duffer

Pages: [1]
1
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;
        }
}
}

2
Can this be done with standard playmaker action?

Also can you jump straight to a grandchild GO?

3
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!

4
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?

5
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?


6
Pre-release Discussion / "Collections" Actions[SOLVED]
« on: March 07, 2017, 08:25:52 AM »
Hi All,

Not sure if this is the right forum board to ask this.... but I see that 'Collections' actions are in planning.

What sorts of actions (and variables) would Collections actions cover?  Where can I find out about them and what they are planned to do/accomplish?

When / what version are they slated to be introduced in?

7
Hi,

Help!

Let's suppose I have used SimpleSQL to create an Item database for an RPG.

I have a couple of string columns in my SQLite database which contain either the paths to (a) Resources, (b) Prefabs, (c) Assets. These string columns are also then reflected in an ORM public class containing string variables.

My question is, with (a), then (b), then (c), how do I go about bringing in or instantiating the actual Resource (Texture2D, Audioclip, Model etc), Prefab and then other Asset using Playmaker actions?

Any help gratefully received.  Better yet, some sample c# script... 8)

8
Hi All,

Fairly new to these Forums.

Wondering about how to go about instantiating Prefabs / Assets using Playmaker (and perhaps EasySave2 which I have)?

Joel from the Easy Save forums said the following:-

Quote
Hi there,

You may be best off asking this question on the PlayMaker forums as you will need to use ArrayMaker to do this, which we can't provide support for, but has it's own actions to work with Easy Save. Generally I don't think PlayMaker is very well suited to this, but they'll be able to give you more information.

I imagine the workflow for doing this in PlayMaker would go a bit like this if we wanted to save the position of prefabs and instantiate them:

    Put all of your prefabs into a List (we'll call this prefabList) with ArrayMaker.
    Give each prefab a unique name.
    When you instantiate a prefab:
        Set the instance's name to the same name as the prefab.
        Add the instance to another List (we'll call this instanceList).
    Then when you come to save, do the following:
        Iterate over the instanceList and add add the names of each prefab to a List (namesList), and then each separate piece of data you want to save to it's own individual List (i.e. put the position of each instantiated prefab into positionList)
        Save the namesList and the positionList using the ArrayMaker Easy Save actions.
    Then when you want to load, do the following:
        Clear the createdPrefabs list.
        Load the namesList and positionList.
        Iterate over the namesList and for each name in the list, find the prefab in the prefabList with the same name.
        Use Playmaker's Create Object action to instantiate this prefab and add it to the createdPrefabs list.
        Get the position from your positionList which is at the same index as the current name in your namesList, and apply this position to the object you just created.


Again, hopefully they can find a more eloquent solution for you on the PlayMaker forums as the complex part is less about the actual saving and more about handling a list of prefabs!

All the best,
Joel

Can anyone direct me to some tutorials or provide me with some more insights?

Thanks in advance!

9
support Lists and Dictionaries?

Pages: [1]