Example #1
0
        /// <summary>
        /// Callback from Tool.AddChild to try to handle other
        /// active tools - trying to disable them.
        /// </summary>
        /// <param name="child">Child that has just been added.</param>
        public static void OnChildAdded(Tool child)
        {
            if (child == null)
            {
                return;
            }

            var root = child.GetRoot() as CustomTargetTool;

            if (root == null)
            {
                return;
            }

            foreach (var targetTool in ActiveTools)
            {
                if (targetTool == root)
                {
                    continue;
                }

                Traverse(targetTool, tool =>
                {
                    if (!tool.IsSingleInstanceTool)
                    {
                        return(false);
                    }
                    tool.PerformRemoveFromParent();
                    return(true);
                });
            }
        }
Example #2
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);
            }
        }
Example #3
0
        /// <summary>
        /// Callback from Tool.AddChild to try to handle other
        /// active tools - trying to disable them.
        /// </summary>
        /// <param name="child">Child that has just been added.</param>
        public static void OnChildAdded(Tool child)
        {
            if (child == null)
            {
                return;
            }

            var root = child.GetRoot() as CustomTargetTool;

            if (root == null)
            {
                return;
            }

            foreach (var targetTool in ActiveTools)
            {
                if (targetTool == root)
                {
                    continue;
                }

                foreach (var targetToolChild in targetTool.GetChildren())
                {
                    // Ignoring any route node tools for now. This should disable
                    // any FrameTool that's active under the route node tool.
                    if (targetToolChild is RouteNodeTool)
                    {
                        continue;
                    }

                    targetToolChild.PerformRemoveFromParent();
                }
            }
        }
Example #4
0
        /// <summary>
        /// Callback from Tool.AddChild to try to handle other
        /// active tools - trying to disable them.
        /// </summary>
        /// <param name="child">Child that has just been added.</param>
        public static void OnChildAdded(Tool child)
        {
            if (child == null)
            {
                return;
            }

            var singleInstanceTools   = new List <Tool>();
            Func <Tool, bool> visitor = tool =>
            {
                // We don't want to remove children to our tool that's being added.
                // I.e., return true to not visit 'child' children.
                if (tool == child)
                {
                    return(true);
                }

                if (tool.HasChild(child))
                {
                    return(false);
                }

                // Route node tool is managing its children.
                if (tool.HasParent <RouteNodeTool>())
                {
                    return(false);
                }

                if (!tool.IsSingleInstanceTool)
                {
                    return(false);
                }

                if (tool is CustomTargetTool)
                {
                    return(false);
                }

                singleInstanceTools.Add(tool);

                return(true);
            };

            foreach (var activeTool in ActiveTools)
            {
                Traverse(activeTool, visitor);
            }

            foreach (var toolToRemove in singleInstanceTools)
            {
                toolToRemove.PerformRemoveFromParent();
            }
        }
Example #5
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);
            }
        }
Example #6
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);
            }
        }