예제 #1
0
 public void ConnectRightKill(NodeBranch parent, Node child)
 {
     if (parent == child)
     {
         return;
     }
     parent.ConnectKillRightChild(child);
     Dirty();
 }
예제 #2
0
        public void ConnectRight(NodeBranch parent, Node child)
        {
            if (parent == child)
            {
                return;
            }
            if (parent.CanConnectChild)
            {
                parent.ConnectRightChild(child);
//				SortChildren(parent);
                Dirty();
            }
            else
            {
                Debug.LogWarning(string.Format("{0} can't accept child {1}", parent, child));
            }
        }
예제 #3
0
파일: Node.cs 프로젝트: coolape/mibao
        // All connections
        public virtual void Disconnect()
        {
            // Disconnect parent
            Node parent = null;

            for (int i = 0; i < parents.Count; i++)
            {
                parent = parents [i];
                if (parent != null)
                {
                    Unparent(parent);
                }
            }
            parents.Clear();

            // Disconnect children
            if (ChildCount > 0)
            {
                for (int i = ChildCount - 1; i >= 0; i--)
                {
                    DisconnectChild(Children [i]);
                }
            }

            for (int i = KillNodes.Count - 1; i >= 0; i--)
            {
                DisconnectKillChild(KillNodes [i]);
            }
            Node killNode = null;

            for (int i = ParentKillNodes.Count - 1; i >= 0; i--)
            {
                killNode = ParentKillNodes [i];
                killNode.DisconnectKillChild(this);
                if (killNode is NodeBranch)
                {
                    NodeBranch branch = killNode as NodeBranch;
                    branch.DisconnectKillLeftChild(this);
                    branch.DisconnectKillRightChild(this);
                }
            }
        }
예제 #4
0
        public void doGenerateNodeState(Node node, ref Hashtable map)
        {
            if (MapEx.getBool(map, node) || node == node.behaviorTree.rootNode)
            {
                return;
            }
            map [node] = true;

            int    mainType = 14;
            string pubStr   = "";

            if (node.behaviorTree.rootNode.attr != null)
            {
                pubStr = mainType + "/" + ((MyRoot)(node.behaviorTree.rootNode.attr)).fubenID + "/";
            }
            else
            {
                pubStr = mainType + "/" + 0 + "/";
            }

            //Condition
            if (node.parents != null && node.parents.Count > 0)
            {
                node.condition = "{";
                if ((node.parents.Count == 1 && (node.parents [0]) is Root))
                {
                    node.condition += "{\"" + pubStr + node.index + "/" + 0 + "\"}";
                }
                else if (node.parents.Contains(node.behaviorTree.rootNode))
                {
                    node.condition += "{\"" + pubStr + node.index + "/" + 0 + "\",\"" + pubStr + node.index + "/" + 1 + "\"}";
                }
                else
                {
                    node.condition += "{\"" + pubStr + node.index + "/" + 1 + "\"}";
                }

                if (node is NodeTogether)
                {
                    Node parent = null;
                    for (int i = 0; i < node.parents.Count; i++)
                    {
                        parent = node.parents [i];
                        if (parent is  Root)
                        {
                        }
                        else if (parent is NodeBranch)
                        {
                            if (((NodeBranch)parent).inLeft(node))
                            {
                                node.condition += ",{\"" + pubStr + (-node.parents [i].index) + "/" + 1 + "\"}";
                            }
                            if (((NodeBranch)parent).inRight(node))
                            {
                                node.condition += ",{\"" + pubStr + (-node.parents [i].index) + "/" + 2 + "\"}";
                            }
                        }
                        else
                        {
                            node.condition += ",{\"" + pubStr + (-node.parents [i].index) + "/" + 1 + "\"}";
                        }
                    }
                }
                node.condition += "}";
            }
            else
            {
                node.condition = "{{\"" + pubStr + node.index + "/" + 0 + "\"}}";
            }
            //result
            if (node is NodeBranch)
            {
                NodeBranch branch = node as NodeBranch;
                node.result1 = getResultWithSubNodes(branch, branch.ChildrenLeft, branch.KillLeftNodes);
                node.result2 = getResultWithSubNodes(branch, branch.ChildrenRight, branch.KillRightNodes);
            }
            else
            {
                node.result1 = getResultWithSubNodes(node, node.Children, node.KillNodes);
                node.result2 = node.result1;
            }
        }
예제 #5
0
        public void Draw(Node node, bool selected)
        {
            float shadowOffset = 3;

            Vector2 offset = new Vector2(shadowOffset, shadowOffset);

            // Edge
            for (int i = 0; i < node.parents.Count; i++)
            {
                if (node.parents [i] is NodeBranch)
                {
                    Vector2 startPos = node.parents [i].editorPosition;
                    if (((NodeBranch)(node.parents [i])).inLeft(node))
                    {
                        startPos.x -= (NodeRenderer.Width / 4);
                        // Shadow
                        DrawEdge(startPos + offset, node.editorPosition + offset, Width, Height, shadowColor);
                        // Line
                        DrawEdge(startPos, node.editorPosition, Width, Height, edgeColor);
                    }
                    startPos = node.parents [i].editorPosition;
                    if (((NodeBranch)(node.parents [i])).inRight(node))
                    {
                        startPos.x += (NodeRenderer.Width / 4);
                        // Shadow
                        DrawEdge(startPos + offset, node.editorPosition + offset, Width, Height, shadowColor);
                        // Line
                        DrawEdge(startPos, node.editorPosition, Width, Height, edgeColor);
                    }
                }
                else
                {
                    // Shadow
                    DrawEdge(node.parents [i].editorPosition + offset, node.editorPosition + offset, Width, Height, shadowColor);
                    // Line
                    DrawEdge(node.parents [i].editorPosition, node.editorPosition, Width, Height, edgeColor);
                }
            }

            //Kill nodes
            if (node is NodeBranch)
            {
                NodeBranch branch = node as NodeBranch;
                for (int i = 0; i < branch.KillLeftNodes.Count; i++)
                {
                    Vector2 startPos = node.editorPosition;
                    startPos.x -= (NodeRenderer.Width / 4);
                    // Shadow
                    DrawEdge(startPos + offset, branch.KillLeftNodes [i].editorPosition + offset, Width, Height, shadowColor);
                    // Line
                    DrawEdge(startPos, branch.KillLeftNodes [i].editorPosition, Width, Height, Color.red);
                }
                for (int i = 0; i < branch.KillRightNodes.Count; i++)
                {
                    if (branch.KillRightNodes [i] == null)
                    {
                        continue;
                    }
                    Vector2 startPos = node.editorPosition;
                    startPos.x += (NodeRenderer.Width / 4);
                    // Shadow
                    DrawEdge(startPos + offset, branch.KillRightNodes [i].editorPosition + offset, Width, Height, shadowColor);
                    // Line
                    DrawEdge(startPos, branch.KillRightNodes [i].editorPosition, Width, Height, Color.red);
                }
            }
            else
            {
                for (int i = 0; i < node.KillNodes.Count; i++)
                {
                    // Shadow
                    DrawEdge(node.editorPosition + offset, node.KillNodes [i].editorPosition + offset, Width, Height, shadowColor);
                    // Line
                    DrawEdge(node.editorPosition, node.KillNodes [i].editorPosition, Width, Height, Color.red);
                }
            }

            // Node Shadow

            Rect nodeRect   = new Rect(node.editorPosition.x, node.editorPosition.y, Width, Height);
            Rect shadowRect = new Rect(nodeRect.x + shadowOffset, nodeRect.y + shadowOffset, nodeRect.width, nodeRect.height);

            if (shadowTexture == null)
            {
                shadowTexture           = new Texture2D(1, 1);
                shadowTexture.hideFlags = HideFlags.DontSave;
                shadowTexture.SetPixel(0, 0, shadowColor);
                shadowTexture.Apply();
            }

            GUI.DrawTexture(shadowRect, shadowTexture);

            // Node
            if (nodeTexture == null)
            {
                Color colA = new Color(0.765f, 0.765f, 0.765f);
                Color colB = new Color(0.886f, 0.886f, 0.886f);

                nodeTexture           = new Texture2D(1, (int)Height);
                nodeTexture.hideFlags = HideFlags.DontSave;
                for (int y = 0; y < Height; y++)
                {
                    nodeTexture.SetPixel(0, y, Color.Lerp(colA, colB, (float)y / 75));
                }
                nodeTexture.Apply();
            }

            // Node Debug
            if (nodeDebugTexture == null)
            {
                Color colA = new Color(1.000f, 0.796f, 0.357f);
                Color colB = new Color(0.894f, 0.443f, 0.008f);

                nodeDebugTexture           = new Texture2D(1, (int)Height);
                nodeDebugTexture.hideFlags = HideFlags.DontSave;
                for (int y = 0; y < Height; y++)
                {
                    nodeDebugTexture.SetPixel(0, y, Color.Lerp(colA, colB, (float)y / 75));
                }
                nodeDebugTexture.Apply();
            }

            if (node.behaviorTree.debugMode && node.behaviorTree.currentNode == node)
            {
                GUI.DrawTexture(nodeRect, nodeDebugTexture);
            }
            else
            {
                GUI.DrawTexture(nodeRect, nodeTexture);
            }

            // Icons
            DrawNodeIcon(nodeRect, node);

            GUI.color = Color.black;
            EditorGUI.LabelField(new Rect(nodeRect.x, nodeRect.y + 58, nodeRect.width, nodeRect.height), node.index.ToString());
            GUI.color = Color.white;
            DrawMuttimesIcon(nodeRect, node);
            // Debug status
//			DrawStatusIcon (nodeRect, node);

            // Action title
            if (node is NodeAction)
            {
                // Node title
                string title = node.desc;
//				if (((Action)node).methodInfo != null)
//					title = ((Action)node).methodName;
//				else
//					title = "";
                title = title.Replace(".", ".\n");
                Vector2 textSize  = GUI.skin.label.CalcSize(new GUIContent(title));
                float   x         = node.editorPosition.x + (Width / 2) - (textSize.x / 2) - 6;
                Rect    titleRect = new Rect(x, node.editorPosition.y + Height, textSize.x + 10, textSize.y);
                EditorGUI.DropShadowLabel(titleRect, new GUIContent(title));
            }

            // Selection highlight
            if (selected)
            {
                if (selectionTexture == null)
                {
                    selectionTexture           = new Texture2D(1, 1);
                    selectionTexture.hideFlags = HideFlags.DontSave;
                    selectionTexture.SetPixel(0, 0, selColor);
                    selectionTexture.Apply();
                }

                float mbOffset = selMargin + selWidth;                                                                                                                   // Margin + Border offset
                GUI.DrawTexture(new Rect(nodeRect.x - mbOffset, nodeRect.y - mbOffset, nodeRect.width + mbOffset * 2, selWidth), selectionTexture);                      // Top
                GUI.DrawTexture(new Rect(nodeRect.x - mbOffset, nodeRect.y - selMargin, selWidth, nodeRect.height + selMargin * 2), selectionTexture);                   // Left
                GUI.DrawTexture(new Rect(nodeRect.x + nodeRect.width + selMargin, nodeRect.y - selMargin, selWidth, nodeRect.height + selMargin * 2), selectionTexture); // Right
                GUI.DrawTexture(new Rect(nodeRect.x - mbOffset, nodeRect.y + nodeRect.height + selMargin, nodeRect.width + mbOffset * 2, selWidth), selectionTexture);   // Top
            }
        }