Exemple #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;
            }
        }
Exemple #2
0
        public ComponentCopy RemoveComponent(Type t)
        {
            ComponentCopy cmp = this.GetComponent(t);

            if (cmp != null)
            {
                this.RemoveComponent(cmp, cmp.GetType());
            }
            return(cmp);
        }
Exemple #3
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);
            }
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }