예제 #1
0
    public static void ApplyGraphChange(GraphOwner go, GameObject instance)
    {
        //--------------------- 同步更新prefab资源
        bool isBound = go.graphIsBound;

        if (!isBound)
        {
            return;
        }

        var prefabType = UnityEditor.PrefabUtility.GetPrefabType(go.gameObject);

        if (prefabType == UnityEditor.PrefabType.PrefabInstance)
        {
            if (!Application.isPlaying)
            {
                GameObject prefab = (GameObject)PrefabUtility.GetCorrespondingObjectFromSource(instance);

                List <Graph> allNestGraphs = go.graph.GetAllNestedGraphs <Graph>(true);

                foreach (var v in allNestGraphs)
                {
                    if (!NestedUtility.CheckHasThisAsset(v, prefab))
                    {
                        UnityEditor.AssetDatabase.AddObjectToAsset(v, prefab);
                    }
                }

                UnityEditor.EditorApplication.delayCall +=
                    () => { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(prefab)); };
                AssetDatabase.Refresh();
            }
        }
    }
        ///----------------------------------------------------------------------------------------------

        //PREFS MENU
        static GenericMenu GetToolbarMenu_Prefs(Graph graph, GraphOwner owner)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Show Icons"), Prefs.showIcons, () => { Prefs.showIcons = !Prefs.showIcons; });
            menu.AddItem(new GUIContent("Show Node Help"), Prefs.showNodeInfo, () => { Prefs.showNodeInfo = !Prefs.showNodeInfo; });
            menu.AddItem(new GUIContent("Show Comments"), Prefs.showComments, () => { Prefs.showComments = !Prefs.showComments; });
            menu.AddItem(new GUIContent("Show Summary Info"), Prefs.showTaskSummary, () => { Prefs.showTaskSummary = !Prefs.showTaskSummary; });
            menu.AddItem(new GUIContent("Show Node IDs"), Prefs.showNodeIDs, () => { Prefs.showNodeIDs = !Prefs.showNodeIDs; });
            menu.AddItem(new GUIContent("Show Node Running Times"), Prefs.showNodeElapsedTimes, () => { Prefs.showNodeElapsedTimes = !Prefs.showNodeElapsedTimes; });
            menu.AddItem(new GUIContent("Show Grid"), Prefs.showGrid, () => { Prefs.showGrid = !Prefs.showGrid; });
            menu.AddItem(new GUIContent("Grid Snap"), Prefs.snapToGrid, () => { Prefs.snapToGrid = !Prefs.snapToGrid; });
            menu.AddItem(new GUIContent("Log Events Info"), Prefs.logEventsInfo, () => { Prefs.logEventsInfo = !Prefs.logEventsInfo; });
            menu.AddItem(new GUIContent("Log Variables Info"), Prefs.logVariablesInfo, () => { Prefs.logVariablesInfo = !Prefs.logVariablesInfo; });
            menu.AddItem(new GUIContent("Breakpoints Pause Editor"), Prefs.breakpointPauseEditor, () => { Prefs.breakpointPauseEditor = !Prefs.breakpointPauseEditor; });
            menu.AddItem(new GUIContent("Animate Inspector Panel"), Prefs.animatePanels, () => { Prefs.animatePanels = !Prefs.animatePanels; });
            menu.AddItem(new GUIContent("Show Hierarchy Icons"), Prefs.showHierarchyIcons, () => { Prefs.showHierarchyIcons = !Prefs.showHierarchyIcons; });
            menu.AddItem(new GUIContent("Connection Style/Hard"), false, () => { Prefs.connectionsMLT = 1f; });
            menu.AddItem(new GUIContent("Connection Style/Soft"), false, () => { Prefs.connectionsMLT = 0.75f; });
            menu.AddItem(new GUIContent("Connection Style/Softer"), false, () => { Prefs.connectionsMLT = 0.5f; });
            menu.AddItem(new GUIContent("Connection Style/Direct"), false, () => { Prefs.connectionsMLT = 0f; });
            if (graph.isTree)
            {
                menu.AddItem(new GUIContent("Automatic Hierarchical Move"), Prefs.hierarchicalMove, () => { Prefs.hierarchicalMove = !Prefs.hierarchicalMove; });
            }
            menu.AddItem(new GUIContent("Open Preferred Types Editor..."), false, () => { TypePrefsEditorWindow.ShowWindow(); });
            return(menu);
        }
예제 #3
0
    public void RestartFromCheckpoint()
    {
        GraphOwner.SendGlobalEvent("Restart");
        var player   = GameObject.FindGameObjectWithTag("Player");
        var lastSave = FindLastActiveSave();

        lastSave.GetComponent <TriggerController>().ResetTrigger();
        var saveInfo = lastSave.GetComponent <TriggerController>().saveInfo;
        var rotation = lastSave.transform.rotation;

        rotation.eulerAngles = new Vector3(0f, 0f, rotation.eulerAngles.z + saveInfo.saveOrientationDelta);
        player.transform.SetPositionAndRotation(lastSave.transform.position + (Vector3)saveInfo.savePositionDelta,
                                                rotation);

        player.GetComponent <PlayerController>().UpdateStatus(saveInfo.GetPlayerStatus());
//		GameObject camera = GameObject.FindGameObjectWithTag("MainCamera");
        camera.GetComponent <CameraController>().UpdateStatus(saveInfo.GetCameraStatus());
//		GameObject.FindGameObjectWithTag("MainCamera").transform.SetPositionAndRotation(saveInfo.GetCameraTrans().position, saveInfo.GetCameraTrans().rotation);
        camera.transform.position = saveInfo.cameraPosition;
        Quaternion newRotation = Quaternion.Euler(0f, 0f, saveInfo.cameraOrientation);

        camera.transform.rotation = newRotation;

        Time.timeScale = 1f;
    }
예제 #4
0
        //Opening the window for a graph owner
        public static GraphEditor OpenWindow(GraphOwner owner)
        {
            var window = OpenWindow(owner.graph, owner, owner.blackboard);

            window.targetOwner = owner;
            return(window);
        }
예제 #5
0
        ///----------------------------------------------------------------------------------------------

        //PREFS MENU
        static GenericMenu GetToolbarMenu_Prefs(Graph graph, GraphOwner owner)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Show Icons"), Prefs.showIcons, () =>
            {
                Prefs.showIcons = !Prefs.showIcons;
                foreach (var node in graph.allNodes)
                {
                    node.rect = new Rect(node.position.x, node.position.y, Node.minSize.x, Node.minSize.y);
                }
            });
            menu.AddItem(new GUIContent("Show Node Help"), Prefs.showNodeInfo, () => { Prefs.showNodeInfo = !Prefs.showNodeInfo; });
            menu.AddItem(new GUIContent("Show Comments"), Prefs.showComments, () => { Prefs.showComments = !Prefs.showComments; });
            menu.AddItem(new GUIContent("Show Summary Info"), Prefs.showTaskSummary, () => { Prefs.showTaskSummary = !Prefs.showTaskSummary; });
            menu.AddItem(new GUIContent("Show Node IDs"), Prefs.showNodeIDs, () => { Prefs.showNodeIDs = !Prefs.showNodeIDs; });
            menu.AddItem(new GUIContent("Grid Snap"), Prefs.doSnap, () => { Prefs.doSnap = !Prefs.doSnap; });
            menu.AddItem(new GUIContent("Log Events"), Prefs.logEvents, () => { Prefs.logEvents = !Prefs.logEvents; });
            menu.AddItem(new GUIContent("Log Dynamic Parameters Info"), Prefs.logDynamicParametersInfo, () => { Prefs.logDynamicParametersInfo = !Prefs.logDynamicParametersInfo; });
            menu.AddItem(new GUIContent("Breakpoints Pause Editor"), Prefs.breakpointPauseEditor, () => { Prefs.breakpointPauseEditor = !Prefs.breakpointPauseEditor; });
            menu.AddItem(new GUIContent("Show Hierarchy Icons"), Prefs.showHierarchyIcons, () => { Prefs.showHierarchyIcons = !Prefs.showHierarchyIcons; });
            if (graph.autoSort)
            {
                menu.AddItem(new GUIContent("Automatic Hierarchical Move"), Prefs.hierarchicalMove, () => { Prefs.hierarchicalMove = !Prefs.hierarchicalMove; });
            }
            menu.AddItem(new GUIContent("Open Preferred Types Editor..."), false, () => { TypePrefsEditorWindow.ShowWindow(); });
            return(menu);
        }
        ///----------------------------------------------------------------------------------------------

        //PREFS MENU
        static GenericMenu GetToolbarMenu_Prefs(Graph graph, GraphOwner owner)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Use Node Browser"), NCPrefs.useBrowser, () => { NCPrefs.useBrowser = !NCPrefs.useBrowser; });
            menu.AddItem(new GUIContent("Show Icons"), NCPrefs.showIcons, () =>
            {
                NCPrefs.showIcons = !NCPrefs.showIcons;
                foreach (var node in graph.allNodes)
                {
                    node.rect = new Rect(node.position.x, node.position.y, Node.minSize.x, Node.minSize.y);
                }
            });
            menu.AddItem(new GUIContent("Show Node Help"), NCPrefs.showNodeInfo, () => { NCPrefs.showNodeInfo = !NCPrefs.showNodeInfo; });
            menu.AddItem(new GUIContent("Show Comments"), NCPrefs.showComments, () => { NCPrefs.showComments = !NCPrefs.showComments; });
            menu.AddItem(new GUIContent("Show Summary Info"), NCPrefs.showTaskSummary, () => { NCPrefs.showTaskSummary = !NCPrefs.showTaskSummary; });
            menu.AddItem(new GUIContent("Show Node IDs"), NCPrefs.showNodeIDs, () => { NCPrefs.showNodeIDs = !NCPrefs.showNodeIDs; });
            menu.AddItem(new GUIContent("Grid Snap"), NCPrefs.doSnap, () => { NCPrefs.doSnap = !NCPrefs.doSnap; });
            menu.AddItem(new GUIContent("Log Events"), NCPrefs.logEvents, () => { NCPrefs.logEvents = !NCPrefs.logEvents; });
            menu.AddItem(new GUIContent("Log Dynamic Parameters Info"), NCPrefs.logDynamicParametersInfo, () => { NCPrefs.logDynamicParametersInfo = !NCPrefs.logDynamicParametersInfo; });
            menu.AddItem(new GUIContent("Breakpoints Pause Editor"), NCPrefs.breakpointPauseEditor, () => { NCPrefs.breakpointPauseEditor = !NCPrefs.breakpointPauseEditor; });
            menu.AddItem(new GUIContent("Highlight Active In Hierarchy"), NCPrefs.highlightOwnersInHierarchy, () => { NCPrefs.highlightOwnersInHierarchy = !NCPrefs.highlightOwnersInHierarchy; });
            if (graph.autoSort)
            {
                menu.AddItem(new GUIContent("Automatic Hierarchical Move"), NCPrefs.hierarchicalMove, () => { NCPrefs.hierarchicalMove = !NCPrefs.hierarchicalMove; });
            }
            menu.AddItem(new GUIContent("Connection Style/Curved"), NCPrefs.connectionStyle == NCPrefs.ConnectionStyle.Curved, () => { NCPrefs.connectionStyle = NCPrefs.ConnectionStyle.Curved; });
            menu.AddItem(new GUIContent("Connection Style/Stepped"), NCPrefs.connectionStyle == NCPrefs.ConnectionStyle.Stepped, () => { NCPrefs.connectionStyle = NCPrefs.ConnectionStyle.Stepped; });
            menu.AddItem(new GUIContent("Connection Style/Linear"), NCPrefs.connectionStyle == NCPrefs.ConnectionStyle.Linear, () => { NCPrefs.connectionStyle = NCPrefs.ConnectionStyle.Linear; });
            menu.AddItem(new GUIContent("Node Header Style/Colorize Header"), NCPrefs.nodeHeaderStyle == NCPrefs.NodeHeaderStyle.ColorizeHeader, () => { NCPrefs.nodeHeaderStyle = NCPrefs.NodeHeaderStyle.ColorizeHeader; });
            menu.AddItem(new GUIContent("Node Header Style/Colorize Title"), NCPrefs.nodeHeaderStyle == NCPrefs.NodeHeaderStyle.ColorizeTitle, () => { NCPrefs.nodeHeaderStyle = NCPrefs.NodeHeaderStyle.ColorizeTitle; });
            menu.AddItem(new GUIContent("Open Preferred Types Editor..."), false, () => { PreferedTypesEditorWindow.ShowWindow(); });
            return(menu);
        }
        ///----------------------------------------------------------------------------------------------

        //EDIT MENU
        static GenericMenu GetToolbarMenu_Edit(Graph graph, GraphOwner owner)
        {
            var menu = new GenericMenu();

            //Bind
            if (!Application.isPlaying && owner != null && !owner.graphIsBound)
            {
                menu.AddItem(new GUIContent("Bind To Owner"), false, () =>
                {
                    if (EditorUtility.DisplayDialog("Bind Graph", "This will make a local copy of the graph, bound to the owner.\n\nThis allows you to make local changes and assign scene object references directly.\n\nNote that you can also use scene object references through the use of Blackboard Variables.\n\nBind Graph?", "YES", "NO"))
                    {
                        Undo.RecordObject(owner, "New Local Graph");
                        owner.SetBoundGraphReference(owner.graph);
                        EditorUtility.SetDirty(owner);
                    }
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Bind To Owner"));
            }

            //SavePlayer to asset
            if (owner != null && owner.graphIsBound)
            {
                menu.AddItem(new GUIContent("SavePlayer To Asset"), false, () =>
                {
                    var newGraph = (Graph)EditorUtils.CreateAsset(graph.GetType(), true);
                    if (newGraph != null)
                    {
                        EditorUtility.CopySerialized(graph, newGraph);
                        newGraph.Validate();
                        AssetDatabase.SaveAssets();
                    }
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("SavePlayer To Asset"));
            }

            //Create defined vars
            if (graph.blackboard != null)
            {
                menu.AddItem(new GUIContent("Promote Defined Parameters To Variables"), false, () =>
                {
                    if (EditorUtility.DisplayDialog("Promote Defined Parameters", "This will fill the current Blackboard with a Variable for each defined Parameter in the graph.\nContinue?", "YES", "NO"))
                    {
                        graph.PromoteDefinedParametersToVariables(graph.blackboard);
                    }
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Promote Defined Parameters To Variables"));
            }

            return(menu);
        }
        /// <summary> 从GraphAssetOwner中加载 </summary>
        public static BaseGraphWindow LoadGraphFromOwner(GraphOwner _graphOwner)
        {
            BaseGraphWindow graphWindow = LoadGraph(_graphOwner.Graph);

            graphWindow.GraphAsset = _graphOwner;
            graphWindow.GraphView.Model.InitializePropertyMapping(_graphOwner);
            graphWindow.GraphOwner = _graphOwner;
            return(graphWindow);
        }
        private GraphOwner GetGraphOwner()
        {
            if (_graphOwner == null)
            {
                _graphOwner = GetGameObject().GetComponent(_newConfig.ComponentType) as GraphOwner;
            }

            return(_graphOwner);
        }
예제 #10
0
        void Awake()
        {
            if (_current != null && _current != this)
            {
                DestroyImmediate(this.gameObject);
                return;
            }

            debugingGraphOwner = null;
            DontDestroyOnLoad(gameObject);
            _current = this;
        }
예제 #11
0
        ///Open GraphEditor initializing target graph
        public static GraphEditor OpenWindow(Graph newGraph, GraphOwner owner, IBlackboard blackboard)
        {
            var window = GetWindow <GraphEditor>();

            SetReferences(newGraph, owner, blackboard);
            if (NCPrefs.showWelcomeWindow && !Application.isPlaying && welcomeShown == false)
            {
                welcomeShown = true;
                var graphType = newGraph != null?newGraph.GetType() : null;

                WelcomeWindow.ShowWindow(graphType);
            }
            return(window);
        }
        ///----------------------------------------------------------------------------------------------

        //FILE MENU
        static GenericMenu GetToolbarMenu_File(Graph graph, GraphOwner owner)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Clear"), false, () =>
            {
                if (EditorUtility.DisplayDialog("Clear Canvas", "This will delete all nodes of the currently viewing graph!\nAre you sure?", "YES", "NO!"))
                {
                    graph.ClearGraph();
                }
            });

            menu.AddItem(new GUIContent("Import JSON"), false, () =>
            {
                if (graph.allNodes.Count > 0 && !EditorUtility.DisplayDialog("Import Graph", "All current graph information will be lost. Are you sure?", "YES", "NO"))
                {
                    return;
                }

                var path = EditorUtility.OpenFilePanel(string.Format("Import '{0}' Graph", graph.GetType().Name), "Assets", graph.GetGraphJSONFileExtension());
                if (!string.IsNullOrEmpty(path))
                {
                    if (graph.Deserialize(System.IO.File.ReadAllText(path), null, true) == false)   //true: validate, null: graph._objectReferences
                    {
                        EditorUtility.DisplayDialog("Import Failure", "Please read the logs for more information", "OK", string.Empty);
                    }
                }
            });

            menu.AddItem(new GUIContent("Export JSON"), false, () =>
            {
                var path = EditorUtility.SaveFilePanelInProject(string.Format("Export '{0}' Graph", graph.GetType().Name), string.Empty, graph.GetGraphJSONFileExtension(), string.Empty);
                if (!string.IsNullOrEmpty(path))
                {
                    var json = graph.Serialize(null);
                    json     = ParadoxNotion.Serialization.JSONSerializer.PrettifyJson(json);
                    System.IO.File.WriteAllText(path, json);
                    AssetDatabase.Refresh();
                }
            });

            menu.AddItem(new GUIContent("Show JSON"), false, () =>
            {
                graph.SelfSerialize();
                ParadoxNotion.Serialization.JSONSerializer.ShowData(graph.GetSerializedJsonData(), graph.name);
            });

            return(menu);
        }
예제 #13
0
        static void OwnerBehaviourChange(GraphOwner owner)
        {
            if (!Application.isPlaying)
            {
                return;
            }
            if (owner.isRunning)
            {
                activeOwners.Add(owner);
            }
            else
            {
                activeOwners.Remove(owner);
            }

            willRepaint = true;
        }
예제 #14
0
        //CUSTOM MENU
        static GenericMenu GetToolbarMenu_Custom(Graph graph, GraphOwner owner)
        {
            var menu    = new GenericMenu();
            var methods = graph.GetType().RTGetMethods();

            for (var i = 0; i < methods.Length; i++)
            {
                var method = methods[i];
                if (method.GetParameters().Length == 0)
                {
                    var menuAtt = method.RTGetAttribute <ToolbarMenuItemAttribute>(true);
                    if (menuAtt != null)
                    {
                        var instance = method.IsStatic? null : graph;
                        menu.AddItem(new GUIContent(menuAtt.path), false, () => { method.Invoke(instance, null); });
                    }
                }
            }
            return(menu);
        }
예제 #15
0
 ///Set GraphEditor inspected references
 public static void SetReferences(Graph newGraph, GraphOwner owner, IBlackboard blackboard)
 {
     if (current == null)
     {
         Debug.Log("GraphEditor is not open.");
         return;
     }
     willRepaint  = true;
     fullDrawPass = true;
     rootGraph    = newGraph;
     targetOwner  = owner;
     if (rootGraph != null)
     {
         rootGraph.currentChildGraph = null;
         rootGraph.UpdateNodeIDs(true);
         rootGraph.UpdateReferences(owner, blackboard);
     }
     GraphEditorUtility.activeElement = null;
     current.Repaint();
 }
예제 #16
0
        //...
        void OwnerBehaviourChange(GraphOwner owner)
        {
            if (!Application.isPlaying)
            {
                return;
            }
            if (owner.isRunning)
            {
                //we check contains for case of paused
                if (!activeOwners.Contains(owner))
                {
                    activeOwners.Add(owner);
                }
            }
            else
            {
                activeOwners.Remove(owner);
            }

            willRepaint = true;
        }
예제 #17
0
        static void ShowDataGUI(Variable data, IBlackboard bb, UnityEngine.Object contextParent, GUILayoutOption[] layoutOptions)
        {
            //Bind info or value GUI control
            if (data.hasBinding)
            {
                var idx        = data.propertyPath.LastIndexOf('.');
                var typeName   = data.propertyPath.Substring(0, idx);
                var memberName = data.propertyPath.Substring(idx + 1);
                GUI.color = new Color(0.8f, 0.8f, 1);
                GUILayout.Label(string.Format(".{0} ({1})", memberName, typeName.Split('.').Last()), layoutOptions);
                GUI.color = Color.white;
            }
            else
            {
                GUI.enabled = !data.isProtected;
                var fieldVar = VariableField(data, contextParent, layoutOptions);
                if (!Equals(fieldVar, data.value))
                {
                    data.value = fieldVar;
                    GraphOwner owner = ParadoxNotion.Services.MonoManager.current.debugingGraphOwner;
                }
                GUI.enabled         = true;
                GUI.backgroundColor = Color.white;
            }

            //Variable options menu
            if (!Application.isPlaying && GUILayout.Button("●", GUILayout.Width(17), GUILayout.Height(16)))
            {
                System.Action <PropertyInfo> SelectProp = (p) => {
                    data.BindProperty(p);
                };

                System.Action <FieldInfo> SelectField = (f) => {
                    data.BindProperty(f);
                };

                var menu = new GenericMenu();

                if (bb.propertiesBindTarget != null)
                {
                    foreach (var comp in bb.propertiesBindTarget.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector))
                    {
                        menu = EditorUtils.GetPropertySelectionMenu(comp.GetType(), data.varType, SelectProp, false, false, menu, "Bind (Self)/Property");
                        menu = EditorUtils.GetFieldSelectionMenu(comp.GetType(), data.varType, SelectField, menu, "Bind (Self)/Field");
                    }
                }

                foreach (var type in UserTypePrefs.GetPreferedTypesList(typeof(object)))
                {
                    menu = EditorUtils.GetStaticPropertySelectionMenu(type, data.varType, SelectProp, false, false, menu, "Bind (Static)/Property");
                    menu = EditorUtils.GetStaticFieldSelectionMenu(type, data.varType, SelectField, menu, "Bind (Static)/Field");
                }


                menu.AddItem(new GUIContent("Protected"), data.isProtected, () => { data.isProtected = !data.isProtected; });

                menu.AddSeparator("/");
                if (data.hasBinding)
                {
                    menu.AddItem(new GUIContent("UnBind"), false, () => { data.UnBindProperty(); });
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("UnBind"));
                }

                menu.AddItem(new GUIContent("Delete Variable"), false, () =>
                {
                    if (EditorUtility.DisplayDialog("Delete Variable '" + data.name + "'", "Are you sure?", "Yes", "No"))
                    {
                        bb.RemoveVariable(data.name);
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                    }
                });

                menu.ShowAsContext();
                Event.current.Use();
            }
        }
예제 #18
0
	    //Opening the window for a graph owner
	    public static GraphEditor OpenWindow(GraphOwner owner){
	    	var window = OpenWindow(owner.graph, owner, owner.blackboard);
	    	window.targetOwner = owner;
	    	return window;
	    }
예제 #19
0
 ///Set GraphEditor inspected references
 public static void SetReferences(GraphOwner owner)
 {
     SetReferences(owner.graph, owner, owner.blackboard);
 }
예제 #20
0
    public void PlayerDie()
    {
        GraphOwner.SendGlobalEvent("PlayerDie");
//		Time.timeScale = 0;
//		cameraController.PlayerDieAnimation();
    }
예제 #21
0
 ///Opening the window for a graph owner
 public static GraphEditor OpenWindow(GraphOwner owner)
 {
     return(OpenWindow(owner.graph, owner, owner.blackboard));
 }
예제 #22
0
    public static void ApplyGraphChange(GraphOwner go, GameObject instance)
    {
        //--------------------- 同步更新prefab资源
        bool isBound = go.graphIsBound;

        if (!isBound)
        {
            return;
        }

#if UNITY_2018_3_OR_NEWER
        var prefabType = UnityEditor.PrefabUtility.GetPrefabInstanceStatus(go.gameObject);
        //Debug.Log("start to add child graph");
        if (prefabType != UnityEditor.PrefabInstanceStatus.MissingAsset || prefabType != UnityEditor.PrefabInstanceStatus.NotAPrefab)
        {
            //Debug.Log("check prefab type");
            if (!Application.isPlaying)
            {
                GameObject prefab = (GameObject)PrefabUtility.GetCorrespondingObjectFromSource(instance);
                //Debug.Log("Prefab name:" + prefab.name);
                List <Graph> allNestGraphs = new List <Graph>();
                allNestGraphs.Add(go.graph);
                allNestGraphs = go.graph.GetAllNestedGraphs <Graph>(true);

                foreach (var v in allNestGraphs)
                {
                    if (!NestedUtility.CheckHasThisAsset(v, prefab))
                    {
                        //Debug.Log(" add child graph");
                        UnityEditor.AssetDatabase.AddObjectToAsset(v, prefab);
                        AssetDatabase.SaveAssets();
                        EditorUtility.SetDirty(go);
                    }
                }

                UnityEditor.EditorApplication.delayCall += () => { UnityEditor.AssetDatabase.ImportAsset(UnityEditor.AssetDatabase.GetAssetPath(prefab)); };
            }
        }
#else
        var prefabType = UnityEditor.PrefabUtility.GetPrefabType(go.gameObject);

        if (prefabType == UnityEditor.PrefabType.PrefabInstance)
        {
            if (!Application.isPlaying)
            {
                GameObject prefab = (GameObject)PrefabUtility.GetPrefabParent(instance);

                List <Graph> allNestGraphs = go.graph.GetAllNestedGraphs <Graph>(true);

                foreach (var v in allNestGraphs)
                {
                    if (!NestedUtility.CheckHasThisAsset(v, prefab))
                    {
                        UnityEditor.AssetDatabase.AddObjectToAsset(v, prefab);
                    }
                }

                UnityEditor.EditorApplication.delayCall +=
                    () => { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(prefab)); };
                AssetDatabase.Refresh();
            }
        }
#endif
    }
        ///----------------------------------------------------------------------------------------------

        //EDIT MENU
        static GenericMenu GetToolbarMenu_Edit(Graph graph, GraphOwner owner)
        {
            var menu = new GenericMenu();

            //Bind
            if (!Application.isPlaying && owner != null && !owner.graphIsBound)
            {
                menu.AddItem(new GUIContent("Bind To Owner"), false, () =>
                {
                    if (EditorUtility.DisplayDialog("Bind Graph", "This will make a local copy of the graph, bound to the owner.\n\nThis allows you to make local changes and assign scene object references directly.\n\nNote that you can also use scene object references through the use of Blackboard Variables.\n\nBind Graph?", "YES", "NO"))
                    {
                        UndoUtility.RecordObject(owner, "New Local Graph");
                        owner.SetBoundGraphReference(owner.graph);
                        UndoUtility.SetDirty(owner);
                    }
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Bind To Owner"));
            }

            //Save to asset
            if (!EditorUtility.IsPersistent(graph))
            {
                menu.AddItem(new GUIContent("Save To Asset"), false, () =>
                {
                    var newGraph = (Graph)EditorUtils.CreateAsset(graph.GetType());
                    if (newGraph != null)
                    {
                        EditorUtility.CopySerialized(graph, newGraph);
                        newGraph.Validate();
                        AssetDatabase.SaveAssets();
                    }
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Save To Asset"));
            }

            //Create defined vars
            if (graph.blackboard != null)
            {
                foreach (var bb in graph.blackboard.GetAllParents(true).Reverse())
                {
                    var category = "Promote Missing Parameters To Variables/";
                    menu.AddItem(new GUIContent(category + $"In '{bb.identifier}' Blackboard"), false, () =>
                    {
                        if (EditorUtility.DisplayDialog("Promote Missing Parameters", "This will fill the target Blackboard with a Variable for each defined missing Parameter in the graph.\nContinue?", "YES", "NO"))
                        {
                            UndoUtility.RecordObject(graph, "Promote Variables");
                            UndoUtility.RecordObject(bb.unityContextObject, "Promote Variables");
                            graph.PromoteMissingParametersToVariables(bb);
                            UndoUtility.SetDirty(graph);
                            UndoUtility.SetDirty(bb.unityContextObject);
                        }
                    });
                }
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Promote Defined Parameters To Variables"));
            }

            menu.AddItem(new GUIContent("Scan Graph for Serialized Struct Types"), false, () =>
            {
                GraphEditorUtility.ScanForStructTypesAndAppendThem(graph);
            });

            if (!Application.isPlaying)
            {
                menu.AddItem(new GUIContent("Re-Validate Graph"), false, () =>
                {
                    graph.SelfDeserialize();
                    graph.Validate();
                    FullDrawPass();
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Re-Validate Graph"));
            }

            return(menu);
        }