Exemple #1
0
        private void DoToolSceneGUI(ToolBase tool)
        {
            var tileSystem = target as TileSystem;

            // Toggle preview material using control key.
            this.CheckSwitchImmediatePreviewMaterial();

            ToolUtility.CheckToolKeyboardShortcuts();

            // Preserve current state of handles.
            Matrix4x4 originalMatrix     = Handles.matrix;
            Color     restoreHandleColor = Handles.color;

            // Place handles within local space of tile system.
            Handles.matrix = tileSystem.transform.localToWorldMatrix;

            // Tools cannot interact with locked tile systems!
            if (!tileSystem.Locked)
            {
                tool.OnSceneGUI(this.toolEvent, this);
            }
            else
            {
                Vector3 activeCenter = Vector3.zero;
                activeCenter.x += this.toolEvent.MousePointerTileIndex.column * tileSystem.CellSize.x + tileSystem.CellSize.x / 2f;
                activeCenter.y -= this.toolEvent.MousePointerTileIndex.row * tileSystem.CellSize.y + tileSystem.CellSize.y / 2f;

                ToolHandleUtility.DrawWireBox(activeCenter, tileSystem.CellSize);
            }

            // Restore former state of handles.
            Handles.matrix = originalMatrix;
            Handles.color  = restoreHandleColor;
        }
Exemple #2
0
        private void TrackMouseInput()
        {
            Event e = Event.current;

            // Refresh status of left/right mouse button when mouse is not being dragged
            // or stop dragging when middle mouse button is pressed.
            if (e.button > 1 || this.toolEvent.Type == EventType.MouseMove)
            {
                this.toolEvent.IsRightButtonPressed = this.toolEvent.IsLeftButtonPressed = false;
            }

            switch (this.toolEvent.Type)
            {
            case EventType.MouseDown:
                if (!this.UpdateToolEventFromCursor(e.mousePosition))
                {
                    break;
                }

                if (ToolManager.Instance.CurrentTool != null && GUIUtility.hotControl == 0)
                {
                    this.toolEvent.IsRightButtonPressed = this.toolEvent.IsLeftButtonPressed = false;

                    // Note: Do not allow use of control or shift with right button
                    //       because otherwise it would not be possible to pan and
                    //       zoom viewport!

                    if ((e.button == 0 || e.button == 1) && !e.alt && (!e.control || e.shift || e.button == 0))
                    {
                        if (e.button == 0)
                        {
                            this.toolEvent.IsLeftButtonPressed = true;
                        }
                        else if (e.button == 1)
                        {
                            this.toolEvent.IsRightButtonPressed = true;
                        }

                        GUIUtility.hotControl = this.sceneControlID;
                        s_AnchorTool          = ToolManager.Instance.CurrentTool;
                    }
                }
                break;

            case EventType.MouseUp:
                this.toolEvent.IsRightButtonPressed = this.toolEvent.IsLeftButtonPressed = false;
                if (GUIUtility.hotControl == this.sceneControlID)
                {
                    GUIUtility.hotControl = 0;
                    s_AnchorTool          = null;
                }
                break;

            case EventType.MouseMove:
            case EventType.MouseDrag:
                this.UpdateToolEventFromCursor(e.mousePosition);
                break;
            }
        }
 private static void ToolManager_ToolChanged(ToolBase oldTool, ToolBase newTool)
 {
     if (oldTool == null && newTool != null)
     {
         s_RestoreAnnotationUtilityShowGrid = AnnotationUtilityShowGrid;
         if (HookEnabled.Value)
         {
             AnnotationUtilityShowGrid = false;
         }
     }
     else if (newTool == null)
     {
         AnnotationUtilityShowGrid = s_RestoreAnnotationUtilityShowGrid;
     }
 }
        /// <summary>
        /// Hide or unhide tool.
        /// </summary>
        /// <param name="tool">Tool.</param>
        /// <param name="hide">Specify a value of <c>true</c> to hide tool; otherwise
        /// a value of <c>false</c> to unhide tool.</param>
        public static void HideTool(ToolBase tool, bool hide)
        {
            if (tool._visible == !hide)
            {
                return;
            }

            tool._visible = !hide;

            if (hide)
            {
                Hidden.Value.Add(tool.GetType().FullName);
            }
            else
            {
                Hidden.Value.Remove(tool.GetType().FullName);
            }

            Hidden.MarkDirty();
        }
Exemple #5
0
        private static void OnDrawGizmosSelected(TileSystem system, GizmoType gizmoType)
        {
            DrawTileSystemGizmosSelected(system, 2.0f);

            // Do not display gizmos when tile system is locked, this would be confusing!
            if (system.Locked)
            {
                return;
            }

            if (!RtsPreferences.ToolImmediatePreviews)
            {
                return;
            }

            ToolBase currentTool = ToolManager.Instance.CurrentTool;

            if (currentTool != null && ToolBase.IsEditorNearestControl)
            {
                ImmediatePreviewUtility.PreviewMaterial.color = RtsPreferences.ToolImmediatePreviewsTintColor;
                currentTool.OnDrawGizmos(system);
            }
        }
Exemple #6
0
        private void DoTool(ToolBase tool, bool isMouseEvent, bool wasSceneActiveControl)
        {
            var tileSystem = target as TileSystem;

            this.toolEvent.MousePointerTileIndex = this.toolEvent.LastMousePointerTileIndex;

            if (!EditorApplication.isPlaying)
            {
                // Mark the current scene as being dirty.
                EditorSceneManager.MarkSceneDirty(tileSystem.gameObject.scene);
            }

            // Allow tool to manipulate event data if desired.
            tool.OnRefreshToolEvent(this.toolEvent, this);
            ToolUtility.ActiveTileIndex = this.toolEvent.MousePointerTileIndex;

            // Use currently selected tool!
            this.DoToolSceneGUI(tool);

            if (isMouseEvent)
            {
                // Tools cannot interact with locked tile systems!
                if (!tileSystem.Locked)
                {
                    // Allow tool to respond to all mouse events.
                    bool isSceneActiveControl = GUIUtility.hotControl == this.sceneControlID;
                    if (wasSceneActiveControl || isSceneActiveControl)
                    {
                        tool.OnTool(this.toolEvent, this);

                        switch (this.toolEvent.Type)
                        {
                        case EventType.MouseDown:
                        case EventType.MouseDrag:
                            if (isSceneActiveControl)
                            {
                                Event.current.Use();
                            }
                            break;

                        case EventType.MouseUp:
                            if (wasSceneActiveControl)
                            {
                                tool.OnToolInactive(this.toolEvent, this);
                                Event.current.Use();
                            }
                            break;
                        }
                    }
                    else
                    {
                        tool.OnToolInactive(this.toolEvent, this);
                    }
                }

                // Force redraw in scene views.
                SceneView.RepaintAll();
                // Force redraw in game views.
                EditorInternalUtility.RepaintAllGameViews();
            }
        }
        /// <summary>
        /// Selects tool for use within custom system.
        /// </summary>
        /// <param name="tool">Tool that is to be selected. Specify `null` to
        /// revert to previous Unity tool.</param>
        /// <returns>
        /// Instance of tool that was selected.
        /// </returns>
        public ToolBase SelectTool(ToolBase tool)
        {
            if (tool != null)
            {
                this.AutoActivateTileSystem();

                if (ToolUtility.ActiveTileSystem == null)
                {
                    // Deselect tool because no tile system is selected!
                    tool = null;
                }
                else if (this.currentTool == null)
                {
                    // Reveal active tile system in scene palette when tool is first activated.
                    // Let's not keep scrolling to the active tile system each time the user
                    // selects another tool since this can be quite annoying!
                    ToolUtility.RevealTileSystem(ToolUtility.ActiveTileSystem, false);

                    // Automatically show tool palette upon activating tool if specified
                    // in user preferences.
                    if (RtsPreferences.AutoShowToolPalette)
                    {
                        ToolUtility.ShowToolPalette(false);
                    }
                }
            }

            if (tool != null)
            {
                // Should current Unity tool be preserved whilst custom tool is used?
                if (UnityEditor.Tools.current != Tool.None)
                {
                    this.previousUnityTool    = UnityEditor.Tools.current;
                    UnityEditor.Tools.current = Tool.None;
                }
            }
            else if (UnityEditor.Tools.current == Tool.None)
            {
                // Revert back to former Unity tool because tool has been deselected!
                UnityEditor.Tools.current = this.previousUnityTool;
            }

            // Will tool selection actually change?
            if (tool == this.currentTool)
            {
                return(tool);
            }

            // Reset active plop reference to avoid issues when switching tools.
            ToolUtility.ActivePlop = null;

            if (this.currentTool != null)
            {
                this.previousTool = this.currentTool;
            }

            // Switch to specified tool.
            var oldTool = this.currentTool;

            this.currentTool = tool;

            if (oldTool != null)
            {
                oldTool.OnDisable();
            }

            if (tool != null)
            {
                if (oldTool == null)
                {
                    // No tool was active prior to using this method to select a tool.
                    this.BeginEditMode();
                }

                tool.OnEnable();
            }
            else if (oldTool != null)
            {
                // A tool was active prior to using this method to deselect tool.
                this.ExitEditMode();
            }

            // Raise event for tool change.
            if (this.ToolChanged != null)
            {
                try {
                    this.ToolChanged(oldTool, this.currentTool);
                }
                catch (Exception ex) {
                    Debug.LogException(ex);
                }
            }

            ToolUtility.RepaintToolPalette();

            // Brush palette only needs to be repainted when tool is first selected or deselected.
            if (oldTool == null || tool == null)
            {
                ToolUtility.RepaintBrushPalette();
            }

            SceneView.RepaintAll();

            return(tool);
        }
        private ToolBase DrawAvailableToolEntry(Rect position, ToolBase tool)
        {
            position.width -= 25;

            Rect eyePosition = position;

            eyePosition.x     = position.xMax;
            eyePosition.width = 25;

            string tipText = tool.Visible
                ? TileLang.ParticularText("Action", "Click to hide tool")
                : TileLang.ParticularText("Action", "Click to show tool");
            int eyeControlID = RotorzEditorGUI.GetHoverControlID(eyePosition, tipText);

            switch (Event.current.GetTypeForControl(eyeControlID))
            {
            case EventType.Repaint:
                Color restoreColor = GUI.color;
                if (!tool.Visible)
                {
                    GUI.color = new Color(0f, 0f, 0f, 0.55f);
                }

                if (tool.IconNormal != null)
                {
                    Rect iconPosition = position;
                    iconPosition.width  = 22;
                    iconPosition.height = 22;

                    GUI.DrawTexture(iconPosition, tool.IconNormal);
                }

                position.x      += 25;
                position.width  -= 25;
                position.height -= 2;
                RotorzEditorStyles.Instance.LabelMiddleLeft.Draw(position, tool.Label, false, false, false, false);

                if (!tool.Visible)
                {
                    GUI.color = restoreColor;
                }

                eyePosition.x     += 3;
                eyePosition.y      = eyePosition.y + (eyePosition.height - 18) / 2;
                eyePosition.width  = 21;
                eyePosition.height = 18;
                GUI.DrawTexture(eyePosition, tool.Visible ? RotorzEditorStyles.Skin.EyeOpen : RotorzEditorStyles.Skin.EyeShut);
                break;

            case EventType.MouseDown:
                if (Event.current.button == 0 && eyePosition.Contains(Event.current.mousePosition))
                {
                    tool.Visible = !tool.Visible;
                    GUI.changed  = true;
                    Event.current.Use();
                }
                break;
            }

            return(tool);
        }
 /// <summary>
 /// Gets a value indicating whether tool is hidden.
 /// </summary>
 /// <param name="tool">Tool.</param>
 /// <returns>
 /// A value of <c>true</c> if tool is hidden; otherwise a value of <c>false</c>.
 /// </returns>
 public static bool IsToolHidden(ToolBase tool)
 {
     return(Hidden.Value.Contains(tool.GetType().FullName));
 }