private void buildUITree(UIElement element) { uiTree = new EditorTreeView(); //uiTree.OnDrag += onDragNode; //uiTree.OnDrop += onDropNode; uiTree.OnNodeToggleChange += onUINodeToggleChange; uiTree.OnNodeNameChange += onUINodeNameChange; uiTree.OnNodeSelChange += onUINodeSelChange; uiTree.AddMenuItem("添加节点", AddNode); uiTree.AddMenuItem("删除节点", RemoveNode); TreeNode node = TreeNodeFactory.CreateNewUITreeNode(element.Name, element.Hide, element.Freeze, element.Lock); node.DataKey = element; node.CanRenameByUI = !LayoutTool.HasUI(element.gameObject, false); uiTree.AddRootNode(node); buildUITreeRev(element, node); }
private void buildUITreeRev(UIElement element, TreeNode node) { for (int i = 0; i < element.ChildrenCount; i++) { UIElement child = element.GetChild(i); TreeNode subnode = TreeNodeFactory.CreateNewUITreeNode(child.Name, child.Hide, child.Freeze, child.Lock); subnode.DataKey = child; subnode.CanRenameByUI = !LayoutTool.HasUI(child.gameObject, false); subnode.Hide = element.Lock; if (LayoutTool.HasUI(child.gameObject, false)) { subnode.SetColor(new Color(0.8f, 0.35f, 0.0f)); } node.AddChild(subnode); buildUITreeRev(child, subnode); } }
static public void ExportLayout() { string prefab = EditorTool.GetCurrentSelectedAssetPath(); string layout_file = LayoutTool.GetLayoutFullPath(prefab); if (string.IsNullOrEmpty(layout_file)) { return; } if (File.Exists(layout_file)) { if (!EditorUtility.DisplayDialog("", "\"" + layout_file + "\"已经存在,是否覆盖?", "确定", "取消")) { return; } } Object objSelected = EditorTool.GetCurrentSelectedAssetObj(); GameObject inst = Object.Instantiate(objSelected) as GameObject; inst.name = objSelected.name; if (LayoutTool.HasUI(inst)) { if (!LayoutTool.HasAnchorUI(inst)) { if (!LayoutTool.HasUIRootOrPanel(inst)) { GameObject objRoot = new GameObject("UIRootTempPanel"); UIPanel uPanel = objRoot.AddComponent <UIPanel>(); if (uPanel != null) { uPanel.depth = 1; inst.transform.parent = objRoot.transform; inst.name = objSelected.name; inst = objRoot; } else { Debug.Log("Add UIPanel Component Failed"); } } Camera camera = LayoutTool.CreateCamera(); int max_try = 5; int try_count = 0; bool need_reset_pos = LayoutTool.NeedResetPos(inst); if (need_reset_pos) { inst.transform.localPosition = Vector3.zero; } inst.transform.localEulerAngles = Vector3.zero; inst.transform.localScale = Vector3.one; LayoutTool.SetCamera(inst, camera); while (try_count < max_try && LayoutTool.RemoveNoUINode(inst)) { ++try_count; } if (LayoutTool.ProcessBeforeExport(inst)) { if (LayoutTool.ProcessSubPrefabBeforeExport(inst)) { if (LayoutTool.ProcessBeforeExport(inst)) { LayoutTool.SaveLayout(layout_file, inst); EditorUtility.DisplayDialog("", "导出成功", "确定"); } } } LayoutTool.ReleaseCamera(camera); } else { EditorUtility.DisplayDialog("", "有含有Anchor的UI节点,无法导出", "确定"); } } else { EditorUtility.DisplayDialog("", "没有可调整的UI,无需导出", "确定"); } Object.DestroyImmediate(inst); }