public static T[] CopyExecutableNodes <T> (ExecutableNode[] nodes, StateMachine root)
        {
            List <T> mNodes = new List <T> ();

            foreach (ExecutableNode node in nodes)
            {
                if (node == null)
                {
                    Debug.LogWarning("Missing Action " + node.name + " in " + root.Name + "! You may need to enable an integration.");
                    continue;
                }
                ExecutableNode dest = (ExecutableNode)ScriptableObject.Instantiate(node);
                dest.hideFlags = HideFlags.HideInHierarchy;
                dest.name      = node.name;
                FieldInfo[] fields = node.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                foreach (FieldInfo field in fields)
                {
                    if (field.FieldType.IsSubclassOf(typeof(FsmVariable)) && field.GetValue(node) == null)
                    {
                        FsmVariable variable = (FsmVariable)ScriptableObject.CreateInstance(field.FieldType);
                        field.SetValue(node, variable);
                    }
                    object value = field.GetValue(node);
                    field.SetValue(dest, CopyFields(value));
                }
                mNodes.Add((T)(object)dest);
            }
            return(mNodes.ToArray());
        }
Beispiel #2
0
 public void Init(Node node)
 {
     if (!initialized)
     {
         initialized = true;
         root        = node.Root;
         FieldInfo[] fields = this.GetType().GetPublicFields();
         for (int k = 0; k < fields.Length; k++)
         {
             if (typeof(FsmVariable).IsAssignableFrom(fields [k].FieldType))
             {
                 FsmVariable variable = (FsmVariable)fields [k].GetValue(this);
                 if (variable != null && variable.IsShared)
                 {
                     FsmVariable fsmVariable = node.Root.GetVariable(variable.Name) ?? GlobalVariables.GetVariable(variable.Name);
                     if (fsmVariable != null)
                     {
                         fields [k].SetValue(this, fsmVariable);
                         //	Debug.Log(this.GetType()+" "+variable.Name);
                     }
                 }
             }
         }
     }
 }
Beispiel #3
0
        public override void Deserialize(NetworkReader reader)
        {
            string typeString = reader.ReadString();
            Type   type       = TypeUtility.GetType(typeString);

            if (variable == null)
            {
                variable = ScriptableObject.CreateInstance(type) as FsmVariable;
            }
            if (type == typeof(FsmInt))
            {
                variable.SetValue(reader.ReadInt32());
            }
            else if (type == typeof(FsmString))
            {
                variable.SetValue(reader.ReadString());
            }
            else if (type == typeof(FsmFloat))
            {
                variable.SetValue(reader.ReadSingle());
            }
            else if (type == typeof(FsmColor))
            {
                variable.SetValue(reader.ReadColor());
            }
            else if (type == typeof(FsmVector2))
            {
                variable.SetValue(reader.ReadVector2());
            }
            else if (type == typeof(FsmVector3))
            {
                variable.SetValue(reader.ReadVector3());
            }
        }
Beispiel #4
0
        public static T[] CopyExecutableNodes <T>(ExecutableNode[] nodes)
        {
            List <T> mNodes = new List <T> ();

            foreach (ExecutableNode node in nodes)
            {
                ExecutableNode dest = (ExecutableNode)ScriptableObject.Instantiate(node);
                dest.hideFlags = HideFlags.HideInHierarchy;
                dest.name      = node.name;
                FieldInfo[] fields = node.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                foreach (FieldInfo field in fields)
                {
                    if (field.FieldType.IsSubclassOf(typeof(FsmVariable)) && field.GetValue(node) == null)
                    {
                        FsmVariable variable = (FsmVariable)ScriptableObject.CreateInstance(field.FieldType);
                        field.SetValue(node, variable);
                    }
                    object value = field.GetValue(node);
                    field.SetValue(dest, CopyFields(value));
                }
                mNodes.Add((T)(object)dest);
            }
            return(mNodes.ToArray());
        }
Beispiel #5
0
        public static bool SetVariable(string name, object value)
        {
            FsmVariable variable = GlobalVariables.GetVariable(name);

            if (variable != null && variable.VariableType == value.GetType())
            {
                variable.SetValue(value);
                return(true);
            }
            return(false);
        }
Beispiel #6
0
 public FsmVariable GetVariable(string name)
 {
     for (int i = 0; i < Root.Variables.Length; i++)
     {
         FsmVariable variable = Root.Variables[i];
         if (variable.Name == name)
         {
             return(variable);
         }
     }
     return(null);
 }
        private static FsmVariable[] CopyVariables(FsmVariable[] variables)
        {
            List <FsmVariable> mVariables = new List <FsmVariable> ();

            foreach (FsmVariable variable in variables)
            {
                FsmVariable mVariable = (FsmVariable)ScriptableObject.Instantiate(variable);

                mVariable.hideFlags = HideFlags.HideInHierarchy;
                mVariables.Add(mVariable);
            }
            return(mVariables.ToArray());
        }
Beispiel #8
0
        public static FsmVariable GetVariable(string name)
        {
            GlobalVariables globalVariables = Load(GlobalVariables.assetName);

            if (globalVariables == null)
            {
                return(null);
            }
            for (int i = 0; i < globalVariables.Variables.Length; i++)
            {
                FsmVariable variable = globalVariables.Variables[i];
                if (variable.Name == name)
                {
                    return(variable);
                }
            }
            return(null);
        }
Beispiel #9
0
        public bool SetVariable(string name, object value)
        {
            FsmVariable variable = GetVariable(name);

            if (variable != null && variable.VariableType.IsAssignableFrom(value.GetType()))
            {
                variable.SetValue(value);
                return(true);
            }
            if (value != null)
            {
                variable           = (FsmVariable)ScriptableObject.CreateInstance(FsmUtility.GetVariableType(value.GetType()));
                variable.hideFlags = HideFlags.HideInHierarchy;
                variable.Name      = name;
                variable.SetValue(value);
                Variables = ArrayUtility.Add <FsmVariable> (Variables, variable);
            }
            return(false);
        }
 private void Start()
 {
     if (behaviour.stateMachine != null)
     {
         if (!behaviour.stateMachine.IsInitialized)
         {
             bool isEnabled = behaviour.enabled;
             behaviour.EnableStateMachine();
             behaviour.enabled = isEnabled;
         }
         for (int i = 0; i < setVariables.Count; i++)
         {
             FsmVariable variable = behaviour.stateMachine.GetVariable(setVariables[i].name);
             if (variable != null)
             {
                 variable.SetValue(setVariables[i].GetValue());
             }
         }
     }
 }
Beispiel #11
0
        public FsmVariable[] GetSharedVariables(Node node)
        {
            List <FsmVariable> sharedVariables = new List <FsmVariable> ();

            FieldInfo[] fields = this.GetType().GetPublicFields();
            for (int k = 0; k < fields.Length; k++)
            {
                if (typeof(FsmVariable).IsAssignableFrom(fields [k].FieldType))
                {
                    FsmVariable variable = (FsmVariable)fields [k].GetValue(this);
                    if (variable != null && variable.IsShared)
                    {
                        FsmVariable fsmVariable = node.Root.GetVariable(variable.Name);
                        if (fsmVariable != null)
                        {
                            sharedVariables.Add(fsmVariable);
                        }
                    }
                }
            }
            return(sharedVariables.ToArray());
        }
Beispiel #12
0
 public FsmVariableMessage(FsmVariable variable)
 {
     this.variable = variable;
 }