예제 #1
0
        /// <summary>
        /// Depth-first recursive Tool.OnSceneViewGUI calls, including
        /// update of a tools key handlers with current event.
        /// </summary>
        /// <param name="tool">Current parent tool.</param>
        /// <param name="sceneView">Scene view.</param>
        private static void HandleOnSceneView(Tool tool, SceneView sceneView)
        {
            if (tool == null)
            {
                return;
            }

            // Previously we had:
            //   1. HandleOnSceneView for all children.
            //   2. Update all my key handlers.
            //   3. HandleOnSceneView for 'tool'.

            // Update 'tool' key handlers, so they're up to date when OnSceneView is called.
            foreach (var keyHandler in tool.KeyHandlers)
            {
                keyHandler.Update(Event.current);
            }

            tool.OnSceneViewGUI(sceneView);

            // Depth first traverse of children.
            foreach (var child in tool.GetChildren())
            {
                HandleOnSceneView(child, sceneView);
            }
        }
예제 #2
0
        private static void TraverseActive(Tool parent, Action <Tool> visitor)
        {
            if (parent == null || visitor == null)
            {
                return;
            }

            visitor(parent);

            foreach (var child in parent.GetChildren())
            {
                TraverseActive(child, visitor);
            }
        }
예제 #3
0
        /// <summary>
        /// Depth-first visit with optional break.
        /// </summary>
        /// <param name="tool">Tool to traverse.</param>
        /// <param name="visitor">Visitor function - return true to break, false to continue.</param>
        private static void Traverse(Tool tool, Func <Tool, bool> visitor)
        {
            if (tool == null || visitor == null)
            {
                return;
            }

            if (visitor(tool))
            {
                return;
            }

            foreach (var child in tool.GetChildren())
            {
                Traverse(child, visitor);
            }
        }
예제 #4
0
        /// <summary>
        /// Recursive depth-first visit of tool and its children.
        /// </summary>
        /// <param name="tool">Current parent tool.</param>
        /// <param name="visitor">Visitor.</param>
        private static void Traverse <T>(Tool tool, Action <T> visitor)
            where T : Tool
        {
            if (tool == null || visitor == null)
            {
                return;
            }

            if (tool is T)
            {
                visitor(tool as T);
            }

            foreach (var child in tool.GetChildren())
            {
                Traverse(child, visitor);
            }
        }