public static bool RemoveNoUINode(GameObject go) { bool remove_sth = false; if (go != null) { GameObject[] children = EditorTool.GetSubChildren(go); for (int i = 0; i < children.Length; ++i) { if (RemoveNoUINode(children[i])) { remove_sth = true; } } bool has_ui = false; bool has_SubPrefabNode = false; Component[] components = go.GetComponents <Component>(); for (int i = 0; i < components.Length; ++i) { if (components[i] != null) { if (components[i] is UIWidget) { has_ui = true; } else if (components[i] is UIPrefabNode) { has_SubPrefabNode = true; } else if (!(components[i] is Transform) && !(components[i] is UIPanel) && !(components[i] is Camera) && !(components[i] is UIAnchor) && !(components[i] is BoxCollider) ) { Object.DestroyImmediate(components[i]); remove_sth = true; } } } if (!has_ui && !has_SubPrefabNode && go.transform.childCount == 0) { Object.DestroyImmediate(go); remove_sth = true; } } return(remove_sth); }
public static void SetWidgetSelfPivot(UIWidget widget, UIWidget.Pivot pivot) { if (widget != null && widget.pivot != pivot) { GameObject[] children = EditorTool.GetSubChildren(widget.gameObject); Vector3 org_pos = widget.transform.position; widget.pivot = pivot; Vector3 inv_pos_delta = (org_pos - widget.transform.position); for (int i = 0; i < children.Length; ++i) { children[i].transform.Translate(inv_pos_delta); } } }
public static void RemoveInvalidNode(GameObject go) { if (go != null) { GameObject[] children = EditorTool.GetSubChildren(go); for (int i = 0; i < children.Length; ++i) { UIElement ui_element = children[i].GetComponent <UIElement>(); if (ui_element != null) { if (ui_element.Removed) { Object.DestroyImmediate(ui_element.gameObject); } else { RemoveInvalidNode(ui_element.gameObject); } } } } }
public static List <GameObject> FindGameObjectByName(GameObject go, string name) { List <GameObject> list = new List <GameObject>(); Stack <GameObject> stack = new Stack <GameObject>(); stack.Push(go); while (stack.Count > 0) { GameObject cur_go = stack.Pop(); GameObject[] children = EditorTool.GetSubChildren(cur_go); for (int i = 0; i < children.Length; ++i) { stack.Push(children[i]); } if (cur_go.name.ToLower() == name.ToLower()) { list.Add(cur_go); } } return(list); }
private static bool CheckSubPrefabImpl(GameObject go, int nCookie) { UIPrefabNode node = go.GetComponent <UIPrefabNode>(); if (node != null) { nCookie++; } if (nCookie >= 2) { return(false); } GameObject[] children = EditorTool.GetSubChildren(go); foreach (GameObject child in children) { if (!CheckSubPrefabImpl(child, nCookie)) { return(false); } } return(true); }
//�ڵ���layout֮ǰ����һ�£���������prefab���Ƿ����������壨ͬ�����£�����������ʾ public static bool ProcessBeforeImport(GameObject go) { if (go == null) { return(false); } HashSet <string> path_name_dic = new HashSet <string>(); Stack <GameObject> stack = new Stack <GameObject>(); stack.Push(go); while (stack.Count > 0) { GameObject cur_go = stack.Pop(); GameObject[] children = EditorTool.GetSubChildren(cur_go); for (int i = 0; i < children.Length; ++i) { stack.Push(children[i]); } if (HasUI(cur_go, false)) { string sPathName = EditorTool.GetGameObjectFullPathName(cur_go, go); if (path_name_dic.Contains(sPathName)) { EditorUtility.DisplayDialog("", "ѡ�е�Prefab���������գɽڵ�\"" + cur_go.name + "\"���ȴ���", "ȷ��"); return(false); } else { path_name_dic.Add(sPathName); } } } return(true); }
// �����Ƿ�������UIԪ�أ�Ϊÿһ���ڵ�����UIElement public static bool ProcessBeforeExport(GameObject go) { if (go == null) { return(false); } HashSet <string> name_dic = new HashSet <string>(); HashSet <string> path_name_dic = new HashSet <string>(); Stack <GameObject> stack = new Stack <GameObject>(); //bool bFirst = true; stack.Push(go); while (stack.Count > 0) { GameObject cur_go = stack.Pop(); GameObject[] children = EditorTool.GetSubChildren(cur_go); for (int i = 0; i < children.Length; ++i) { stack.Push(children[i]); } string sPathName = EditorTool.GetGameObjectFullPathName(cur_go, go); if (HasUI(cur_go, false)) { if (name_dic.Contains(cur_go.name)) { if (path_name_dic.Contains(sPathName)) { EditorUtility.DisplayDialog("", "�ڵ�����\"" + cur_go.name + "\"��Ψһ��������", "ȷ��"); return(false); } else { path_name_dic.Add(sPathName); } } else { name_dic.Add(cur_go.name); path_name_dic.Add(sPathName); } } UIElement ui_element = cur_go.GetComponent <UIElement>(); if (ui_element == null) { ui_element = cur_go.AddComponent <UIElement>(); } ui_element.Hide = !cur_go.activeSelf; //UIWidget ui_widget = ui_element.GetWidget(); if (cur_go.name == "UIRootTempPanel") { sPathName = "UIRootTempPanel"; } //else if (bFirst) //{ // int nIndex = cur_go.name.IndexOf("(Clone)"); // if (nIndex > 0) // { // sPathName = cur_go.name.Substring(0, nIndex); // } //} ui_element.FullPathName = sPathName; //Debug.Log(sPathName); //SetWidgetSelfPivot(ui_widget, UIWidget.Pivot.BottomLeft); //bFirst = false; } return(true); }