public override Model.NodeGraphObj CreateNodeGraphObject()
 {
     Model.NodeGraphObj graph = ScriptableObject.CreateInstance <T>();
     graph.ControllerType = this.GetType().FullName;
     ProjectWindowUtil.CreateAsset(graph, string.Format("new {0}.asset", graph.GetType().Name));
     return(graph);
 }
Example #2
0
        public static bool ImportJSONToGraphFromDialog(ref Model.NodeGraphObj graph)
        {
            string fileSelected = EditorUtility.OpenFilePanelWithFilters("Select JSON files to import", Application.dataPath, new string[] { "JSON files", "json", "All files", "*" });

            if (string.IsNullOrEmpty(fileSelected))
            {
                return(false);
            }

            string name = Path.GetFileNameWithoutExtension(fileSelected);

            var jsonContent = File.ReadAllText(fileSelected, System.Text.Encoding.UTF8);

            if (graph != null)
            {
                Undo.RecordObject(graph, "Import");
                DeserializeGraph(jsonContent, ref graph);
            }
            else
            {
                var newAssetFolder = CreateFolderForImportedAssets();
                var graphPath      = FileUtility.PathCombine(newAssetFolder, string.Format("{0}.asset", name));
                graph = ScriptableObject.CreateInstance <Model.NodeGraphObj>();
                AssetDatabase.CreateAsset(graph, graphPath);
                AssetDatabase.Refresh();
                graph = AssetDatabase.LoadAssetAtPath <Model.NodeGraphObj>(graphPath);
                Debug.Log("create new:" + graph);
            }
            DeserializeGraph(jsonContent, ref graph);
            return(true);
        }
Example #3
0
        public static void ExportGraphToJSONFromDialog(Model.NodeGraphObj graph)
        {
            string path =
                EditorUtility.SaveFilePanel/*SaveFilePanelInProject*/ (
                    string.Format("Export {0} to JSON file", graph.name), Application.dataPath,
                    graph.name, "json");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            string jsonString = SerializeGraph(graph);

            File.WriteAllText(path, jsonString, System.Text.Encoding.UTF8);
        }
Example #4
0
        private static void DeleteSubAsset(Model.NodeGraphObj graph)
        {
            var path = AssetDatabase.GetAssetPath(graph);

            if (!string.IsNullOrEmpty(path))
            {
                var subAssets = AssetDatabase.LoadAllAssetsAtPath(path);
                foreach (var item in subAssets)
                {
                    if (item != graph)
                    {
                        //Debug.Log("delete:" + item);
                        UnityEngine.Object.DestroyImmediate(item, true);
                    }
                }
            }
        }
Example #5
0
        public static void DeserializeGraph(string json, ref Model.NodeGraphObj graph)
        {
            var jsonNode = JSONClass.Parse(json);

            if (graph == null)
            {
                graph = ScriptableObject.CreateInstance <Model.NodeGraphObj>();
            }
            else
            {
                DeleteSubAsset(graph);
            }

            List <ScriptableObject> subAssets = new List <ScriptableObject>();

            JsonUtility.FromJsonOverwrite(json, graph);

            for (int i = 0; i < jsonNode["m_allNodes"].AsArray.Count; i++)
            {
                var item = jsonNode["m_allNodes"][i]["m_node"];
                var obj  = ScriptableObject.CreateInstance(item["type"].Value) as Model.Node;
                JsonUtility.FromJsonOverwrite(item["json"], obj);
                obj.name = obj.GetType().FullName;
                graph.Nodes[i].Object = (obj);
                subAssets.Add(obj);
            }


            for (int i = 0; i < jsonNode["m_allConnections"].AsArray.Count; i++)
            {
                var item = jsonNode["m_allConnections"][i]["m_connection"];
                var obj  = ScriptableObject.CreateInstance(item["type"].Value) as Model.Connection;
                JsonUtility.FromJsonOverwrite(item["json"], obj);
                obj.name = obj.GetType().FullName;
                graph.Connections[i].Object = (obj);
                subAssets.Add(obj);
            }

            ScriptableObjUtility.SetSubAssets(subAssets.ToArray(), graph, true);
            EditorUtility.SetDirty(graph);
            foreach (var item in graph.Nodes)
            {
                //Debug.Log(item.Object);
                EditorUtility.SetDirty(item.Object);
            }
        }
Example #6
0
        public static string SerializeGraph(Model.NodeGraphObj graph)
        {
            var       rootJson = JsonUtility.ToJson(graph);
            JSONClass jc       = JSONClass.Parse(rootJson) as JSONClass;

            var nodes = jc["m_allNodes"].AsArray;

            for (int i = 0; i < nodes.Count; i++)
            {
                var node = graph.Nodes[i].Object;
                AddFieldToNode(nodes[i]["m_node"], JsonUtility.ToJson(node), node.GetType().FullName);
            }

            var connections = jc["m_allConnections"].AsArray;

            for (int i = 0; i < connections.Count; i++)
            {
                var connection = graph.Connections[i].Object;
                AddFieldToNode(connections[i]["m_connection"], JsonUtility.ToJson(connection), connection.GetType().FullName);
            }
            return(jc.ToString());
        }
Example #7
0
 internal override void BuildFromGraph(DataModel.NodeGraphObj m_targetGraph)
 {
     Debug.Log("On Build Button Clicked!");
 }
Example #8
0
 protected override void JudgeNodeExceptions(DataModel.NodeGraphObj m_targetGraph, List <NodeException> m_nodeExceptions)
 {
     Debug.Log("To Judge All Nodes, Is There Have Some Exceptions?");
 }
 protected virtual void BuildFromGraph(Model.NodeGraphObj m_targetGraph)
 {
 }
 protected virtual void JudgeNodeExceptions(Model.NodeGraphObj m_targetGraph, List <NodeException> m_nodeExceptions)
 {
 }
Example #11
0
 public ExecuteGraphResult(Model.NodeGraphObj g, List <NodeException> issues)
 {
     this.graph  = g;
     this.issues = issues;
 }