コード例 #1
0
 private void drawCurNodeLabel(Rect labelRect, SwitchTree tree)
 {
     EditorGUI.LabelField(labelRect, new GUIContent("Current active state: "
                                                    + tree.curActiveNodeName,
                                                    "This is the node name that will be returned "
                                                    + "by the currentState property."));
 }
コード例 #2
0
        private SwitchTree makeSwitchTree(SerializedProperty treeProperty)
        {
            var treeRootTransform = (treeProperty.FindPropertyRelative("rootSwitchBehaviour")
                                     .objectReferenceValue as MonoBehaviour).transform;
            var hierarchyHash = Hash.GetHierarchyHash(treeRootTransform);


            HashTreePair hashTreePair;

            if (_cachedSwitchTrees.TryGetValue(treeRootTransform, out hashTreePair) &&
                hashTreePair.hash == hierarchyHash)
            {
                // Either there's no tree for this transform, or the hierarchy of the transform
                // has changed (switches may have been disabled, enabled, added, or removed).

                return(hashTreePair.tree);
            }
            else
            {
                // Construct a new tree and cache it.
                var newTree = new SwitchTree(treeRootTransform,
                                             (treeProperty.FindPropertyRelative("_curActiveNodeName")
                                              .stringValue));

                _cachedSwitchTrees[treeRootTransform] = new HashTreePair()
                {
                    hash = hierarchyHash,
                    tree = newTree
                };

                return(newTree);
            }
        }
コード例 #3
0
            public DepthFirstEnumerator(SwitchTree tree, HashSet <Node> useToTrackVisitedNodes)
            {
                useToTrackVisitedNodes.Clear();

                this.tree    = tree;
                maybeCurNode = Maybe.None;
                visitedNodes = useToTrackVisitedNodes;
            }
コード例 #4
0
 private void refreshTree()
 {
     if (tree == null)
     {
         tree = new SwitchTree(this.transform, null);
     }
     else
     {
         var curActiveNodeName = tree.curActiveNodeName;
         tree.Initialize(this.transform, curActiveNodeName);
     }
 }
コード例 #5
0
        private void drawNode(SwitchTree.Node node, Rect rect, SwitchTree switchTree,
                              SerializedProperty treeProperty,
                              bool isEvenRow = true)
        {
            if (node.treeDepth == 0)
            {
                drawControllerBackground(rect);
            }
            else
            {
                drawTreeBackground(rect, isEvenRow);
            }

            Rect indentRect;
            Rect labelRect = rect.PadLeft(INDENT_WIDTH * (node.treeDepth + 1), out indentRect);

            drawNodeLabel(labelRect, node);

            Rect fullButtonRect = indentRect.TakeRight(INDENT_WIDTH, out indentRect);


            #region Debug Rects

            //EditorGUI.DrawRect(indentRect, Color.cyan);
            //EditorGUI.DrawRect(fullButtonRect, Color.magenta);

            #endregion


            // Line drawing.
            if (node.hasChildren)
            {
                bool anyChildGlowDueToParent = node.isOn && node.children
                                               .Query()
                                               .Any(c => c.isOn);
                drawCenteredLine(Direction4.Down, fullButtonRect,
                                 anyChildGlowDueToParent ? LineType.Glow : LineType.Default);
            }
            if (node.hasParent)
            {
                bool glowingDueToParent = node.isOn && node.isParentOn;
                drawCenteredLine(Direction4.Left, fullButtonRect,
                                 glowingDueToParent ? LineType.Glow : LineType.Default);
            }

            // Leftward rects.
            var  curNode       = node;
            bool firstLeftward = true;
            while (curNode.hasParent)
            {
                Rect leftwardRect = indentRect.TakeRight(INDENT_WIDTH, out indentRect);

                bool glowingDueToParent = curNode.isOn && curNode.isParentOn;

                bool isAnyPrevSiblingOnDueToParent = curNode.prevSiblings
                                                     .Query()
                                                     .Any(n => n.isOn && n.isParentOn);

                bool isSelfOrAnyPrevSiblingOnDueToParent = glowingDueToParent ||
                                                           isAnyPrevSiblingOnDueToParent;

                if (firstLeftward)
                {
                    drawCenteredLine(Direction4.Right, leftwardRect,
                                     glowingDueToParent ? LineType.Glow : LineType.Default);
                    drawCenteredLine(Direction4.Up, leftwardRect,
                                     isSelfOrAnyPrevSiblingOnDueToParent ? LineType.Glow
                                                               : LineType.Default);
                    firstLeftward = false;
                }
                else if (curNode.hasPrevSibling)
                {
                    drawCenteredLine(Direction4.Up, leftwardRect,
                                     isAnyPrevSiblingOnDueToParent ? LineType.Glow
                                                         : LineType.Default);
                }

                if (curNode.hasPrevSibling)
                {
                    drawCenteredLine(Direction4.Down, leftwardRect,
                                     isAnyPrevSiblingOnDueToParent ? LineType.Glow
                                                         : LineType.Default);
                }

                curNode = curNode.hasParent ? curNode.parent.node : default(SwitchTree.Node);
            }


            Rect buttonRect = fullButtonRect.PadInner(BUTTON_RECT_INNER_PAD);

            // Support undo history.
            Undo.IncrementCurrentGroup();
            var curGroupIdx = Undo.GetCurrentGroup();

            bool test_isNodeOff = node.isOff;
            if (test_isNodeOff)
            {
                EditorGUI.DrawRect(buttonRect, Color.red);
            }

            Color origContentColor = GUI.contentColor;
            if (node.isOn)
            {
                Rect glowRect = buttonRect.Extrude(GLOW_WIDTH);
                EditorGUI.DrawRect(glowRect, glowBackgroundColor);
                GUI.contentColor = glowContentColor;
            }

            if (GUI.Button(buttonRect, new GUIContent("Switch to this node.")))
            {
                // Note: It is the responsibility of the IPropertySwitch implementation
                // to perform operations that correctly report their actions in OnNow() to the
                // Undo history!
                switchTree.SwitchTo(node.transform.name, immediately: !Application.isPlaying);
                treeProperty.FindPropertyRelative("_curActiveNodeName").stringValue = node.transform.name;
            }

            Undo.CollapseUndoOperations(curGroupIdx);
            Undo.SetCurrentGroupName("Set Switch Tree State");

            if (node.isOn)
            {
                GUI.contentColor = origContentColor;
            }
        }
コード例 #6
0
 private void refreshTree()
 {
     tree = new SwitchTree(this.transform, tree == null ? null : tree.curActiveNodeName);
 }