Beispiel #1
0
        /// <summary>
        /// Lets the Editor handle an event in the scene view
        /// http://docs.unity3d.com/ScriptReference/Editor.OnSceneGUI.html
        /// </summary>
        public void OnSceneGUI()
        {
            Initialize();

            //
            tp_ComponentBaseEditor target = null;
            string undoMsg = string.Empty;

            switch (component.EditingTool)
            { // Update the current menu
            case EditingTool.Height:
                m_heightmapEditor.OnSceneGUI(component);
                undoMsg = TP.UndoMessages.HEIGHTMAP;
                target  = m_heightmapEditor;
                break;

            case EditingTool.Texture:
                m_splatmapEditor.OnSceneGUI(component);
                undoMsg = TP.UndoMessages.TEXTURE;
                target  = m_splatmapEditor;
                break;

            case EditingTool.Foliage:
                m_foliageEditor.OnSceneGUI(component);
                undoMsg = TP.UndoMessages.FOLIAGE;
                target  = m_foliageEditor;
                break;

            case EditingTool.Object: break;

            case EditingTool.Settings: m_settings.OnSceneGUI(component); break;
            }

            // Update projector
            if (Event.current.type == EventType.Repaint)
            {
                m_projector.Update(component.IsPainting);
            }
            if (target == null || !component.Alpha.Enabled)
            {
                return;
            }
            component.brushPosition = Vector3.zero;
            bool wasPainting = component.IsPainting;

            tp_Input.Update(component, target, ref component.brushPosition, ref wasPainting, undoMsg);
            component.IsPainting = wasPainting;
        }
Beispiel #2
0
        /// <summary>
        /// Get input
        /// </summary>
        /// <param name="method">Delegate method</param>
        /// <param name="position">Mouse world position</param>
        /// <param name="active">Is painting</param>
        /// <param name="saveMsg">Undo message</param>
        internal static void Update(TP component, tp_ComponentBaseEditor target, ref Vector3 position, ref bool active, string saveMsg = default(string))
        {
            // Get current event
            Event current = Event.current;

            // checkkeys
            int controlID = GUIUtility.GetControlID(TP.HashCode, FocusType.Passive);
            int hotControl = GUIUtility.hotControl;
            EventType filteredControlID = current.GetTypeForControl(controlID);

            switch (filteredControlID)
            {
                // (If mouse down or mouse drag)
                case EventType.MouseDown:
                case EventType.MouseDrag:
                    // Check if current control is Terrain Painter control
                    if (hotControl != controlID && (hotControl != 0) || TP.Instance.SplatmapLock || RotateButtonPressed) { return; }
                    if (current.button != 0 || HandleUtility.nearestControl != controlID || (TP.Instance.EditingTool == EditingTool.Texture && TP.Instance.SplatTool == SplatTool.None)) { return; }

                    if (current.type == EventType.MouseDown) { GUIUtility.hotControl = controlID; }
                    if (!GetPosition(out position)) { break; }
                    if (current.type == EventType.MouseDown)
                    {
                        // Save current splatmap
                        TP.Instance.History.CreateRestorePoint(target.UndoType, saveMsg);
                        if (TP.Instance.Noise.GenerateOnClick) { TP.Instance.Noise.Generate(new Point(component.TerrainData.alphamapWidth, component.TerrainData.alphamapHeight)); }
                    }
                    
                    // Run method, and Painting is in use
                    if (target != null) { target.Paint(false); }
                    active = true;
                    current.Use();
                    break;

                // Update projector position
                case EventType.MouseMove:
                    if (GetPosition(out position)) { HandleUtility.Repaint(); }
                    break;

                // Disable painting, and current control is not Terrain Painter any more
                case EventType.MouseUp:
                    active = false;
                    if (hotControl != controlID || TP.Instance.SplatmapLock) { return; }
                    GUIUtility.hotControl = hotControl = 0;
                    if (TP.Instance.EditingTool == EditingTool.Texture && TP.Instance.SplatTool == SplatTool.None) { return; }
                    current.Use();
                    break;

                // Disable the selection tool
                case EventType.Layout:
                    if (RotateButtonPressed)
                    {
                        HandleUtility.AddDefaultControl(controlID);
                        HandleUtility.Repaint();
                        current.Use();
                        break;
                    }
                    if ((TP.Instance.EditingTool == EditingTool.Texture && TP.Instance.SplatTool == SplatTool.None) || TP.Instance.SplatmapLock) { return; }
                    HandleUtility.AddDefaultControl(controlID);
                    break;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get input
        /// </summary>
        /// <param name="method">Delegate method</param>
        /// <param name="position">Mouse world position</param>
        /// <param name="active">Is painting</param>
        /// <param name="saveMsg">Undo message</param>
        internal static void Update(TP component, tp_ComponentBaseEditor target, ref Vector3 position, ref bool active, string saveMsg = default(string))
        {
            // Get current event
            Event current = Event.current;

            // checkkeys
            int       controlID         = GUIUtility.GetControlID(TP.HashCode, FocusType.Passive);
            int       hotControl        = GUIUtility.hotControl;
            EventType filteredControlID = current.GetTypeForControl(controlID);

            switch (filteredControlID)
            {
            // (If mouse down or mouse drag)
            case EventType.MouseDown:
            case EventType.MouseDrag:
                // Check if current control is Terrain Painter control
                if (hotControl != controlID && (hotControl != 0) || TP.Instance.SplatmapLock || RotateButtonPressed)
                {
                    return;
                }
                if (current.button != 0 || HandleUtility.nearestControl != controlID || (TP.Instance.EditingTool == EditingTool.Texture && TP.Instance.SplatTool == SplatTool.None))
                {
                    return;
                }

                if (current.type == EventType.MouseDown)
                {
                    GUIUtility.hotControl = controlID;
                }
                if (!GetPosition(out position))
                {
                    break;
                }
                if (current.type == EventType.MouseDown)
                {
                    // Save current splatmap
                    TP.Instance.History.CreateRestorePoint(target.UndoType, saveMsg);
                    if (TP.Instance.Noise.GenerateOnClick)
                    {
                        TP.Instance.Noise.Generate(new Point(component.TerrainData.alphamapWidth, component.TerrainData.alphamapHeight));
                    }
                }

                // Run method, and Painting is in use
                if (target != null)
                {
                    target.Paint(false);
                }
                active = true;
                current.Use();
                break;

            // Update projector position
            case EventType.MouseMove:
                if (GetPosition(out position))
                {
                    HandleUtility.Repaint();
                }
                break;

            // Disable painting, and current control is not Terrain Painter any more
            case EventType.MouseUp:
                active = false;
                if (hotControl != controlID || TP.Instance.SplatmapLock)
                {
                    return;
                }
                GUIUtility.hotControl = hotControl = 0;
                if (TP.Instance.EditingTool == EditingTool.Texture && TP.Instance.SplatTool == SplatTool.None)
                {
                    return;
                }
                current.Use();
                break;

            // Disable the selection tool
            case EventType.Layout:
                if (RotateButtonPressed)
                {
                    HandleUtility.AddDefaultControl(controlID);
                    HandleUtility.Repaint();
                    current.Use();
                    break;
                }
                if ((TP.Instance.EditingTool == EditingTool.Texture && TP.Instance.SplatTool == SplatTool.None) || TP.Instance.SplatmapLock)
                {
                    return;
                }
                HandleUtility.AddDefaultControl(controlID);
                break;
            }
        }