コード例 #1
0
        void OnSceneGUI(SceneView sceneView)
        {
            if (mode == null)
            {
                return;
            }

            Event e = Event.current;

            CheckForEscapeKey(e);

            if (Tools.current != Tool.None)
            {
                SetTool(BrushTool.None);
            }

            if (brushSettings == null)
            {
                SetBrushSettings(PolyEditorUtility.GetFirstOrNew <BrushSettings>());
            }

            if (PolySceneUtility.SceneViewInUse(e) || tool == BrushTool.None)
            {
                // Force exit the current brush if user's mouse left
                // the SceneView while a brush was still in use.
                if (m_ApplyingBrush)
                {
                    OnFinishApplyingBrush();
                }
                return;
            }

            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            if (Util.IsValid(brushTarget))
            {
                HandleUtility.AddDefaultControl(controlID);
            }

            switch (e.GetTypeForControl(controlID))
            {
            case EventType.MouseMove:
                // Handles:
                //		OnBrushEnter
                //		OnBrushExit
                //		OnBrushMove
                if (EditorApplication.timeSinceStartup - m_LastBrushUpdate > GetTargetFramerate(brushTarget))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.MouseDown:
            case EventType.MouseDrag:
                // Handles:
                //		OnBrushBeginApply
                //		OnBrushApply
                //		OnBrushFinishApply
                if (EditorApplication.timeSinceStartup - m_LastBrushUpdate > GetTargetFramerate(brushTarget))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                    ApplyBrush(Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.MouseUp:
                if (m_ApplyingBrush)
                {
                    OnFinishApplyingBrush();
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.ScrollWheel:
                ScrollBrushSettings(e);
                break;
            }

            if (Util.IsValid(brushTarget))
            {
                mode.DrawGizmos(brushTarget, brushSettings);
            }
        }
コード例 #2
0
ファイル: PolyEditor.cs プロジェクト: kjr247/Meteor228
        void OnSceneGUI(SceneView sceneView)
        {
            if (mode == null)
            {
                return;
            }

            Event e = Event.current;

            CheckForEscapeKey(e);

            if (Tools.current != Tool.None)
            {
                SetTool(BrushTool.None);
            }

            if (brushSettings == null)
            {
                SetBrushSettings(PolyEditorUtility.GetFirstOrNew <BrushSettings>());
            }

            if (PolySceneUtility.SceneViewInUse(e) || tool == BrushTool.None)
            {
                // Force exit the current brush if user's mouse left
                // the SceneView while a brush was still in use.
                if (m_ApplyingBrush)
                {
                    OnFinishApplyingBrush();
                }
                return;
            }

            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            if (Util.IsValid(brushTarget))
            {
                HandleUtility.AddDefaultControl(controlID);
            }

            switch (e.GetTypeForControl(controlID))
            {
            case EventType.MouseMove:
                // Handles:
                //		OnBrushEnter
                //		OnBrushExit
                //		OnBrushMove
                if (EditorApplication.timeSinceStartup - m_LastBrushUpdate > GetTargetFramerate(brushTarget))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.MouseDown:
            case EventType.MouseDrag:
                // Handles:
                //		OnBrushBeginApply
                //		OnBrushApply
                //		OnBrushFinishApply
                if (EditorApplication.timeSinceStartup - m_LastBrushUpdate > GetTargetFramerate(brushTarget))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                    ApplyBrush(Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.MouseUp:
                if (m_ApplyingBrush)
                {
                    OnFinishApplyingBrush();
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.ScrollWheel:
                ScrollBrushSettings(e);
                break;

            case EventType.KeyDown:
                // Key down event continues as long as the key is held down. However, we only need to update the brush once while the key is down.
                // Check if the key has already been marked as pressed in the brush settings, and don't update if it is.
                if (((e.keyCode == KeyCode.LeftControl || e.keyCode == KeyCode.RightControl) && !brushSettings.isUserHoldingControl) ||
                    ((e.keyCode == KeyCode.LeftShift || e.keyCode == KeyCode.RightShift) && !brushSettings.isUserHoldingShift))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;

            case EventType.KeyUp:
                // Key up only happens once, so don't need to check if we were already holding control/shift
                if ((e.keyCode == KeyCode.LeftControl || e.keyCode == KeyCode.RightControl) ||
                    (e.keyCode == KeyCode.LeftShift || e.keyCode == KeyCode.RightShift))
                {
                    m_LastBrushUpdate = EditorApplication.timeSinceStartup;
                    UpdateBrush(e.mousePosition, Event.current.control, Event.current.shift && Event.current.type != EventType.ScrollWheel);
                }
                break;
            }

            if (Util.IsValid(brushTarget))
            {
                mode.DrawGizmos(brushTarget, brushSettings);
            }
        }