/// <summary> /// 返回所有子节点;includeInactive 为是否搜索隐藏的物体,all 表示搜索全部,包括隐藏和显示的; /// /// Action 是查找同名的 GameObject,并且返回; /// </summary> /// <param name="goAsset"></param> /// <param name="includeInactive"></param> /// <param name="all"></param> /// <returns></returns> private List <GameObject> GetAllGameObjects(List <GameObject> AllGameObjectsList, GameObjectAssetsBase goAsset, bool includeInactive, bool all = false) { List <GameObject> gameObjectList = new List <GameObject>(); if (goAsset.recursion) { foreach (Transform childAsset in goAsset.GetComponentsInChildren <Transform>(includeInactive)) { if (includeInactive ^ (childAsset.gameObject.activeSelf & !all)) { if (AllGameObjectsList.Contains(childAsset.gameObject)) { throw new Exception(childAsset.name + "被重复搜索!"); } //continue; // 如果包含该物体了,则跳过该物体; gameObjectList.Add(childAsset.gameObject); } } } else //goAsset.transform 无法返回 Transform[],所以两句 if 不能合并; { foreach (Transform childAsset in goAsset.transform) { if (includeInactive ^ (childAsset.gameObject.activeSelf & !all)) { if (AllGameObjectsList.Contains(childAsset.gameObject)) { throw new Exception(childAsset.name + "被重复搜索!"); } //continue; // 如果包含该物体了,则跳过该物体; gameObjectList.Add(childAsset.gameObject); } } } return(gameObjectList); }
/// <summary> /// 查找子节点;includeInactive 为是否搜索隐藏的物体,all 表示搜索全部,包括隐藏和显示的; /// /// Action 是查找同名的 GameObject,并且返回; /// </summary> /// <param name="goAsset"></param> /// <param name="name"></param> /// <param name="includeInactive"></param> /// <returns></returns> private GameObject FindGameObjectDisplayOrHide(GameObjectAssetsBase goAsset, string name, bool includeInactive, bool all = false, Action <GameObject> action = null) { if (goAsset.recursion) { foreach (Transform childAsset in goAsset.GetComponentsInChildren <Transform>(includeInactive)) { if (includeInactive ^ (childAsset.gameObject.activeSelf & !all) && childAsset.name.ToLower() == name.ToLower()) { if (action == null) { return(childAsset.gameObject); } action(childAsset.gameObject); } } } else //goAsset.transform 无法返回 Transform[],所以两句 if 不能合并; { foreach (Transform childAsset in goAsset.transform) { if (includeInactive ^ (childAsset.gameObject.activeSelf & !all) && childAsset.name.ToLower() == name.ToLower()) { if (action == null) { return(childAsset.gameObject); } action(childAsset.gameObject); } } } return(null); }