/// <summary> /// /// </summary> /// <param name="go"></param> public GameObjectKun(GameObject go) { if (go == null) { return; } activeSelf = go.activeSelf; isStatic = go.isStatic; layer = go.layer; tag = go.tag; instanceID = go.GetInstanceID(); name = go.name; var components = go.GetComponents(typeof(Component)); componentKuns = new ComponentKun[components.Length]; componentKunTypes = new ComponentKun.ComponentKunType[components.Length]; var i = 0; foreach (var component in components) { componentKunTypes[i] = ComponentKun.GetComponentKunType(component); var systemType = ComponentKun.GetComponetKunSyetemType(componentKunTypes[i]); componentKuns[i] = System.Activator.CreateInstance(systemType, new object[] { component }) as ComponentKun; i++; } dirty = false; }
public T AddComponent <T>() where T : ComponentKun, new() { var componentKun = new T(); componentKun.gameObjectKun = this; if (componentKuns == null) { componentKuns = new ComponentKun[1]; componentKuns[0] = componentKun; componentKunTypes = new ComponentKun.ComponentKunType[1]; componentKunTypes[0] = componentKun.componentKunType; } else { var list = new List <ComponentKun>(componentKuns); list.Add(componentKun); componentKuns = list.ToArray(); var types = new List <ComponentKun.ComponentKunType>(componentKunTypes); types.Add(componentKun.componentKunType); componentKunTypes = types.ToArray(); } return(componentKun); }