Exemple #1
0
        void OnSceneGUI(SceneView sv)
        {
            if (!drawing)
            {
                if (preview != null)
                {
                    MonoBehaviour.DestroyImmediate(preview.gameObject);
                }

                previewLocked = false;
                return;
            }

            if (!InternalEditorUtility.isApplicationActive)
            {
                return;
            }

            GameObject prefab = GetPrefab();

            if (prefab == null)
            {
                return;
            }

            Event e = Event.current;

            Handles.BeginGUI();
            GUI.Label(new Rect(e.mousePosition.x + mosuePosOffset, (e.mousePosition.y + mosuePosOffset) - 75, sceneViewBoxSize, sceneViewBoxSize), GetHint());
            Handles.EndGUI();


            EditorWindowTools.FocusSceneViewOnMouseOver();


            Event current = Event.current;

            if (EventType.KeyUp == current.type)
            {
                bool earlyOut = false;
                if (exitDrawKey == current.keyCode)
                {
                    drawing  = false;
                    earlyOut = true;
                    MonoBehaviour.DestroyImmediate(preview.gameObject);
                }
                if (lockPreviewKey == current.keyCode)
                {
                    earlyOut      = true;
                    previewLocked = !previewLocked;
                }
                if (switchDrawModeKey == current.keyCode)
                {
                    earlyOut = true;
                    SwitchDrawMode();
                }
                if (alignNormalKey == current.keyCode)
                {
                    earlyOut    = true;
                    alignNormal = !alignNormal;
                }
                if (randomizePreviewKey == current.keyCode)
                {
                    earlyOut = true;
                    UpdatePreviewRandom();
                }
                if (earlyOut)
                {
                    current.Use();
                    Repaint();
                    return;
                }
            }

            bool focus = false;

            if ((EventType.KeyUp == current.type || EventType.KeyDown == current.type) && focusKey == current.keyCode)
            {
                focus = EventType.KeyUp == current.type;
                current.Use();
            }

            if (EventType.ScrollWheel == current.type && current.command)
            {
                radius += current.delta.y;
                current.Use();
            }

            int      controlId = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);
            Collider hitCollider;
            bool     isValid = CalculateMousePosition(out hitCollider);

            if (isValid)
            {
                if (drawMode == DrawMode.Field || drawMode == DrawMode.RandomArea)
                {
                    Handles.color = current.shift ? GUITools.red : GUITools.white;
                    if (drawMode == DrawMode.Field)
                    {
                        Matrix4x4 mat = Handles.matrix;
                        Handles.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.FromToRotation(Vector3.up, hitNormal), Vector3.one);
                        Handles.DrawWireCube(hitPos, new Vector3(radius * 2, 1, radius * 2));
                        Handles.matrix = mat;
                    }
                    else if (drawMode == DrawMode.RandomArea)
                    {
                        Handles.DrawWireDisc(hitPos, hitNormal, radius);
                    }
                }

                if (focus)
                {
                    SceneView.lastActiveSceneView.Frame(new Bounds(hitPos, Vector3.one * radius), false);
                }

                if ((current.type == EventType.MouseDown) && !current.alt)
                {
                    if (current.button == 0)
                    {
                        if (!current.shift)
                        {
                            PrefabInstantiate(prefab);
                        }
                        else
                        {
                            PrefabRemove(hitCollider);
                        }
                    }
                }
            }

            HandlePreview(isValid, current.shift);

            if (Event.current.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(controlId);
            }

            SceneView.RepaintAll();
        }
Exemple #2
0
        static public void OnSceneGUI(SerializedProperty locationList, int hashID)
        {
            if (!drawing)
            {
                return;
            }

            if (!InternalEditorUtility.isApplicationActive)
            {
                return;
            }

            Vector2 mousePos = Event.current.mousePosition;

            Handles.BeginGUI();
            GUI.Label(new Rect(mousePos.x + 8, (mousePos.y + 8) - 75, 256, 256), string.Format("Left Click: Draw\n{0}: Focus area\n{1}: Exit Draw\n{2}: Rotate Preview\n", KeyCode.F, KeyCode.Escape, KeyCode.Space));
            Handles.EndGUI();

            EditorWindowTools.FocusSceneViewOnMouseOver();

            Event current = Event.current;

            if (EventType.KeyUp == current.type)
            {
                bool earlyOut = false;
                if (KeyCode.Escape == current.keyCode)
                {
                    drawing  = false;
                    earlyOut = true;
                }
                if (KeyCode.Space == current.keyCode)
                {
                    earlyOut = true;
                    yAngle   = (yAngle + 15f) % 360f;
                }
                if (earlyOut)
                {
                    current.Use();
                    return;
                }
            }

            bool focus = false;

            if ((EventType.KeyUp == current.type || EventType.KeyDown == current.type) && KeyCode.F == current.keyCode)
            {
                focus = EventType.KeyUp == current.type;
                current.Use();
            }

            int  controlId = GUIUtility.GetControlID(hashID, FocusType.Passive);
            bool isValid   = CalculateMousePosition(mousePos);

            if (isValid)
            {
                Handles.DrawWireDisc(hitPos, Vector3.up, 1f);

                if (focus)
                {
                    SceneView.lastActiveSceneView.Frame(new Bounds(hitPos, Vector3.one), false);
                }

                if ((current.type == EventType.MouseDown) && !current.alt)
                {
                    if (current.button == 0)
                    {
                        AddNewSubLocation(locationList);
                    }
                }

                GUI.enabled = false;
                Handles.PositionHandle(hitPos, Quaternion.Euler(0, yAngle, 0));
                GUI.enabled = true;
            }

            if (Event.current.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(controlId);
            }

            SceneView.RepaintAll();
        }