Ejemplo n.º 1
0
        public T GetComponent <T>() where T : IComponent, new()
        {
            foreach (IComponent component in Components)
            {
                if (component is T t)
                {
                    return(t);
                }
            }

            T newT = new T();

            newT.DeltinScript = this;

            for (int i = InitComponent.Count - 1; i >= 0; i--)
            {
                if (typeof(T) == InitComponent[i].ComponentType)
                {
                    InitComponent[i].Apply(newT);
                    InitComponent.RemoveAt(i);
                }
            }

            Components.Add(newT);
            newT.Init();

            return(newT);
        }
        private T AddComponent <T>() where T : IComponent, new()
        {
            T newT = new T();

            for (int i = InitComponent.Count - 1; i >= 0; i--)
            {
                if (typeof(T) == InitComponent[i].ComponentType)
                {
                    InitComponent[i].Apply(newT);
                    InitComponent.RemoveAt(i);
                }
            }

            Components.Add(newT);
            newT.Init(this);

            return(newT);
        }