Beispiel #1
0
        public override void OnOpen()
        {
            // Create and add an AssetRootNode if not present.
            if (target.nodes.TrueForAll(x => x.GetType() != typeof(AssetRootNode)))
            {
                var node = target.AddNode(typeof(AssetRootNode));
                node.position = Vector2.zero;
                node.name     = NodeEditorUtilities.NodeDefaultName(typeof(AssetRootNode));

                AssetDatabase.SaveAssets();
                AssetDatabase.AddObjectToAsset(node, target);
                AssetDatabase.SaveAssets();
                NodeEditorWindow.RepaintAll();
            }
        }
Beispiel #2
0
        public static BlackboardVariableInstance Create(BlackboardObject value, BlackBoardGraph graph)
        {
            Node.graphHotfix = graph;
            Undo.RecordObject(graph, "Create Blackboard Value Instance");
            BlackboardVariableInstance node = CreateInstance <BlackboardVariableInstance>();

            node.value = value;
            node.graph = graph;
            if (node.name == null || node.name.Trim() == "")
            {
                node.name = NodeEditorUtilities.NodeDefaultName(typeof(BlackboardVariableInstance));
            }
            node.AddDynamicOutput(value.Type, ConnectionType.Multiple, TypeConstraint.InheritedInverse, "ValueOut");
            node.AddDynamicInput(value.Type, ConnectionType.Override, TypeConstraint.Inherited, "ValueIn");
            graph.nodes.Add(node);
            Undo.RegisterCreatedObjectUndo(node, "Create Blackboard Value Instance");
            AssetDatabase.AddObjectToAsset(node, graph);
            return(node);
        }
Beispiel #3
0
 public override void OnCreate()
 {
     base.OnCreate();
     if (target.nodes.Where(a => a.GetType() == typeof(Blackboard)).FirstOrDefault() == null)
     {
         Blackboard node = (Blackboard)target.AddNode(typeof(Blackboard));
         node.position = new Vector2(0, 0);
         if (node.name == null || node.name.Trim() == "")
         {
             node.name = NodeEditorUtilities.NodeDefaultName(typeof(Blackboard));
         }
         //Normally we would check for autosave first, but since this should be standard in this graph we donot.
         //Also GetSettings() doesn't work when closing the EditorWindow of a previous graph until this graph is opened fully.
         AssetDatabase.SaveAssets();
         NodeEditorWindow.RepaintAll();
         AssetDatabase.AddObjectToAsset(node, target);
         (target as BlackBoardGraph).Blackboard = node;
         AssetDatabase.SaveAssets();
     }
 }
Beispiel #4
0
        public override string GetNodeMenuName(Type type)
        {
            // Main Nodes
            if (type == typeof(OptionNode) || type == typeof(UtilityNode) || type == typeof(ConverterNode))
            {
                return("MainNodes/" + NodeEditorUtilities.NodeDefaultName(type));
            }
            // Memory Nodes
            if (type == typeof(MemoryCheckNode) || type == typeof(MemoryClearNode) || type == typeof(MemoryLoadNode) ||
                type == typeof(MemorySaveNode))
            {
                return(null);
                //TODO-fred Memory Nodes not available yet
//                return "MemoryNodes/"  + NodeEditorUtilities.NodeDefaultName(type);
            }
            // Pattern Nodes
            if (type == typeof(InCooldownNode) || type == typeof(SaveHistoricNode))
            {
                return(null);
                //TODO-fred Pattern Nodes not available yet
//                return "PatternNodes/"  + NodeEditorUtilities.NodeDefaultName(type);
            }
            // Other Nodes
            if (type.IsSubclassOf(typeof(MiddleNode)))
            {
                return("MiddleNodes/" + NodeEditorUtilities.NodeDefaultName(type));
            }
            if (type.IsSubclassOf(typeof(DataNode)))
            {
                return("DataNodes/" + NodeEditorUtilities.NodeDefaultName(type));
            }
            if (type.IsSubclassOf(typeof(ActionNode)))
            {
                return("ActionNodes/" + NodeEditorUtilities.NodeDefaultName(type));
            }
            return(null);
        }
Beispiel #5
0
    private static void DeleteNullAssets(NodeGraph toDelete)
    {
        //Create a new instance of the object to delete
        ScriptableObject newInstance = ScriptableObject.CreateInstance(toDelete.GetType());

        //Copy the original content to the new instance
        EditorUtility.CopySerialized(toDelete, newInstance);
        newInstance.name = toDelete.name;

        string toDeletePath = AssetDatabase.GetAssetPath(toDelete);
        string clonePath    = toDeletePath.Replace(".asset", "CLONE.asset");

        //Create the new asset on the project files
        AssetDatabase.CreateAsset(newInstance, clonePath);
        AssetDatabase.ImportAsset(clonePath);

        //Unhide sub-assets
        var subAssets = AssetDatabase.LoadAllAssetsAtPath(toDeletePath);

        HideFlags[] flags = new HideFlags[subAssets.Length];
        for (int i = 0; i < subAssets.Length; i++)
        {
            //Ignore the "corrupt" one
            if (subAssets[i] == null)
            {
                continue;
            }
            //Store the previous hide flag
            flags[i] = subAssets[i].hideFlags;
            subAssets[i].hideFlags = HideFlags.None;
            EditorUtility.SetDirty(subAssets[i]);
        }



        EditorUtility.SetDirty(toDelete);
        AssetDatabase.SaveAssets();
        //Reparent the subAssets to the new instance
        foreach (var subAsset in AssetDatabase.LoadAllAssetRepresentationsAtPath(toDeletePath))
        {
            //Ignore the "corrupt" one
            if (subAsset == null)
            {
                continue;
            }

            //We need to remove the parent before setting a new one
            AssetDatabase.RemoveObjectFromAsset(subAsset);
            AssetDatabase.AddObjectToAsset(subAsset, newInstance);
        }
        //Import both assets back to unity
        AssetDatabase.ImportAsset(toDeletePath);
        AssetDatabase.ImportAsset(clonePath);

        //Reset sub-asset flags
        for (int i = 0; i < subAssets.Length; i++)
        {
            //Ignore the "corrupt" one
            if (subAssets[i] == null)
            {
                continue;
            }
            subAssets[i].hideFlags = flags[i];
            EditorUtility.SetDirty(subAssets[i]);
        }

        EditorUtility.SetDirty(newInstance);
        AssetDatabase.SaveAssets();

        //Here's the magic. First, we need the system path of the assets
        string globalToDeletePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.dataPath), toDeletePath);
        string globalClonePath    = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.dataPath), clonePath);

        //We need to delete the original file (the one with the missing script asset)
        //Rename the clone to the original file and finally
        //Delete the meta file from the clone since it no longer exists

        File.Delete(globalToDeletePath);
        File.Delete(globalClonePath + ".meta");
        File.Move(globalClonePath, globalToDeletePath);
        AssetDatabase.Refresh();
        Object mainObj   = AssetDatabase.LoadMainAssetAtPath(toDeletePath);
        Node   nodeAsset = mainObj as Node;

        // If the renamed asset is a node graph, but the v2 AssetDatabase has swapped a sub-asset node to be its
        // main asset, reset the node graph to be the main asset and rename the node asset back to its default
        // name.
        if (nodeAsset != null && AssetDatabase.IsMainAsset(nodeAsset))
        {
            AssetDatabase.SetMainObject(nodeAsset.graph, toDeletePath);
            AssetDatabase.ImportAsset(toDeletePath);
            if (nodeAsset != null)
            {
                nodeAsset.name = NodeEditorUtilities.NodeDefaultName(nodeAsset.GetType());
                EditorUtility.SetDirty(nodeAsset);
            }
        }

        AssetDatabase.Refresh();
    }