diff --git a/Sample/Editor/HelloWorld.asset b/Sample/Editor/HelloWorld.asset deleted file mode 100644 index 8dfc869..0000000 --- a/Sample/Editor/HelloWorld.asset +++ /dev/null @@ -1,27 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: cde084f079a7426daa86ed86cb80ed1b, type: 3} - m_Name: HelloWorld - m_EditorClassIdentifier: - nodeData: - rid: -2 - nodePos: - serializedVersion: 2 - x: 0 - y: 0 - width: 0 - height: 0 - references: - version: 2 - RefIds: - - rid: -2 - type: {class: , ns: , asm: } diff --git a/Sample/Editor/HelloWorld.asset.meta b/Sample/Editor/HelloWorld.asset.meta deleted file mode 100644 index 0ec0efa..0000000 --- a/Sample/Editor/HelloWorld.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ad64ccb31efdc9c4082380856cd58efc -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/Editor/HelloWorld.cs b/Sample/Editor/HelloWorld.cs deleted file mode 100644 index 9de7b9e..0000000 --- a/Sample/Editor/HelloWorld.cs +++ /dev/null @@ -1,10 +0,0 @@ -using TNode.Editor; -using UnityEditor; -using UnityEditor.Callbacks; -using UnityEditor.Experimental.GraphView; -using UnityEngine; -using UnityEngine.UIElements; - -public class HelloWorld : GraphEditor{ - -} \ No newline at end of file diff --git a/Sample/Editor/HelloWorld.cs.meta b/Sample/Editor/HelloWorld.cs.meta deleted file mode 100644 index f68d71c..0000000 --- a/Sample/Editor/HelloWorld.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 7b39119946f2f83458e3c2bafb200552 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: - - nodeEditorData: {fileID: 11400000, guid: ad64ccb31efdc9c4082380856cd58efc, type: 2} - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/Editor/HelloWorldGraph.cs b/Sample/Editor/HelloWorldGraph.cs deleted file mode 100644 index bc22163..0000000 --- a/Sample/Editor/HelloWorldGraph.cs +++ /dev/null @@ -1,4 +0,0 @@ -using TNode.Models; -public class HelloWorldGraph : GraphData{ - -} \ No newline at end of file diff --git a/Sample/Editor/HelloWorldGraph.cs.meta b/Sample/Editor/HelloWorldGraph.cs.meta deleted file mode 100644 index 982b74d..0000000 --- a/Sample/Editor/HelloWorldGraph.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8b641f4bc28454e4aa2c5ddc629b07c2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/TNode/Editor/BaseViews/DataGraphView.cs b/TNode/Editor/BaseViews/DataGraphView.cs index 1bd6d14..a0ce812 100644 --- a/TNode/Editor/BaseViews/DataGraphView.cs +++ b/TNode/Editor/BaseViews/DataGraphView.cs @@ -1,10 +1,105 @@ -using TNode.Cache; +using System.Collections.Generic; +using TNode.BaseViews; +using TNode.Cache; using TNode.Models; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; -namespace TNode.BaseViews{ +namespace TNode.Editor.BaseViews{ + /* + public class DialogueGraphView : DataGraphView{ + public Action onNodeAdded; + public Action onNodeSelected; + public Action onNodeRemoved; + public Action onNodeUnselected; + // public DialogueGraphView(DialogueGraph graph):base(){ + // this.Data = graph; + // + // //Set background to a bit of darker + // + // + // //Register a data context change callback + // + // } + + public override void OnGraphViewCreate(){ + AddNode(GenerateEntryPoint()); + RegisterCallback(evt => { + var pos = evt.mousePosition; + + evt.menu.AppendAction("Add Node", (dropMenuAction) => { + DialogueNodeView nodeView = new DialogueNodeView{ + GUID = Guid.NewGuid().ToString(), + title = "New Node" + }; + // make it a 200x100 box + nodeView.SetPosition(new Rect(pos.x - 100, pos.y - 50, 200, 100)); + + + AddNode(nodeView); + }, DropdownMenuAction.AlwaysEnabled); + }); + this.OnDataChanged += OnOnDataChanged; + } + private void OnOnDataChanged(object sender, DataChangedEventArgs e){ + //clean all nodes from the graphview + foreach (var graphViewNode in nodes){ + RemoveElement(graphViewNode); + } + + foreach (var edge in edges){ + RemoveElement(edge); + } + //add all nodes from the new graph + foreach (var node in e.NewData.nodes){ + //AddNode(node); + } + } + + public void AddNode(DialogueNodeData dialogueNodeData){ + var res = InstantiateFromDialogueNodeData(dialogueNodeData); + AddNode(res); + } + public void AddNode(DialogueNodeView nodeView){ + AddElement(nodeView); + onNodeAdded?.Invoke(nodeView); + //Register nodeView selection callback + nodeView.RegisterCallback(evt => { + if (evt.clickCount == 1){ + onNodeSelected?.Invoke(nodeView); + } + }); + nodeView.OnUnselect += () => { onNodeUnselected?.Invoke(nodeView); }; + } + + public override List GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) => this.ports.ToList() + .Where(x => x != startPort && + x.direction != startPort.direction).ToList(); + + public DialogueNodeView GenerateEntryPoint(){ + var entryPoint = new DialogueNodeView{ + title = "Entry Point", + GUID = Guid.NewGuid().ToString(), + EntryPoint = true + }; + //Add output port to the nodeView + entryPoint.AddPort(Orientation.Horizontal, Direction.Output, "Next"); + //Set nodeView position to top center side of screen + entryPoint.SetPosition(new Rect(this.layout.width / 2 - 100, 0, 200, 200)); + return entryPoint; + } + protected DialogueNodeView InstantiateFromDialogueNodeData(DialogueNodeData dialogueNodeData){ + var node = new DialogueNodeView(); + node.title = dialogueNodeData.nodeName; + node.GUID = Guid.NewGuid().ToString(); + //TODO:after completing the separation of the node data and the node editor data,this should be switch to the node editor data + //node.SetPosition(dialogueNodeData.rect); + this.AddNode(node); + return node; + } + } + */ public abstract class DataGraphView:GraphView where T:GraphData{ private T _data; @@ -64,6 +159,9 @@ namespace TNode.BaseViews{ private void OnInit(){ OnGraphViewCreate(); } + + + public virtual void OnGraphViewCreate(){ } @@ -73,6 +171,14 @@ namespace TNode.BaseViews{ ~DataGraphView(){ OnGraphViewDestroy(); } + //rewrite function of the derived class in the comment on the top of this script file in this class + // public abstract override List GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter); + // + // public void AddNode(NodeData nodeData){ + // + // } + + } public class DataChangedEventArgs{ diff --git a/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs b/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs index 9402842..b81282b 100644 --- a/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs +++ b/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs @@ -6,13 +6,13 @@ namespace TNode.BaseViews{ public class SimpleGraphSubWindow:GraphElement{ private readonly Dragger _dragger = new Dragger(); - private void ConstructWindowBasicSetting(){ + protected void ConstructWindowBasicSetting(){ RegisterCallback(evt => { evt.StopPropagation(); }); focusable = false; capabilities |= Capabilities.Movable | Capabilities.Resizable; this.AddManipulator(_dragger); } - private void BuildWindow(VisualTreeAsset visualTreeAsset){ + protected void BuildWindow(VisualTreeAsset visualTreeAsset){ if(visualTreeAsset != null){ visualTreeAsset.CloneTree(this); } diff --git a/TNode/Editor/Cache/NodeEditorExtensions.cs b/TNode/Editor/Cache/NodeEditorExtensions.cs index 8e5fb14..4d8f57b 100644 --- a/TNode/Editor/Cache/NodeEditorExtensions.cs +++ b/TNode/Editor/Cache/NodeEditorExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using TNode.Attribute; using TNode.BaseViews; +using TNode.Editor.BaseViews; using UnityEngine; namespace TNode.Cache{ diff --git a/TNode/Editor/GraphEditor.cs b/TNode/Editor/GraphEditor.cs index 38fd04c..1aa89e8 100644 --- a/TNode/Editor/GraphEditor.cs +++ b/TNode/Editor/GraphEditor.cs @@ -1,6 +1,7 @@ using Codice.CM.Common; using TNode.BaseViews; using TNode.Cache; +using TNode.Editor.BaseViews; using TNode.Editor.Model; using TNode.Models; using UnityEditor; @@ -28,14 +29,9 @@ namespace TNode.Editor{ // Instantiate UXML VisualElement labelFromUXML = mVisualTreeAsset.Instantiate(); root.Add(labelFromUXML); - + BuildGraphView(); - - - DefineGraphEditorActions(); - - OnCreate(); } private void BuildGraphView(){ diff --git a/TNode/Editor/Inspector/DefaultInspectorItemFactory.cs b/TNode/Editor/Inspector/DefaultInspectorItemFactory.cs index 7386a4a..0bc873e 100644 --- a/TNode/Editor/Inspector/DefaultInspectorItemFactory.cs +++ b/TNode/Editor/Inspector/DefaultInspectorItemFactory.cs @@ -21,7 +21,7 @@ namespace TNode.Editor.Inspector{ public static InspectorItem DefaultInspectorItem(){ DefaultInspectorItem item = new DefaultInspectorItem(); if (typeof(string) == typeof(T)){ - item.FoldOut.Add(new TextField(){ + item.foldOut.Add(new TextField(){ name = "StringTextField" }); } diff --git a/TNode/Editor/Inspector/INodeDataBinding.cs b/TNode/Editor/Inspector/INodeDataBinding.cs index 99aa316..1fe044b 100644 --- a/TNode/Editor/Inspector/INodeDataBinding.cs +++ b/TNode/Editor/Inspector/INodeDataBinding.cs @@ -2,7 +2,7 @@ using UnityEngine; namespace TNode.Editor.Inspector{ - public interface INodeDataBinding{ + public interface INodeDataBinding:INodeDataBindingBase{ protected T GetValue(){ var fieldInfo = typeof(T).GetField(BindingPath, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); @@ -15,8 +15,7 @@ namespace TNode.Editor.Inspector{ } return default; } - public string BindingPath{ get; set; } - public NodeData BindingNodeData{ get; set; } + public T Value => GetValue(); public void OnBindingDataUpdate(){ diff --git a/TNode/Editor/Inspector/INodeDataBindingBase.cs b/TNode/Editor/Inspector/INodeDataBindingBase.cs new file mode 100644 index 0000000..bb367b9 --- /dev/null +++ b/TNode/Editor/Inspector/INodeDataBindingBase.cs @@ -0,0 +1,8 @@ +using TNode.Models; + +namespace TNode.Editor.Inspector{ + public interface INodeDataBindingBase{ + public string BindingPath{ get; set; } + public NodeData BindingNodeData{ get; set; } + } +} \ No newline at end of file diff --git a/TNode/Editor/Inspector/INodeDataBindingBase.cs.meta b/TNode/Editor/Inspector/INodeDataBindingBase.cs.meta new file mode 100644 index 0000000..7885931 --- /dev/null +++ b/TNode/Editor/Inspector/INodeDataBindingBase.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2445523267fc49d3a17639a5c3ee47c7 +timeCreated: 1656210915 \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/DefaultInspectorItem.cs b/TNode/Editor/Inspector/InspectorImplementation/DefaultInspectorItem.cs index ada5681..2dd72c2 100644 --- a/TNode/Editor/Inspector/InspectorImplementation/DefaultInspectorItem.cs +++ b/TNode/Editor/Inspector/InspectorImplementation/DefaultInspectorItem.cs @@ -2,14 +2,14 @@ namespace TNode.Editor.Inspector.InspectorImplementation{ public class DefaultInspectorItem:InspectorItem{ - public Foldout FoldOut; + public readonly Foldout foldOut; public DefaultInspectorItem(){ - var foldout = new Foldout{ + foldOut = new Foldout{ text = "" }; - this.Add(foldout); + this.Add(foldOut); OnValueChanged += () => { - foldout.text = this.BindingPath; + foldOut.text = this.BindingPath; }; } } diff --git a/TNode/Editor/Inspector/InspectorItem.cs b/TNode/Editor/Inspector/InspectorItem.cs index f430620..09de53f 100644 --- a/TNode/Editor/Inspector/InspectorItem.cs +++ b/TNode/Editor/Inspector/InspectorItem.cs @@ -28,8 +28,17 @@ namespace TNode.Editor.Inspector{ } } - - + public InspectorItem(){ + OnValueChanged+= OnValueChangedHandler; + } + + private void OnValueChangedHandler(){ + + + } + ~InspectorItem(){ + OnValueChanged-= OnValueChangedHandler; + } } } \ No newline at end of file diff --git a/TNode/Editor/Inspector/MonoScriptInspector.cs b/TNode/Editor/Inspector/MonoScriptInspector.cs new file mode 100644 index 0000000..a06049a --- /dev/null +++ b/TNode/Editor/Inspector/MonoScriptInspector.cs @@ -0,0 +1,16 @@ +using UnityEditor; +using UnityEditor.AssetImporters; +using UnityEngine; + +namespace TNode.Editor.Inspector{ + // [CustomEditor(typeof(MonoImporter))] + // public class MonoScriptInspector:AssetImporterEditor{ + // public override void OnInspectorGUI(){ + // base.OnInspectorGUI(); + // if(GUILayout.Button("Open")){ + // EditorUtility.OpenWithDefaultApp(AssetDatabase.GetAssetPath(target)); + // } + // } + // } + // +} \ No newline at end of file diff --git a/TNode/Editor/Inspector/MonoScriptInspector.cs.meta b/TNode/Editor/Inspector/MonoScriptInspector.cs.meta new file mode 100644 index 0000000..9441899 --- /dev/null +++ b/TNode/Editor/Inspector/MonoScriptInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 192a51f6578144c5bbddb5cf77685c71 +timeCreated: 1656214219 \ No newline at end of file diff --git a/TNode/Editor/Inspector/NodeInspector.cs b/TNode/Editor/Inspector/NodeInspector.cs index 80eb3dd..a15dabb 100644 --- a/TNode/Editor/Inspector/NodeInspector.cs +++ b/TNode/Editor/Inspector/NodeInspector.cs @@ -1,7 +1,10 @@ -using TNode.BaseViews; +using System.Reflection; +using TNode.BaseViews; using TNode.Models; +using UnityEngine; +using UnityEngine.UIElements; -namespace TNode.Editor.BaseViews{ +namespace TNode.Editor.Inspector{ public class NodeInspector:SimpleGraphSubWindow{ private NodeData _data; @@ -18,8 +21,30 @@ namespace TNode.Editor.BaseViews{ RefreshInspector(); } } + public NodeInspector(){ + var visualTreeAsset = Resources.Load("NodeInspector"); + ConstructWindowBasicSetting(); + BuildWindow(visualTreeAsset); + } private void RefreshInspector(){ + //iterate field of data and get name of every fields,create a new inspector item of appropriate type and add it to the inspector for each field + foreach (var field in GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){ + var bindingPath = field.Name; + var type = field.FieldType; + DefaultInspectorItemFactory defaultInspectorItemFactory = new DefaultInspectorItemFactory(); + //Invoke generic function Create<> of default inspector item factory to create an inspector item of appropriate type by reflection + MethodInfo methodInfo = defaultInspectorItemFactory.GetType().GetMethod("Create", BindingFlags.Instance | BindingFlags.Public); + if (methodInfo != null){ + var genericMethod = methodInfo.MakeGenericMethod(type); + var createdInspector = genericMethod.Invoke(defaultInspectorItemFactory,null) as VisualElement; + Add(createdInspector); + if (createdInspector is INodeDataBindingBase castedInspector){ + castedInspector.BindingNodeData = _data; + castedInspector.BindingPath = bindingPath; + } + } + } } diff --git a/TNode/Editor/Resources/ScriptTemplates/NewGraph.cs.txt b/TNode/Editor/Resources/ScriptTemplates/NewGraph.cs.txt index fdccd12..913d60c 100644 --- a/TNode/Editor/Resources/ScriptTemplates/NewGraph.cs.txt +++ b/TNode/Editor/Resources/ScriptTemplates/NewGraph.cs.txt @@ -1,6 +1,7 @@ using TNode.Models; using UnityEngine; using UnityEditor; +using System; [CreateAssetMenu(fileName = "New $GraphClassName$", menuName = "TNode/$GraphClassName$")] [Serializable] public class $GraphClassName$ : GraphData{ diff --git a/TNode/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt b/TNode/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt index 20018c0..1f5ad7e 100644 --- a/TNode/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt +++ b/TNode/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt @@ -4,14 +4,14 @@ using UnityEditor.Callbacks; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; - +using System; public class $EditorClassName$ : GraphEditor<$GraphClassName$>{ [OnOpenAsset] public static bool OnOpenAsset(int instanceID, int line){ var graph = EditorUtility.InstanceIDToObject(instanceID) as $GraphClassName$; if (graph != null) { - $GraphClassName$ wnd = GetWindow<$EditorClassName$>(); + var wnd = GetWindow<$EditorClassName$>(); wnd.titleContent = new GUIContent("$GraphClassName$ Editor"); wnd.CreateGUI(); wnd._graphView.Data = graph; diff --git a/TNode/Editor/Resources/ScriptTemplates/NewGraphView.cs.txt b/TNode/Editor/Resources/ScriptTemplates/NewGraphView.cs.txt new file mode 100644 index 0000000..65fdf23 --- /dev/null +++ b/TNode/Editor/Resources/ScriptTemplates/NewGraphView.cs.txt @@ -0,0 +1,9 @@ +using TNode.Models; +using TNode.Attribute; +using TNode.Editor.BaseViews; +[NodeComponent] +public class $GraphViewClassName$ : DataGraphView<$GraphClassName$>{ + + + +} \ No newline at end of file diff --git a/TNode/Editor/Resources/ScriptTemplates/NewGraphView.cs.txt.meta b/TNode/Editor/Resources/ScriptTemplates/NewGraphView.cs.txt.meta new file mode 100644 index 0000000..646231a --- /dev/null +++ b/TNode/Editor/Resources/ScriptTemplates/NewGraphView.cs.txt.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bc741e48f31d4668bd3351eea8a5eaf1 +timeCreated: 1656217566 \ No newline at end of file diff --git a/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs b/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs index 472a7cd..5387b68 100644 --- a/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs +++ b/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs @@ -59,6 +59,8 @@ namespace TNode.Editor.Tools.GraphEditorCreator{ _graphClassNameTextField.RegisterCallback>((evt) => { CheckIfTextValid(); }); + + CheckIfTextValid(); } @@ -107,6 +109,7 @@ namespace TNode.Editor.Tools.GraphEditorCreator{ //Query the name of the graph editor string editorName =_editorClassNameTextField.text; string graphName = _graphClassNameTextField.text; + string graphViewName = graphName+"View"; if (editorName == "") { editorName = "NewGraphEditor"; @@ -117,35 +120,32 @@ namespace TNode.Editor.Tools.GraphEditorCreator{ var source = sourceGeneratorForGraphEditor.GenerateGraphEditor(editorName,graphName); var sourceGraph = sourceGeneratorForGraphEditor.GenerateGraph(graphName); + + var sourceGraphView = sourceGeneratorForGraphEditor.GenerateGraphView(graphViewName,graphName); string editorPath = Path.Combine(path, editorName + ".cs"); string graphPath = Path.Combine(path, graphName + ".cs"); + string graphViewPath = Path.Combine(path, graphViewName + ".cs"); File.WriteAllText(editorPath, source); - File.WriteAllText(graphPath, sourceGraph); - - - + File.WriteAllText(graphViewPath, sourceGraphView); //Refresh the AssetDatabase to import the new file - AssetDatabase.Refresh(); - + //Wait for the new file to be imported while (!AssetDatabase.LoadAssetAtPath(editorPath)) { EditorUtility.DisplayProgressBar("Generating Graph Editor", "Please wait while the new graph editor is being imported", 0.5f); EditorApplication.update(); } + //Create an Node Editor Data Instance for the new graph editor NodeEditorData nodeEditorData = ScriptableObject.CreateInstance(); nodeEditorData.name = editorName; - EditorUtility.SetDirty(nodeEditorData); //Save it at the same folder as the new graph editor string nodeEditorDataPath = Path.Combine(path, editorName + ".asset"); AssetDatabase.CreateAsset(nodeEditorData, nodeEditorDataPath); - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); //Wait for the new file to be imported while (!AssetDatabase.LoadAssetAtPath(nodeEditorDataPath)) { @@ -153,18 +153,12 @@ namespace TNode.Editor.Tools.GraphEditorCreator{ EditorApplication.update(); } var script = AssetDatabase.LoadAssetAtPath(editorPath); - - //Set the mono importer to the current graph editor script MonoImporter monoImporter = AssetImporter.GetAtPath(editorPath) as MonoImporter; if (monoImporter != null) monoImporter.SetDefaultReferences(new string[]{"nodeEditorData"}, new Object[]{nodeEditorData}); - - - - //Refresh the asset ann close it //Mark it dirty diff --git a/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.uxml b/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.uxml index 6906f40..de74e5e 100644 --- a/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.uxml +++ b/TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.uxml @@ -6,7 +6,7 @@ - + diff --git a/TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs b/TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs index e4e1e40..8e4eeae 100644 --- a/TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs +++ b/TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs @@ -22,7 +22,9 @@ namespace TNode.Editor.Tools.GraphEditorCreator{ } var source = template.text.Replace("$EditorClassName$",editorClassName).Replace("$GraphClassName$",graphClassName); return source; - } + } + //what's the shortcut to navigate the files + public string GenerateGraph(string graphClassName,string templateName="NewGraph.cs"){ TextAsset template = Resources.Load("ScriptTemplates/"+templateName); //Check if graph class name is valid @@ -33,5 +35,19 @@ namespace TNode.Editor.Tools.GraphEditorCreator{ var source = template.text.Replace("$GraphClassName$",graphClassName); return source; } + + public string GenerateGraphView(string graphViewClassName,string graphClassName,string templateName="NewGraphView.cs"){ + TextAsset template = Resources.Load("ScriptTemplates/"+templateName); + //Check if graph class name is valid + var regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9_]+$"); + if(!Regex.IsMatch(graphClassName)){ + Debug.LogError("The graph class name is invalid. It must be a valid C# identifier."); + } + if(!Regex.IsMatch(graphViewClassName)){ + Debug.LogError("The graph view name is invalid. It must be a valid C# identifier."); + } + var source = template.text.Replace("$GraphClassName$",graphClassName).Replace("$GraphViewClassName$",graphViewClassName); + return source; + } } } \ No newline at end of file