//-------∽-★-∽------∽-★-∽--------∽-★-∽gameobject管理∽-★-∽--------∽-★-∽------∽-★-∽--------// public GameObject CreateGo(string url_, CALLBACK_GO onComplete_) { url_ = url_.ToLower(); GameObject prefab = m_assetCache.GetAsset(url_) as GameObject; if (prefab == null) { Log.Assert("gameobject未加载:" + url_); return(null); } GameObject go = GameObjUtil.CreateGameObj(prefab); GameObjUtil.DontDestroyOnLoad(go); //所有加载出来的go都是默认不销毁 AddGo(url_, go); if (onComplete_ != null) { onComplete_(go); } return(go); }
/// <summary> /// 显示默认go, 子类重写 /// </summary> virtual protected void ShowGameObject() { if (m_gameObject == null) { //如果没有, 则创建一个空容器 ShowGameObject(GameObjUtil.CreateGameobj(TypeName), false); } }
//public bool ignoreRestart = false; void Awake() { //if (!ignoreRestart) //{ // ResMgr.AddImmortalObject(gameObject); //} GameObjUtil.DontDestroyOnLoad(gameObject); Destroy(this); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽Transform∽-★-∽--------∽-★-∽------∽-★-∽--------// //移出父级 virtual protected void RemoveChildThis() { if (m_goIsExternal) { //外部go,不负责移除 return; } GameObjUtil.RemoveFromParent(this.gameObject); }
public virtual GameObject GetChildByName(GameObject parent_, string name_, bool isRecursive = false) { GameObject go = GameObjUtil.FindChild(parent_, name_, isRecursive); if (go == null) { Log.Warn("找不到子对象:" + name_, this); } return(go); }
/// <summary> /// 销毁垃圾桶里的子对象 /// </summary> /// <param name="child_"></param> /// <returns></returns> public bool Delete(GameObject child_) { if (!Contains(child_)) { return(false); } m_objArr.Remove(child_); GameObjUtil.Delete(child_); return(true); }
/// <summary> /// 为子对象添加组件 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="go"></param> /// <param name="path"></param> /// <returns></returns> public static T AddChildComponent <T>(GameObject go, string path) where T : Component { GameObject child = GameObjUtil.FindChild(go, path); if (child == null) { Debug.LogWarning(string.Format("miss child: {0}, {1}", go, path)); return(null); } return(child.AddComponent <T>()); }
public GameObject Pop(GameObject child_, GameObject toParent_) { if (!Contains(child_)) { return(null); } m_objArr.Remove(child_); GameObjUtil.ChangeParent(child_, toParent_); return(child_); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽CreateChild∽-★-∽--------∽-★-∽------∽-★-∽--------// static public GameObject CreateChildByName(GameObject parent_, string name_) { GameObject go = GameObjUtil.FindChild(parent_, name_); if (go == null) { //还没创建 go = GameObjUtil.CreateGameobj(name_); GameObjUtil.ChangeParent(go, parent_); } return(go); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽数据操作∽-★-∽--------∽-★-∽------∽-★-∽--------// /// <summary> /// 回收对象 /// </summary> /// <param name="obj_"></param> public void Push(GameObject child_) { if (Contains(child_)) { return; } GameObjUtil.RecordLocalMatrix(child_.transform); //记录位置 child_.transform.parent = m_transform; GameObjUtil.ApplyLocalMatrix(child_.transform); //恢复位置 m_objArr.Add(child_); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽ChildComponent∽-★-∽--------∽-★-∽------∽-★-∽--------// /// <summary> /// 获取子对象的组件 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="go_"></param> /// <param name="path_"></param> /// <returns></returns> public static T GetChildComponent <T>(GameObject go_, string path_) where T : Component { GameObject child = GameObjUtil.FindChild(go_, path_); if (child == null) { Debug.LogWarning(string.Format("miss child: {0}, {1}", go_, path_)); return(null); } T component = child.GetComponent <T>(); return(component); }
static public T CreateChildByName <T>(GameObject parent_, string name_) where T : Component { GameObject go = GameObjUtil.FindChild(parent_, name_); if (go == null) { //还没创建 go = GameObjUtil.CreateGameobj(name_); GameObjUtil.ChangeParent(go, parent_); } T cmpt = ComponentUtil.EnsureComponent <T>(go); return(cmpt); }
/// <summary> /// 替换子对象 /// </summary> /// <param name="name_"></param> /// <param name="replace_"></param> public void ReplaceChildByName(string name_, GameObject replace_) { GameObject child = GetChildByName(name_, true); if (child == null) { return; } GameObject parent = GameObjUtil.GetParent(child); GameObjUtil.RecordLocalMatrix(child.transform); GameObjUtil.ApplyLocalMatrix(replace_.transform); GameObjUtil.Delete(child); //删除原来的子对象 GameObjUtil.ChangeParent(replace_, parent); }
//初始化容器 protected void InitGameObject(string name_) { if (m_gameObject) { return; } string name = string.IsNullOrEmpty(name_) ? this.GetType().Name : name_; //容器名称 m_gameObject = GameObjUtil.CreateGameobj(name); m_gameObject.isStatic = true; //设置为静态对象 m_transform = m_gameObject.transform; GameObjUtil.DontDestroyOnLoad(m_gameObject); AllocPoolPos(m_gameObject); }
/// <summary> /// 清空所有子对象 /// 仅清除对象列表 /// </summary> public void Clear() { if (m_objArr.Count == 0) { return; } GameObject go; var enumerator = m_objArr.GetEnumerator(); while (enumerator.MoveNext()) { go = enumerator.Current; GameObjUtil.Delete(go); //直接销毁,会不会导致其他引用者产生空对象? } enumerator.Dispose(); m_objArr.Clear(); }
protected override void __Dispose(bool disposing_) { Clear(); if (disposing_) { if (m_gameObject != null) { GameObjUtil.Delete(m_gameObject); m_gameObject = null; } } else { if (m_gameObject != null) { Log.Fatal("gameObject销毁失败", this.GetType()); } } }
protected void ClearGameObject() { if (m_gameObject == null) { return; } __ClearGameObject(); if (m_goIsExternal) { //如果是外部go, 只是移除引用 m_gameObject = null; } else { //是自己托管的go, 则删除对象 GameObjUtil.Delete(m_gameObject); //GameObjUtil.DestroyNow(m_gameObject); m_gameObject = null; } }
static void __Setup() { m_appBhv = ComponentUtil.EnsureComponent <CCAppBhv>(m_gRoot); if (!m_trash) { m_trash = GameObjUtil.CreateGameobj("Trash"); GameObjUtil.DontDestroyOnLoad(m_trash); m_trash.transform.position = new Vector3(-1000, -1000, -1000); m_trash.isStatic = true; //设置为静态对象 } m_resMgr = m_resMgr ?? new ResMgr(); m_resMgr.Setup(); m_soundMgr = m_soundMgr ?? new SoundMgr(m_gRoot); m_soundMgr.Setup(); m_keyboard.Setup(); m_classPools = ClassPools.me; // TimerMgr.inst.Setup(); // ActionMgr.inst.Setup(); // UserPrefs.Setup(); if (CCDefine.DEBUG) { //显示帧频 ComponentUtil.EnsureComponent <FpsTicker>(m_gRoot); } LogFile.Run(); }
static void __Clear() { m_keyboard.Clear(); m_subject.DetachAll(); m_autoRelease.Excute(); m_resMgr.Clear(); m_soundMgr.Clear(); //对象池清除 m_classPools.Clear(); m_classPools = null; //单例清除 TimerMgr.inst.Clear(); ActionMgr.inst.Clear(); UserPrefs.Clear(); Refer.ClearNotify(); GameObject.Destroy(m_appBhv); m_appBhv = null; m_gRoot = null; m_onLateUpdate = null; m_onUpdate = null; m_onGui = null; if (m_trash) { m_trash = GameObjUtil.Delete(m_trash); } }