public override void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }

            if (Tools.current != Tool.Custom || !ChiselEditGeneratorTool.IsActive())
            {
                OnDefaultSceneTools();
                return;
            }

            var generator = target as T;

            if (GUIUtility.hotControl == 0)
            {
                if (!OnGeneratorValidate(generator))
                {
                    if (validTargets.Contains(generator))
                    {
                        OnGeneratorDeselected(generator);
                        validTargets.Remove(generator);
                    }
                    return;
                }
                if (!validTargets.Contains(generator))
                {
                    OnGeneratorSelected(generator);
                    validTargets.Add(generator);
                }
            }

            var sceneView = SceneView.currentDrawingSceneView;

            var modelMatrix   = ChiselNodeHierarchyManager.FindModelTransformMatrixOfTransform(generator.hierarchyItem.Transform);
            var generatorNode = generator.TopNode;

            if (!generatorNode.Valid)
            {
                return;
            }

            // NOTE: could loop over multiple instances from here, once we support that
            {
                using (new UnityEditor.Handles.DrawingScope(UnityEditor.Handles.yAxisColor, modelMatrix * generatorNode.NodeToTreeSpaceMatrix))
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        OnScene(sceneView, generator);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        OnTargetModifiedInScene();
                    }
                }
            }
        }
        public virtual void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }

            if (Tools.current != Tool.Custom || !ChiselEditGeneratorTool.IsActive())
            {
                OnDefaultSceneTools();
                return;
            }
        }
        public override void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }

            if (Tools.current != Tool.Custom || !ChiselEditGeneratorTool.IsActive())
            {
                OnDefaultSceneTools();
                return;
            }

            // Skip some events, to prevent scalability issues (when selecting thousands of brushes at the same time)
            // Could happen when doing control-A (select all)
            switch (Event.current.type)
            {
            case EventType.MouseEnterWindow:
            case EventType.MouseLeaveWindow:
            case EventType.Ignore:
            case EventType.Used:
                return;

            case EventType.MouseDown:
            case EventType.MouseUp:
            case EventType.MouseDrag:
            case EventType.DragExited:
            case EventType.DragPerform:
            case EventType.DragUpdated:
            {
                // Mouse messages don't make sense when the mouse is not over the current window
                if (SceneView.currentDrawingSceneView != EditorWindow.mouseOverWindow)
                {
                    return;
                }
                break;
            }
            }

            var generator   = target as T;
            var sceneView   = SceneView.currentDrawingSceneView;
            var modelMatrix = ChiselNodeHierarchyManager.FindModelTransformMatrixOfTransform(generator.hierarchyItem.Transform);

            // NOTE: allow invalid nodes to be edited to be able to recover from invalid state

            // NOTE: could loop over multiple instances from here, once we support that
            {
                using (new UnityEditor.Handles.DrawingScope(SceneHandles.handleColor, modelMatrix * generator.LocalTransformationWithPivot))
                {
                    handles.Start(generator, sceneView);
                    {
                        if (GUIUtility.hotControl == 0)
                        {
                            if (!OnGeneratorActive(generator))
                            {
                                if (validTargets.Contains(generator))
                                {
                                    handles.generatorStateLookup.Remove(generator);
                                    OnGeneratorDeselected(generator);
                                    validTargets.Remove(generator);
                                }
                                return;
                            }
                            if (!validTargets.Contains(generator))
                            {
                                handles.generatorStateLookup.Remove(generator);
                                OnGeneratorDeselected(generator);
                                validTargets.Add(generator);
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        try
                        {
                            OnScene(handles, generator);
                        }
                        finally
                        {
                            if (EditorGUI.EndChangeCheck())
                            {
                                generator.OnValidate();
                                OnTargetModifiedInScene();
                            }
                            handles.End();
                        }
                    }
                }
            }
        }
Example #4
0
        public override void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }

            if (Tools.current != Tool.Custom || !ChiselEditGeneratorTool.IsActive())
            {
                OnDefaultSceneTools();
                return;
            }

            var generator   = target as T;
            var sceneView   = SceneView.currentDrawingSceneView;
            var modelMatrix = ChiselNodeHierarchyManager.FindModelTransformMatrixOfTransform(generator.hierarchyItem.Transform);

            // NOTE: allow invalid nodes to be edited to be able to recover from invalid state

            // NOTE: could loop over multiple instances from here, once we support that
            {
                using (new UnityEditor.Handles.DrawingScope(SceneHandles.handleColor, modelMatrix * generator.LocalTransformationWithPivot))
                {
                    handles.Start(generator, sceneView);
                    {
                        if (GUIUtility.hotControl == 0)
                        {
                            if (!OnGeneratorActive(generator))
                            {
                                if (validTargets.Contains(generator))
                                {
                                    handles.generatorStateLookup.Remove(generator);
                                    OnGeneratorDeselected(generator);
                                    validTargets.Remove(generator);
                                }
                                return;
                            }
                            if (!validTargets.Contains(generator))
                            {
                                handles.generatorStateLookup.Remove(generator);
                                OnGeneratorDeselected(generator);
                                validTargets.Add(generator);
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        try
                        {
                            OnScene(handles, generator);
                        }
                        finally
                        {
                            if (EditorGUI.EndChangeCheck())
                            {
                                generator.OnValidate();
                                OnTargetModifiedInScene();
                            }
                            handles.End();
                        }
                    }
                }
            }
        }