예제 #1
0
        internal void EnsureComponentOrder()
        {
            // Using insertion sort here, because it achieves best performance for already
            // sorted lists, and nearly sorted lists, as well as small lists.
            ComponentExecutionOrder execOrder = Component.ExecOrder;

            for (int k = 1; k < this.compList.Count; k++)
            {
                ComponentCopy swapComponent = this.compList[k];
                int           swapSortIndex = execOrder.GetSortIndex(swapComponent.GetType());
                int           index         = k - 1;
                while (index >= 0)
                {
                    int sortIndex = execOrder.GetSortIndex(this.compList[index].GetType());
                    if (sortIndex > swapSortIndex)
                    {
                        this.compList[index + 1] = this.compList[index];
                        index--;
                        continue;
                    }
                    break;
                }
                this.compList[index + 1] = swapComponent;
            }
        }
예제 #2
0
        private void AddComponent(ComponentCopy newComp, Type type)
        {
            newComp.gameobj = this;
            this.compMap.Add(type, newComp);

            bool added        = false;
            int  newSortIndex = Component.ExecOrder.GetSortIndex(type);

            for (int i = 0; i < this.compList.Count; i++)
            {
                Type itemType      = this.compList[i].GetType();
                int  itemSortIndex = Component.ExecOrder.GetSortIndex(itemType);
                if (itemSortIndex > newSortIndex)
                {
                    this.compList.Insert(i, newComp);
                    added = true;
                    break;
                }
            }
            if (!added)
            {
                this.compList.Add(newComp);
            }

            this.OnComponentAdded(newComp);
        }
예제 #3
0
        private void RemoveComponent(ComponentCopy cmp, Type type)
        {
            this.OnComponentRemoving(cmp);

            this.compMap.Remove(type);
            this.compList.Remove(cmp);

            cmp.gameobj = null;
        }
예제 #4
0
        public ComponentCopy RemoveComponent(Type t)
        {
            ComponentCopy cmp = this.GetComponent(t);

            if (cmp != null)
            {
                this.RemoveComponent(cmp, cmp.GetType());
            }
            return(cmp);
        }
예제 #5
0
        private void RemoveFromManagers(ComponentCopy cmp)
        {
            // Per-Type lists
            TypeInfo             cmpType = cmp.GetType().GetTypeInfo();
            List <ComponentCopy> cmpList;

            if (this.componentsByType.TryGetValue(cmpType, out cmpList))
            {
                cmpList.Remove(cmp);
            }
        }
예제 #6
0
        public void GetComponents(Type t, List <ComponentCopy> resultList)
        {
            TypeInfo typeInfo = t.GetTypeInfo();

            for (int i = 0; i < this.compList.Count; i++)
            {
                ComponentCopy component = this.compList[i];
                if (typeInfo.IsInstanceOfType(component))
                {
                    resultList.Add(component);
                }
            }
        }
예제 #7
0
        private void AddToManagers(ComponentCopy cmp)
        {
            // Per-Type lists
            TypeInfo             cmpType = cmp.GetType().GetTypeInfo();
            List <ComponentCopy> cmpList;

            if (!this.componentsByType.TryGetValue(cmpType, out cmpList))
            {
                cmpList = new List <ComponentCopy>();
                this.componentsByType[cmpType] = cmpList;
            }
            cmpList.Add(cmp);
        }
예제 #8
0
        public ComponentCopy AddComponent(Type type)
        {
            ComponentCopy existing;

            if (this.compMap.TryGetValue(type, out existing))
            {
                return(existing);
            }

            ComponentCopy newComp = type.GetTypeInfo().CreateInstanceOf() as ComponentCopy;

            this.AddComponent(newComp, type);
            return(newComp);
        }
예제 #9
0
        public void RemoveComponent(ComponentCopy cmp)
        {
            if (cmp == null)
            {
                throw new ArgumentNullException("cmp", "Can't remove a null reference Component");
            }
            if (cmp.gameobj != this)
            {
                throw new ArgumentException("The specified Component does not belong to this GameObject", "cmp");
            }

            Type type = cmp.GetType();

            this.RemoveComponent(cmp, type);
        }
예제 #10
0
        private void OnComponentRemoving(ComponentCopy cmp)
        {
            // Notify Components
            ICmpAttachmentListener cmpInit = cmp as ICmpAttachmentListener;

            if (cmpInit != null)
            {
                cmpInit.OnRemoveFromGameObject();
            }

            // Public event
            if (this.eventComponentRemoving != null)
            {
                this.eventComponentRemoving(this, new ComponentCopyEventArgs(cmp));
            }
        }
예제 #11
0
        private void OnComponentAdded(ComponentCopy cmp)
        {
            // Notify Components
            ICmpAttachmentListener cmpInit = cmp as ICmpAttachmentListener;

            if (cmpInit != null)
            {
                cmpInit.OnAddToGameObject();
            }

            // Public event
            if (this.eventComponentAdded != null)
            {
                this.eventComponentAdded(this, new ComponentCopyEventArgs(cmp));
            }
        }
예제 #12
0
        public ComponentCopy GetComponent(Type t)
        {
            ComponentCopy result;

            if (this.compMap.TryGetValue(t, out result))
            {
                return(result);
            }
            else
            {
                TypeInfo typeInfo = t.GetTypeInfo();
                for (int i = 0; i < this.compList.Count; i++)
                {
                    ComponentCopy component = this.compList[i];
                    if (typeInfo.IsInstanceOfType(component))
                    {
                        return(component);
                    }
                }
                return(null);
            }
        }
예제 #13
0
        public void AddComponent(ComponentCopy newComp)
        {
            Type type = newComp.GetType();

            // Consistency checks. Don't fail silently when we can't do what was intended.
            if (newComp.gameobj != null)
            {
                throw new ArgumentException(string.Format(
                                                "Specified Component '{0}' is already part of another GameObject '{1}'",
                                                LogFormat.Type(type),
                                                newComp.gameobj.FullName));
            }
            if (this.compMap.ContainsKey(type))
            {
                throw new InvalidOperationException(string.Format(
                                                        "GameObject '{0}' already has a Component of type '{1}'.",
                                                        this,
                                                        LogFormat.Type(type)));
            }

            this.AddComponent(newComp, type);
        }
예제 #14
0
        public GameObjectCopy FindGameObject(Type hasComponentOfType, bool activeOnly = true)
        {
            ComponentCopy cmp = this.FindComponent(hasComponentOfType, activeOnly);

            return(cmp != null ? cmp.GameObj : null);
        }
예제 #15
0
        void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation)
        {
            ComponentCopy target = targetObj as ComponentCopy;

            this.OnCopyDataTo(targetObj, operation);
        }
예제 #16
0
        void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            GameObjectCopy target        = targetObj as GameObjectCopy;
            bool           isPrefabApply = setup.Context is ApplyPrefabContext;

            if (!isPrefabApply)
            {
                // Destroy additional Components in the target GameObject
                if (target.compMap.Count > 0)
                {
                    List <Type> removeComponentTypes = null;
                    foreach (var pair in target.compMap)
                    {
                        if (!this.compMap.ContainsKey(pair.Key))
                        {
                            if (removeComponentTypes == null)
                            {
                                removeComponentTypes = new List <Type>();
                            }
                            removeComponentTypes.Add(pair.Key);
                        }
                    }
                    if (removeComponentTypes != null)
                    {
                        foreach (Type type in removeComponentTypes)
                        {
                            target.RemoveComponent(type);
                        }
                    }
                }
                // Destroy additional child objects in the target GameObject
                if (target.children != null)
                {
                    int thisChildCount = this.children != null ? this.children.Count : 0;
                    for (int i = target.children.Count - 1; i >= thisChildCount; i--)
                    {
                        target.children[i].Dispose();
                    }
                }
            }

            // Create missing Components in the target GameObject
            foreach (var pair in this.compMap)
            {
                ComponentCopy targetComponent = target.AddComponent(pair.Key);
                setup.HandleObject(pair.Value, targetComponent, CloneBehavior.ChildObject);
            }
            // Create missing child objects in the target GameObject
            if (this.children != null)
            {
                for (int i = 0; i < this.children.Count; i++)
                {
                    GameObjectCopy targetChild;
                    if (target.children != null && target.children.Count > i)
                    {
                        targetChild = target.children[i];
                    }
                    else
                    {
                        targetChild = new GameObjectCopy(string.Empty, target);
                    }

                    setup.HandleObject(this.children[i], targetChild, CloneBehavior.ChildObject);
                }
            }

            // Handle referenced and child objects
            setup.HandleObject(this.scene, target.scene, CloneBehavior.Reference);
            setup.HandleObject(this.prefabLink, target.prefabLink);
        }
예제 #17
0
        void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            ComponentCopy target = targetObj as ComponentCopy;

            this.OnSetupCloneTargets(targetObj, setup);
        }
예제 #18
0
 public ComponentCopyEventArgs(ComponentCopy cmp)
 {
     this.cmp = cmp;
 }
예제 #19
0
 public void CopyTo(ComponentCopy target)
 {
     this.DeepCopyTo(target);
 }