Example #1
0
        public BaseNode Deserialize()
        {
            IsMissingTypes = false;
            var      queue      = new Queue <string>(tokens);
            var      objects    = new Queue <UnityEngine.Object>(references);
            var      parents    = new Stack <IParentNode>();
            Type     type       = null;
            BaseNode instance   = null;
            BaseNode lastParent = null;

            while (queue.Count > 0)
            {
                var cmd = queue.Dequeue();
                switch (cmd)
                {
                case "null":
                    Debug.LogError("WTF");
                    break;

                case "new":
                    var typeName = queue.Dequeue();
                    type = ReactTypeRegister.Find(typeName);
                    if (type == null)
                    {
                        missingTypes.Add(typeName);
                        IsMissingTypes = true;
                        Debug.Log("Missing Type: " + typeName);
                        return(null);
                    }
                    instance = Activator.CreateInstance(type) as BaseNode;
                    if (parents.Count > 0)
                    {
                        parents.Peek().Add(instance);
                    }
                    break;

                case "{":
                    var fcmd = queue.Dequeue();
                    while (fcmd != "}")
                    {
                        var fi = type.GetField(fcmd);
                        if (fi == null)
                        {
                            Debug.LogError(fcmd);
                        }
                        else
                        {
                            if (fi.FieldType.IsSubclassOf(typeof(UnityEngine.Object)))
                            {
                                fi.SetValue(instance, objects.Dequeue());
                            }
                            else
                            {
                                fi.SetValue(instance, ConvertToValue(fi.FieldType, queue.Dequeue(), objects));
                            }
                        }
                        fcmd = queue.Dequeue();
                    }
                    break;

                case "[":
                    parents.Push((IParentNode)instance);
                    break;

                case "]":
                    lastParent = (BaseNode)parents.Pop();
                    break;
                }
            }
            return(lastParent);
        }
Example #2
0
 public void Receive(GameObject sender)
 {
     BaseNode.ExecuteNode(this);
 }
Example #3
0
 public override void OnAfterDeserialize(BaseNode parent, Reactor reactor)
 {
     base.OnAfterDeserialize(parent, reactor);
 }