private UABGameObject Pack(GameObject root, List <ISerializer> serializers)
        {
            var uGo = new UABGameObject();

            uGo.name   = root.name;
            uGo.tag    = root.tag;
            uGo.layer  = root.layer;
            uGo.active = root.activeSelf;

            var childCount = root.transform.childCount;

            uGo.childs = new UABGameObject[childCount];
            for (int i = 0; i < childCount; ++i)
            {
                var uChild = this.Pack(root.transform.GetChild(i).gameObject, serializers);
                uGo.childs[i] = uChild;
            }

            var components = root.GetComponents <Component>();

            uGo.components = new UABComponent[components.Length];
            for (int i = 0; i < components.Length; ++i)
            {
                uGo.components[i] = this.Pack(components[i], serializers);
            }

            return(uGo);
        }
示例#2
0
        public GameObject Unpack(UABGameObject root, List <ISerializer> serializers)
        {
            System.Action nextStep = null;
            var           go       = this.Unpack(root, null, serializers, ref nextStep);

            nextStep.Invoke();
            return(go);
        }
示例#3
0
        private GameObject Unpack(UABGameObject root, Transform parent, List <ISerializer> serializers, ref System.Action nextStep)
        {
            var go = new GameObject(root.name);

            go.tag   = root.tag;
            go.layer = root.layer;
            go.SetActive(root.active);
            go.transform.SetParent(parent);

            var tempList = ListPool <Component> .Get();

            for (int i = 0; i < root.components.Length; ++i)
            {
                var type        = System.Type.GetType(root.components[i].type);
                var isTransform = false;
                if (
                    type == typeof(Transform) ||
                    type == typeof(RectTransform))
                {
                    isTransform = true;
                }

                Component c = null;
                if (isTransform == true)
                {
                    c = go.GetComponent <Transform>();
                    if (type == typeof(RectTransform))
                    {
                        c = go.AddComponent <RectTransform>();
                    }
                }
                else
                {
                    if (type == typeof(ParticleSystemRenderer))
                    {
                        c = go.GetComponent <ParticleSystemRenderer>();
                    }

                    if (c == null)
                    {
                        c = go.AddComponent(type);
                    }
                }

                if (c == null)
                {
                    throw new UnityException(string.Format("Package malformed. Type was not found: {0}", root.components[i].type));
                }
                else
                {
                    this.RegisterReferenceUnpack(root.components[i], c);
                    tempList.Add(c);
                }
            }

            System.Action[] childsNextStep = new System.Action[root.childs.Length];
            for (int i = 0; i < root.childs.Length; ++i)
            {
                var childNextStep = childsNextStep[i];
                this.Unpack(root.childs[i], go.transform, serializers, ref childNextStep);
                childsNextStep[i] = childNextStep;
            }

            nextStep = () => {
                for (int i = 0; i < childsNextStep.Length; ++i)
                {
                    childsNextStep[i].Invoke();
                }

                for (int i = 0; i < root.components.Length; ++i)
                {
                    this.Unpack(tempList[i], root.components[i], serializers);
                }

                ListPool <Component> .Release(tempList);
            };

            return(go);
        }
        public GameObject Unpack(UABGameObject root, Transform parent, List <ISerializer> serializers)
        {
            var go = new GameObject(root.name);

            go.tag   = root.tag;
            go.layer = root.layer;
            go.SetActive(root.active);
            go.transform.SetParent(parent);

            var tempList = ListPool <Component> .Get();

            for (int i = 0; i < root.components.Length; ++i)
            {
                var type        = System.Type.GetType(root.components[i].type);
                var isTransform = false;
                if (
                    type == typeof(Transform) ||
                    type == typeof(RectTransform))
                {
                    isTransform = true;
                }

                Component c = null;
                if (isTransform == true)
                {
                    c = go.GetComponent <Transform>();
                    if (type == typeof(RectTransform))
                    {
                        c = go.AddComponent <RectTransform>();
                    }
                }
                else
                {
                    c = go.AddComponent(type);
                }

                if (c == null)
                {
                    throw new UnityException("Package malformed. Type was not found: " + root.components[i].type);
                }
                else
                {
                    this.RegisterReferenceUnpack(root.components[i], c);
                    tempList.Add(c);
                }
            }

            for (int i = 0; i < root.childs.Length; ++i)
            {
                this.Unpack(root.childs[i], go.transform, serializers);
            }

            for (int i = 0; i < root.components.Length; ++i)
            {
                this.Unpack(tempList[i], root.components[i], serializers);
            }

            ListPool <Component> .Release(tempList);

            return(go);
        }
 public GameObject Unpack(UABGameObject root, List <ISerializer> serializers)
 {
     return(this.Unpack(root, null, serializers));
 }