public void Init(LayoutManager layout_mng) { m_camera = LayoutTool.CreateCamera(true); m_normal_camera = true; m_background = LayoutTool.CreateBackground(true); m_preview_tex = new RenderTexture(ConfigTool.Instance.target_width, ConfigTool.Instance.target_height, 32); m_camera.targetTexture = m_preview_tex; m_view_rect = new Rect(0, 0, ConfigTool.Instance.target_width, ConfigTool.Instance.target_height); m_target_view_rect = new Vector3[4]; m_target_view_rect[0] = new Vector3(LayoutTool.s_editor_default_x - ConfigTool.Instance.target_width / 2, LayoutTool.s_editor_default_y - ConfigTool.Instance.target_height / 2); m_target_view_rect[1] = new Vector3(LayoutTool.s_editor_default_x - ConfigTool.Instance.target_width / 2, LayoutTool.s_editor_default_y + ConfigTool.Instance.target_height / 2); m_target_view_rect[2] = new Vector3(LayoutTool.s_editor_default_x + ConfigTool.Instance.target_width / 2, LayoutTool.s_editor_default_y + ConfigTool.Instance.target_height / 2); m_target_view_rect[3] = new Vector3(LayoutTool.s_editor_default_x + ConfigTool.Instance.target_width / 2, LayoutTool.s_editor_default_y - ConfigTool.Instance.target_height / 2); m_view_controller = new Controller(this); m_layout_mng = layout_mng; BackColor = LayoutTool.DefaultBackColor; BackTexture = EditorPrefs.GetString("BackTexture"); nResWidth = ConfigTool.Instance.target_width; nResHeight = ConfigTool.Instance.target_height; }
static public void ImportLayout() { string prefab = EditorTool.GetCurrentSelectedAssetPath(); string layout_file = LayoutTool.GetLayoutFullPath(prefab); if (string.IsNullOrEmpty(layout_file)) { return; } if (!File.Exists(layout_file)) { EditorUtility.DisplayDialog("", "\"" + layout_file + "\"不存在,无法导入", "确定"); return; } GameObject layout_obj = LayoutTool.LoadLayout(layout_file); Dictionary <GameObject, string> subPrefabs = LayoutTool.ProcessSubPrefabWhenImport(layout_obj); if (subPrefabs != null) { foreach (KeyValuePair <GameObject, string> kvp in subPrefabs) { ImportLayout(kvp.Key, kvp.Value); Object.DestroyImmediate(kvp.Key); } } ImportLayout(layout_obj, prefab); Object.DestroyImmediate(layout_obj); EditorUtility.DisplayDialog("", "导入成功", "确定"); }
public bool Save() { if (Dirty && m_root != null) { //UIElement uiEle = m_root.GetComponent<UIElement>(); //uiEle.UpdateAllSubPrefabLocalPos(); if (LayoutTool.SaveLayout(FileName, m_root)) { m_dirty = false; return(true); } } return(false); }
public bool Load(string layout_file) { GameObject root = LayoutTool.LoadLayout(layout_file, true); if (root != null) { Release(); m_root = root; m_dirty = false; m_layout_file = layout_file; m_name = EditorTool.GetFileName(layout_file, false); UpdateHierarchyInfo(m_root, 0); } return(root != null); }
void OnDestroy() { Layout cur_layout = m_layout_mng.CurEditLayout; if (cur_layout != null && cur_layout.Dirty) { if (EditorUtility.DisplayDialog("", "当前编辑的layout已被修改,是否保存?", "是", "否")) { cur_layout.Save(); } } ClearUndos(); m_view.Dispose(); m_layout_mng.Dispose(); LayoutTool.ReleaseRoot(); }
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); } }
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); }
public void SetTool(ITool tool) { _layoutTool = (LayoutTool)tool; _layoutTool.LayoutChanged += OnLayoutToolLayoutChanged; }
void RenderLayoutList() { EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(true)); Rect treeRect = EditorGUILayout.BeginVertical(LayoutEditorGUIStyle.panelBox, GUILayout.ExpandHeight(true)); if (layoutTree != null) { layoutTree.Draw(treeRect, this); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("导入")) { if (m_layout_mng.CurEditLayout == null) { EditorUtility.DisplayDialog("", "请先打开一个layout文件!", "确定"); return; } string layout = LayoutTool.OpenLayoutDialog(); if (!string.IsNullOrEmpty(layout)) { m_layout_mng.ImportLayout(layout); m_layout_mng.SetLayoutVisible(m_layout_mng.LayoutCount - 1, true); ResetLayoutTree(); RequestRepaint(); } } if (GUILayout.Button("移除")) { List <TreeNode> selList = layoutTree.GetSelectedNodes(); bool hasEdit = false; foreach (TreeNode node in selList) { if (node.ToggleList["编辑"]) { hasEdit = true; break; } } if (!hasEdit && EditorUtility.DisplayDialog("移除layout", "确认要移除选中的layout?", "确认", "取消")) { foreach (TreeNode node in selList) { layoutTree.RemoveRootNode(node); m_layout_mng.RemoveLayout((int)node.DataKey); } ResetLayoutTree(); RequestRepaint(); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
void RenderToolBar() { Layout cur_layout = m_layout_mng.CurEditLayout; GUILayout.Label("版本号:" + ConfigTool.Instance.version); if (cur_layout == null) { GUILayout.Label("请打开layout文件来编辑。"); } else { GUILayout.Label(cur_layout.FileName + (cur_layout.Dirty ? " *" : "")); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("打开")) { int res = 0; if (cur_layout != null && m_layout_mng.CurEditLayout.Dirty) { res = EditorUtility.DisplayDialogComplex("", "当前编辑的layout已被修改,是否保存?", "是", "否", "取消"); switch (res) { // 是 case 0: if (cur_layout != null) { cur_layout.Save(); } break; // 否 case 1: break; // 取消 case 2: break; default: break; } } if (res != 2) { string layout = LayoutTool.OpenLayoutDialog(); if (!string.IsNullOrEmpty(layout)) { ClearUndos(); m_layout_mng.Clear(); /* * if (res == 1) * m_layout_mng.CurEditLayout.Reload();*/ //m_layout_mng.RemoveLayout(1); m_layout_mng.ImportLayout(layout); m_layout_mng.SetCurEditLayout(m_layout_mng.LayoutCount - 1); m_layout_mng.SetLayoutVisible(m_layout_mng.LayoutCount - 1, true); ResetLayoutTree(); ResetUITree(); RequestRepaint(); } } } GUI.enabled = (cur_layout != null && cur_layout.Dirty); if (GUILayout.Button("保存")) { if (cur_layout != null && m_view.CheckResolutionBeforeSave()) { cur_layout.Save(); } //Debug.Log("counter:" + cmdCounter.Cur + " cur:" + cmdCur); } GUI.enabled = true; if (GUILayout.Button("设置背景图")) { string file = LayoutTool.OpenBackImage(); if (!string.IsNullOrEmpty(file)) { m_view.BackTexture = file; } } if (GUILayout.Button("清除背景图")) { m_view.BackTexture = ""; } GUILayout.Label("背景颜色"); m_view.BackColor = EditorGUILayout.ColorField(m_view.BackColor); m_view.ShowBorder = GUILayout.Toggle(m_view.ShowBorder, "显示边框"); GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignLeft)); if (GUILayout.Button("左对齐")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_AlignLeft); } } GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignVCenter)); if (GUILayout.Button("纵向居中对齐")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_AlignVCenter); } } GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignRight)); if (GUILayout.Button("右对齐")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_AlignRight); } } GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignTop)); if (GUILayout.Button("顶对齐")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_AlignTop); } } GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignHCenter)); if (GUILayout.Button("横向居中对齐")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_AlignHCenter); } } GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignBottom)); if (GUILayout.Button("底对齐")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_AlignBottom); } } GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_SameSize)); if (GUILayout.Button("使大小相同")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_SameSize); } } GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_SameXSpace)); if (GUILayout.Button("使x间距相同")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_SameXSpace); } } GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_SameYSpace)); if (GUILayout.Button("使y间距相同")) { if (cur_layout != null) { cur_layout.Format(Layout.FormatType.FT_SameYSpace); } } GUI.enabled = (cur_layout != null && !m_view.NormalCamera); if (GUILayout.Button("重置相机")) { m_view.ResetCamera(); } GUI.enabled = (cur_layout != null); if (GUILayout.Button("调整分辨率")) { ResDialog dlg = EditorWindow.GetWindow <ResDialog>(false, "选择分辨率", true); dlg.mainview = m_view; } m_view.ShowBoxCollider = GUILayout.Toggle(m_view.ShowBoxCollider, "显示碰撞盒边框"); GUI.enabled = true; if (GUILayout.Button("使用文档")) { Help.BrowseURL(ConfigTool.Instance.help_url); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
public void Dispose() { LayoutTool.ReleaseCamera(m_camera); LayoutTool.ReleaseBackground(m_background); }
public void ResetCamera() { LayoutTool.ResetCamera(m_camera); m_normal_camera = true; m_camera.Render(); }
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); }
static public void ImportLayout(GameObject layout_obj, string sPrefabPath) { GameObject prefab_obj; #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 prefab_obj = Resources.LoadAssetAtPath(sPrefabPath, typeof(GameObject)) as GameObject; #else prefab_obj = AssetDatabase.LoadAssetAtPath(sPrefabPath, typeof(GameObject)) as GameObject; #endif GameObject new_prefab_obj = Object.Instantiate(prefab_obj) as GameObject; Vector3 pos = new_prefab_obj.transform.localPosition; Vector3 rotate = new_prefab_obj.transform.localEulerAngles; Vector3 scale = new_prefab_obj.transform.localScale; bool need_reset_pos = LayoutTool.NeedResetPos(new_prefab_obj); if (!LayoutTool.ProcessBeforeImport(new_prefab_obj)) { Object.DestroyImmediate(new_prefab_obj); Object.DestroyImmediate(layout_obj); return; } Camera camera = LayoutTool.CreateCamera(); UIElement[] all_element = layout_obj.GetComponentsInChildren <UIElement>(true); if (need_reset_pos) { new_prefab_obj.transform.localPosition = Vector3.zero; } new_prefab_obj.transform.localEulerAngles = Vector3.zero; new_prefab_obj.transform.localScale = Vector3.one; new_prefab_obj.name = prefab_obj.name; LayoutTool.SetCamera(new_prefab_obj, camera); for (int i = 0; i < all_element.Length; ++i) { if (all_element[i].FullPathName == "UIRootTempPanel") { continue; } bool bHasUIWidget = true; UIWidget widget = all_element[i].GetComponent <UIWidget>(); if (widget == null) { bHasUIWidget = false; } List <GameObject> ui_list = null; if (bHasUIWidget) { ui_list = EditorTool.FindGameObjectByName(new_prefab_obj, widget.name); } else { ui_list = EditorTool.FindGameObjectByName(new_prefab_obj, all_element[i].Name); } if (ui_list.Count == 0) { if (bHasUIWidget) { Debug.LogError("找不到节点\"" + widget.name + "\""); } else { Debug.LogError("找不到节点\"" + all_element[i].Name + "\""); } } else if (ui_list.Count > 1) { GameObject child = null; string sFullPathName = all_element[i].FullPathName; if (sFullPathName.Length > 0) { int nIndex = sFullPathName.IndexOf('/'); if (nIndex >= 0) { sFullPathName = sFullPathName.Substring(nIndex + 1); } child = EditorTool.FindGameObjectByPath(new_prefab_obj, sFullPathName); } if (child != null) { if (bHasUIWidget) { if (!LayoutTool.LoadWidgetInfo(child, widget)) { Debug.LogError("节点\"" + widget.name + "\"类型改变,无法导入数据"); } } else { LayoutTool.LoadNonWidgetTransformInfo(child, all_element[i]); } } else { if (bHasUIWidget) { Debug.LogError("节点名称\"" + widget.name + "\"不唯一"); } else { Debug.LogError("节点名称\"" + all_element[i].Name + "\"不唯一"); } } } else { if (bHasUIWidget) { if (!LayoutTool.LoadWidgetInfo(ui_list[0], widget)) { Debug.LogError("节点\"" + widget.name + "\"类型改变,无法导入数据"); } } else { LayoutTool.LoadNonWidgetTransformInfo(ui_list[0], all_element[i]); } } } if (need_reset_pos) { new_prefab_obj.transform.localPosition = pos; } new_prefab_obj.transform.localEulerAngles = rotate; new_prefab_obj.transform.localScale = scale; PrefabUtility.ReplacePrefab(new_prefab_obj, prefab_obj); AssetDatabase.SaveAssets(); LayoutTool.ReleaseCamera(camera); Object.DestroyImmediate(new_prefab_obj); }