Example #1
0
        public K AddComponent <K, P1>(P1 p1) where K : Component, new()
        {
            K component = ComponentFactory.CreateWithParent <K, P1>(this, p1);

            if (this.componentDict.ContainsKey(component.GetType()))
            {
                throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
            }

            if (component is ISerializeToEntity)
            {
                this.components.Add(component);
            }
            this.componentDict.Add(component.GetType(), component);
            return(component);
        }
Example #2
0
        public Component AddComponent(Type type)
        {
            Component component = ComponentFactory.CreateWithParent(type, this);

            if (this.componentDict.ContainsKey(component.GetType()))
            {
                throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {type.Name}");
            }

            if (component is ISerializeToEntity)
            {
                this.components.Add(component);
            }
            this.componentDict.Add(component.GetType(), component);
            return(component);
        }