public void execute() { if (!executed) { executed = true; m_element.SetParent(m_newEleParent); return; } //Debug.Log("in execute!!" + " node:" + m_node.NodeName + " oldpar:" + m_oldParent.NodeName + " newpar:" + m_newParent.NodeName); if (m_oldParent != null) { m_oldParent.RemoveChild(m_node); } else { m_tree.RemoveRootNode(m_node); } if (m_newParent != null) { m_newParent.AddChild(m_node); } else { m_tree.AddRootNode(m_node); } m_element.SetParent(m_newEleParent); LayoutEditorWindow.RequestRepaint(); }
public void execute() { if (!executed) { executed = true; m_new_ui = (m_node == null ? m_layout_mng.CurEditLayout.Root.AddChildNode() : (m_node.DataKey as UIElement).AddChildNode()); m_new_node = TreeNodeFactory.CreateNewUITreeNode(m_new_ui.Name); m_new_node.DataKey = m_new_ui; } else { (m_new_node.DataKey as UIElement).Removed = false; } if (m_node == null) { m_tree.AddRootNode(m_new_node); } else { m_node.AddChild(m_new_node); } LayoutEditorWindow.RequestRepaint(); }
public void unexecute() { //Debug.Log("in unexecute!!" + " node:" + m_node.NodeName + " oldpar:" + m_oldParent.NodeName + " newpar:" + m_newParent.NodeName); //Debug.Log("tree:" + (m_node.Tree == null ? "null" : "not null")); if (m_newParent != null) { m_newParent.RemoveChild(m_node); } else { m_tree.RemoveRootNode(m_node); } if (m_oldParent != null) { m_oldParent.AddChild(m_node); } else { m_tree.AddRootNode(m_node); } m_element.SetParent(m_oldEleParent); LayoutEditorWindow.RequestRepaint(); }
public void unexecute() { LayoutEditorWindow.RequestRepaint(); #if NGUI_3_5_8 foreach (var p in UIPanel.list) { p.RebuildAllDrawCalls(); } #else UIPanel.SetDirty(); #endif // sprite 实时刷新 foreach (UnityEngine.Object obj in Objs) { if (obj is UIWidget) { (obj as UIWidget).MarkAsChanged(); } } if (CmdName == "Sprite Change" && Objs[0] is UISprite) { UISprite sprite = Objs[0] as UISprite; #if NGUI_3_5_8 sprite.MarkAsChanged(); #else if (sprite.isValid) { sprite.UpdateUVs(true); } #endif } }
public void ScaleCamera(bool larger) { m_camera.orthographicSize *= (larger ? 1.1f : 0.9f); m_normal_camera = false; m_camera.Render(); LayoutEditorWindow.RequestRepaint(); }
public void unexecute() { if (m_parent == null) { m_tree.AddRootNode(m_node); } else { m_parent.AddChild(m_node); } (m_node.DataKey as UIElement).Removed = false; LayoutEditorWindow.RequestRepaint(); }
public void unexecute() { (m_new_node.DataKey as UIElement).Removed = true; if (m_node == null) { m_tree.RemoveRootNode(m_new_node); } else { m_node.RemoveChild(m_new_node); } LayoutEditorWindow.RequestRepaint(); }
public void unexecute() { foreach (KeyValuePair <UIElement, bool> kvp in m_selDic) { if (kvp.Value) { m_layout.UnSelElement(kvp.Key); } else if (!kvp.Key.Hide && !kvp.Key.Freeze) { m_layout.SelElement(kvp.Key); } } LayoutEditorWindow.Instance.SyncUITreeSelectState(m_selDic, true, true); LayoutEditorWindow.RequestRepaint(); }
private void showRenameTextbox() { if (startRename) { renameStr = renamingNode.NodeName; } if (Event.current.type == EventType.repaint) { renameRect = new Rect(renamingNode.x - 3, renamingNode.y + 1, renamingNode.xMax - renamingNode.x, renamingNode.yMax - renamingNode.y); } GUI.SetNextControlName(renameTextField); if (_textBoxStyle == null) { _textBoxStyle = new GUIStyle(GUI.skin.textField); _textBoxStyle.fontStyle = FontStyle.Bold; } renameStr = GUI.TextField(renameRect, renameStr, _textBoxStyle); if (startRename) { TextEditor te = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl); te.SelectAll(); startRename = false; GUI.FocusControl(renameTextField); LayoutEditorWindow.RequestRepaint(); } if (Event.current.keyCode == KeyCode.Escape) { renamingNode = null; startRename = true; LayoutEditorWindow.RequestRepaint(); } else if ((!string.IsNullOrEmpty(GUI.GetNameOfFocusedControl()) && GUI.GetNameOfFocusedControl() != renameTextField) || Event.current.keyCode == KeyCode.Return || endRenaming == true) { endRenaming = false; if (renameStr != renamingNode.NodeName) { performNodeNameChange(renamingNode, renameStr); } renamingNode = null; startRename = true; LayoutEditorWindow.RequestRepaint(); } }
public void execute() { foreach (KeyValuePair <UIElement, bool> kvp in m_selDic) { if (kvp.Value && !kvp.Key.Hide && !kvp.Key.Freeze) { m_layout.SelElement(kvp.Key); } else if (!kvp.Value) { m_layout.UnSelElement(kvp.Key); } } LayoutEditorWindow.Instance.SyncUITreeSelectState(m_selDic, false, !m_firstExe || !m_firstNoScroll); LayoutEditorWindow.RequestRepaint(); m_firstExe = false; }
public void ChangeResolution(int nW, int nH) { m_camera.orthographicSize = nH / 2; m_camera.aspect = (float)nW / nH; m_preview_tex = new RenderTexture(nW, nH, 32); m_camera.targetTexture = m_preview_tex; m_view_rect = new Rect(0, 0, nW, nH); m_target_view_rect[0] = new Vector3(LayoutTool.s_editor_default_x - nW / 2, LayoutTool.s_editor_default_y - nH / 2); m_target_view_rect[1] = new Vector3(LayoutTool.s_editor_default_x - nW / 2, LayoutTool.s_editor_default_y + nH / 2); m_target_view_rect[2] = new Vector3(LayoutTool.s_editor_default_x + nW / 2, LayoutTool.s_editor_default_y + nH / 2); m_target_view_rect[3] = new Vector3(LayoutTool.s_editor_default_x + nW / 2, LayoutTool.s_editor_default_y - nH / 2); m_bSetCameraToAnchor = false; nResWidth = nW; nResHeight = nH; LayoutEditorWindow.RequestRepaint(); }
private void syncElementProp() { switch (m_prop) { case "隐藏": m_element.Hide = m_node.ToggleList[m_prop]; synSelect(!m_element.Hide); break; case "冻结": m_element.Freeze = m_node.ToggleList[m_prop]; synSelect(!m_element.Freeze); break; case "锁定": m_element.Lock = m_node.ToggleList[m_prop]; foreach (TreeNode node in m_node.Children) { node.Hide = m_element.Lock; } if (m_new_value) { synSelect(!m_element.Lock); } if (!m_new_value) { synSelect(false); } break; default: break; } LayoutEditorWindow.RequestRepaint(); }
private void HandleInput(Layout cur_layout) { Event e = Event.current; switch (e.type) { case EventType.MouseDown: if (m_view.ViewRect.Contains(e.mousePosition)) { m_lastMousePos = m_view.GUIToWorld(new Vector3(e.mousePosition.x, e.mousePosition.y)); if (e.button == 0) // ×ó¼ü { m_drag = true; if (m_knob_sel_res.m_knob_index != -1) { m_knob_move = true; } else { UIElement sel_widget = cur_layout.RayTest(m_lastMousePos); BeginSelChange(cur_layout); if (sel_widget != null) { if (!cur_layout.IsElementSelected(sel_widget)) { if (!e.control) { cur_layout.ClearSel(); } cur_layout.SelElement(sel_widget); } else { m_last_sel = sel_widget; } } else { if (!e.control) { cur_layout.ClearSel(); } m_draggingMousePos = m_lastMousePos; BuildSelRect(m_pre_sel_rec, m_draggingMousePos, m_lastMousePos); m_bound_selecting = true; } EndSelChange(cur_layout); BeginSelChange(cur_layout); } } else if (e.button == 2) // Öмü { m_camera_move = true; } } break; case EventType.MouseUp: if (m_last_sel != null && !m_sel_move) { if (e.control) { cur_layout.UnSelElement(m_last_sel); } else { cur_layout.ClearSel(); cur_layout.SelElement(m_last_sel); } } if (m_drag) { if (!m_knob_move) { EndSelChange(cur_layout); } if (!m_bound_selecting && m_sel_move) { CmdManager.Instance.EndCmd(); } } m_drag = false; m_camera_move = false; m_bound_selecting = false; m_knob_move = false; m_sel_move = false; m_last_sel = null; SelKnob(cur_layout, e.mousePosition); break; case EventType.ScrollWheel: if (m_view.ViewRect.Contains(e.mousePosition)) { m_view.ScaleCamera(e.delta.y > 0); } break; case EventType.KeyDown: if (e.keyCode == KeyCode.UpArrow || e.keyCode == KeyCode.DownArrow || e.keyCode == KeyCode.LeftArrow || e.keyCode == KeyCode.RightArrow) { List <UIElement> sel_list = cur_layout.GetMoveUIs(); if (sel_list.Count > 0 && EditorGUIUtility.keyboardControl == 0) { Vector3 move_delta = new Vector3((e.keyCode == KeyCode.LeftArrow ? -1 : (e.keyCode == KeyCode.RightArrow ? 1 : 0)), (e.keyCode == KeyCode.UpArrow ? 1 : (e.keyCode == KeyCode.DownArrow ? -1 : 0)), 0); CmdManager.Instance.BeginCmd(sel_list, "Move Widgets"); for (int i = 0; i < sel_list.Count; ++i) { if (sel_list[i].IsEditBoxCollider()) { if (m_view.ShowBoxCollider) { sel_list[i].Move(move_delta); } } else { sel_list[i].Move(move_delta); } } //for (int i = 0; i < sel_list.Count; ++i) //{ // sel_list[i].SyncPrefabUI((int)EUIOpFlag.UOF_Shape); //} CmdManager.Instance.EndCmd(); LayoutEditorWindow.RequestRepaint(); cur_layout.SetDirty(); } } break; case EventType.MouseMove: case EventType.MouseDrag: Vector3 curMousePos = m_view.GUIToWorld(new Vector3(e.mousePosition.x, e.mousePosition.y)); if (m_camera_move) { Vector3 camera_move_delta = m_lastMousePos - curMousePos; m_view.MoveCamera(camera_move_delta.x, camera_move_delta.y); m_lastMousePos = m_view.GUIToWorld(new Vector3(e.mousePosition.x, e.mousePosition.y)); } else if (m_drag) // Êó±ê×ó¼ü±»°´Ï { if (m_bound_selecting) // ¿òÑ¡ { BuildSelRect(m_cur_sel_rect, m_draggingMousePos, curMousePos); List <UIElement> widgets = cur_layout.GetAllUIs(false); for (int i = 0; i < widgets.Count; ++i) { UIElement w = widgets[i]; Vector3[] corners = w.worldCorners; bool in_pre_rect = SelUI(corners, m_pre_sel_rec); bool in_cur_rect = SelUI(corners, m_cur_sel_rect); if (in_pre_rect != in_cur_rect) { if (in_cur_rect) { if (!cur_layout.IsElementSelected(w)) { cur_layout.SelElement(w); } else if (e.control) { cur_layout.UnSelElement(w); } } else { if (cur_layout.IsElementSelected(w)) { cur_layout.UnSelElement(w); } else if (e.control) { cur_layout.SelElement(w); } } } } BuildSelRect(m_pre_sel_rec, m_draggingMousePos, curMousePos); m_lastMousePos = curMousePos; } else { bool real_move = false; Vector3 move_delta = curMousePos - m_lastMousePos; List <UIElement> sel_list = cur_layout.GetMoveUIs(); if (!m_sel_move) { CmdManager.Instance.BeginCmd(sel_list, (m_knob_move ? "Resize Widgets" : "Move Widgets")); } if (m_knob_move) { UIWidget.Pivot pivot = GetKnobPivot(); int x_scale = GetKnobXScale(pivot); int y_scale = GetKnobYScale(pivot); for (int i = 0; i < sel_list.Count; ++i) { UIElement ui_element = sel_list[i]; if (ui_element.IsEditBoxCollider() && !m_view.ShowBoxCollider) { continue; } if (ui_element.SetWidthDelta(x_scale, move_delta.x)) { real_move = true; } if (ui_element.SetHeightDelta(y_scale, move_delta.y)) { real_move = true; } } //for (int i = 0; i < sel_list.Count; ++i) //{ // UIElement ui_element = sel_list[i]; // if (ui_element.IsEditBoxCollider() && !m_view.ShowBoxCollider) // continue; // ui_element.SyncPrefabUI((int)EUIOpFlag.UOF_Shape); //} } else { for (int i = 0; i < sel_list.Count; ++i) { // ÍÏקÒƶ¯ if (sel_list[i].IsEditBoxCollider()) { if (m_view.ShowBoxCollider) { sel_list[i].Move(move_delta); } } else { sel_list[i].Move(move_delta); } real_move = true; } //for (int i = 0; i < sel_list.Count; ++i) //{ // sel_list[i].SyncPrefabUI((int)EUIOpFlag.UOF_Shape); //} } m_sel_move = true; if (real_move) { m_lastMousePos = curMousePos; } cur_layout.SetDirty(); } } else { SelKnob(cur_layout, e.mousePosition); } break; } cur_layout.ResetAllUIElementOpFlag(); }
public void unexecute() { m_node.NodeName = m_old_name; (m_node.DataKey as UIElement).Name = m_old_name; LayoutEditorWindow.RequestRepaint(); }
public void Draw(Rect rect, EditorWindow window) { Event e = Event.current; if (e.isMouse) { leftDown = false; leftDrag = false; leftUp = false; rightUp = false; } ctrlDown = e.control; shiftDown = !ctrlDown && e.shift; if (e.type == EventType.Repaint) { innerPos = new Vector2(e.mousePosition.x - rect.x + scrollViewPosition.x, e.mousePosition.y - rect.y + scrollViewPosition.y); } if (e.rawType == EventType.MouseDown && e.button == 0) { if (rect.Contains(e.mousePosition) && rect.xMax - 16 > e.mousePosition.x) // 避免在有滚动条的情况下穿透点击 { leftDown = true; } if (renamingNode != null && !renameRect.Contains(innerPos)) { endRenaming = true; leftDown = false; } } else if (e.rawType == EventType.MouseDrag && e.button == 0 && renamingNode == null) { leftDrag = true; dragged = true; if (curNode != null && OnDrag != null) { DragEventArgs args = new DragEventArgs(curNode); OnDrag(this, args); if (args.Cancel) { curNode = null; } } } else if (e.rawType == EventType.MouseUp && e.button == 0) { mutilSelectDown = false; leftUp = true; } else if (e.rawType == EventType.MouseUp && e.button == 1) { if (rect.Contains(Event.current.mousePosition)) { rightUp = true; menuNode = null; } } if (leftDown && shiftDown && !mutilSelectDown && Event.current.type == EventType.repaint) { multiSelEnd = false; multiSelCache.Clear(); inShiftSelRange = false; //clearSelect(); } if (leftUp && dragged) { nodeToRename = null; } if (CanRenameNode && leftUp && !dragged && nodeToRename != null && nodeToRename.CanRenameByUI) { TreeNode temNode = nodeToRename; new System.Threading.Thread(delegate() { System.Threading.Thread.Sleep(100); renamingNode = temNode; LayoutEditorWindow.RequestRepaint(); }).Start(); nodeToRename = null; } if (hasFoundNodeToScroll) { float nodeHeight = 18f; if (rect.height + scrollViewPosition.y < yToScroll + nodeHeight) { scrollViewPosition.y = yToScroll - rect.height + nodeHeight; } else if (yToScroll < scrollViewPosition.y) { scrollViewPosition.y = yToScroll; } hasFoundNodeToScroll = false; yToScroll = 0.0f; } scrollViewPosition = EditorGUILayout.BeginScrollView(scrollViewPosition, GUIStyle.none, GUI.skin.verticalScrollbar); EditorGUILayout.BeginVertical(); SetGeneralStyles(); if (nodeToScroll != null) { findNodeToScroll = true; hasFoundNodeToScroll = false; } foreach (TreeNode node in RootNode) { if (!node.Hide) { DrawNode(node); } } EditorGUILayout.EndVertical(); if (findNodeToScroll) { nodeToScroll = null; findNodeToScroll = false; } if (leftUp) { nodeToRenameList = GetSelectedNodes(); dragged = false; } if (renamingNode != null) { showRenameTextbox(); } if (leftDrag && curNode != null) { Vector2 size = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(curNode.NodeName)); EditorGUI.LabelField(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, size.x, size.y), curNode.NodeName); } EditorGUILayout.EndScrollView(); if (leftDown && shiftDown && selectChangeDic.Count > 0 && !mutilSelectDown) { multiSelEnd = true; mutilSelectDown = true; inShiftSelRange = false; if (OnNodeSelChange != null) { OnNodeSelChange(this, new NodeSelChangeEventArgs(selectChangeDic)); } selectChangeDic.Clear(); multiSelCache.Clear(); } if (leftUp && curNode != null) { if (shiftDown) { curNode = null; } } if (leftUp && curNode != null) { if (curNode != dragDestNode) { performDrag(rect); } dragDestNode = null; curNode = null; } if (rightUp) { ShowMenu(); e.Use(); } if (Event.current.isMouse) { window.Repaint(); } }