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); }
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); }