Esempio n. 1
0
        public T AddComponent <T>() where T : Component, new()
        {
            Type typeofT = typeof(T);

            if (!ComponentsRegistry.ContainsKey(typeofT))
            {
                EntityManager.RegisterAddEntityComponent(typeofT, this);
            }
            else if (typeofT.IsDefined(typeof(UniqueComponentAttribute), true))
            {
                throw new Exception("Trying to adding a unique component to an entity but this entity already have the component.");
            }

            T c = new T {
                Entity = this
            };

            Components.Add(c);

            c.Transform = Transform;
            c.Init();

            ComponentsRegistry[typeofT] = true;

            return(c);
        }
Esempio n. 2
0
        public bool HasComponent <T>() where T : Component
        {
            Type typeofT = typeof(T);

            return(ComponentsRegistry.ContainsKey(typeofT) && ComponentsRegistry[typeofT]);
        }