Beispiel #1
0
 public SComponent AddComponent(Type type)
 {
     if (!isAlive)
     {
         return(null);
     }
     if (!HasComponent(type))
     {
         SComponent sComponent = Activator.CreateInstance(type) as SComponent;
         if (sComponent != null)
         {
             sComponent._gameObject = this;
             _willAddComponent.Enqueue(new ComponentTypePair(type, sComponent));
             _commandQueue.Enqueue(AddComponent);
             //_componentList.Add(type, sComponent);
             return(sComponent);
         }
         else
         {
             SDebug.LogError("Create Component Instance Failed");
         }
     }
     else
     {
         SDebug.LogError("this kind of component has already been added");
     }
     return(null);
 }
Beispiel #2
0
 public void RemoveComponent(Type type)
 {
     if (!isAlive)
     {
         return;
     }
     if (HasComponent(type))
     {
         _willDeleteComponent.Enqueue(new ComponentTypePair(type, null));
         _commandQueue.Enqueue(RemoveComponent);
     }
     // if (_componentList.ContainsKey(type))
     // {
     //     _componentList.Remove(type);
     // }
     else
     {
         SDebug.LogError("this kind of component has not been added yet");
     }
 }
Beispiel #3
0
        public T AddComponent <T>() where T : SComponent, new()
        {
            if (!isAlive)
            {
                return(null);
            }
            Type type = typeof(T);

            if (!HasComponent(type))
            {
                T t = new T();
                t._gameObject = this;
                _willAddComponent.Enqueue(new ComponentTypePair(type, t));
                _commandQueue.Enqueue(AddComponent);
                //_componentList.Add(type, t);
                return(t);
            }
            else
            {
                SDebug.LogError("this kind of component has already been added");
            }
            return(null);
        }