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); }
public ComponentTypePair(Type t, SComponent c) { type = t; component = c; }