void SetColor()
        {
            TargetColor = GetColor();

            if (BehaviourTreeEditor.GetInstance().ExecuteInRuntime())
            {
                CurrentColor = Color.Lerp(CurrentColor, TargetColor, Time.deltaTime);
            }
            else
            {
                CurrentColor = TargetColor;
            }

            GUI.color = CurrentColor;
        }
        void OnGUI()
        {
            if (instance == null)
            {
                instance = this;
            }

            editorSize = new Vector2(position.width, position.height);

            if (TreeAsset != null)
            {
                GUILayout.BeginVertical();
                {
                    DrawToolbar();

                    GUILayout.BeginHorizontal();
                    {
                        DrawNodeGraph();

                        if (showParameters)
                        {
                            EditorGUILayout.BeginVertical(GUILayout.Width(300));
                            {
                                DrawParameterList();
                            }
                            EditorGUILayout.EndVertical();
                        }
                    }
                    GUILayout.EndHorizontal();

                    Nodes.HandleEvents(this);

                    DrawFooter();
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                GUI.Label(new Rect(editorSize.x * 0.5f - 175, editorSize.y * 0.5f - 15, 350, 30), "Select Behaviour Tree in project tab to edit, or create new ");
                if (GUI.Button(new Rect(editorSize.x * 0.5f - 50, editorSize.y * 0.5f + 15, 100, 20), "Create"))
                {
                    CreateNewBehaviourTree();
                }
            }
        }
        void DrawParentDot(Rect dotRect)
        {
            if (TreeNode && TreeNode.Parent)
            {
                GUI.Box(
                    new Rect(dotRect.center.x - ConnectorSize.x * 0.5f, dotRect.yMin - ConnectorSize.y * 0.5f, ConnectorSize.x, ConnectorSize.y),
                    GUIContent.none, SpaceEditorStyles.DotFlowTarget
                    );

                if (BehaviourTreeEditor.GetInstance().ExecuteInRuntime())
                {
                    GUI.color = CurrentColor;
                }

                GUI.Box(
                    new Rect(dotRect.center.x - ConnectorSize.x * 0.5f, dotRect.yMin - ConnectorSize.y * 0.5f, ConnectorSize.x, ConnectorSize.y),
                    GUIContent.none, SpaceEditorStyles.DotFlowTargetFill
                    );

                GUI.color = Color.white;
            }
        }
        Color GetColor()
        {
            if (BehaviourTreeEditor.GetInstance() != null &&
                BehaviourTreeEditor.GetInstance().ExecuteInRuntime())
            {
                switch (BehaviourTreeEditor.GetInstance().CheckNodeStatus(TreeNode))
                {
                case NodeResult.Suspended:
                    return(Color.gray);

                case NodeResult.Success:
                    return(Color.green);

                case NodeResult.Failrue:
                    return(Color.red);

                case NodeResult.Running:
                    return(Color.yellow);

                default:
                    return(Color.clear);
                }
            }
            else if (TreeNode.IsRootNode())
            {
                return(Color.blue + Color.grey);
            }
            else if (TreeNode.IsParentNode())
            {
                return(Color.cyan + Color.grey);
            }
            else
            {
                return(Color.white);
            }
        }
 public static void ShowEditor()
 {
     instance = EditorWindow.GetWindow <BehaviourTreeEditor>();
 }