Esempio n. 1
0
        public T AddComponent <T>(T component) where T : class, IComponent
        {
            var idx = _reactor.GetFutureComponentIdx(component);

            _components.Insert(idx, component);
            _reactor.AddComponent(this, component);
            OnAddComponent.Execute(component);
            return(component);
        }
Esempio n. 2
0
        public T AddComponent <T>() where T : ComponentBase, new()
        {
            if (Disposed)
            {
                return(null);          // TODO: Show an error for trying to add components on a disposed Entity
            }
            var component = new T();

            component.AssignDependencies(this);
            if (component.CheckDependencies())
            {
                components.Add(component);
                OnAddComponent?.Invoke(this, component);
                component.OnCreate();
                return(component);
            }

            return(null);
        }