1.start to make an inspector to inspect nodes

main
taoria 3 years ago
parent 7eb9406b75
commit 51d1973964
  1. 27
      Sample/Editor/HelloWorld.asset
  2. 8
      Sample/Editor/HelloWorld.asset.meta
  3. 10
      Sample/Editor/HelloWorld.cs
  4. 12
      Sample/Editor/HelloWorld.cs.meta
  5. 4
      Sample/Editor/HelloWorldGraph.cs
  6. 11
      Sample/Editor/HelloWorldGraph.cs.meta
  7. 110
      TNode/Editor/BaseViews/DataGraphView.cs
  8. 4
      TNode/Editor/BaseViews/SimpleGraphSubWindow.cs
  9. 1
      TNode/Editor/Cache/NodeEditorExtensions.cs
  10. 6
      TNode/Editor/GraphEditor.cs
  11. 2
      TNode/Editor/Inspector/DefaultInspectorItemFactory.cs
  12. 5
      TNode/Editor/Inspector/INodeDataBinding.cs
  13. 8
      TNode/Editor/Inspector/INodeDataBindingBase.cs
  14. 3
      TNode/Editor/Inspector/INodeDataBindingBase.cs.meta
  15. 8
      TNode/Editor/Inspector/InspectorImplementation/DefaultInspectorItem.cs
  16. 9
      TNode/Editor/Inspector/InspectorItem.cs
  17. 16
      TNode/Editor/Inspector/MonoScriptInspector.cs
  18. 3
      TNode/Editor/Inspector/MonoScriptInspector.cs.meta
  19. 29
      TNode/Editor/Inspector/NodeInspector.cs
  20. 1
      TNode/Editor/Resources/ScriptTemplates/NewGraph.cs.txt
  21. 4
      TNode/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt
  22. 9
      TNode/Editor/Resources/ScriptTemplates/NewGraphView.cs.txt
  23. 3
      TNode/Editor/Resources/ScriptTemplates/NewGraphView.cs.txt.meta
  24. 22
      TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs
  25. 2
      TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.uxml
  26. 16
      TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs

@ -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: }

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ad64ccb31efdc9c4082380856cd58efc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

@ -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<HelloWorldGraph>{
}

@ -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:

@ -1,4 +0,0 @@
using TNode.Models;
public class HelloWorldGraph : GraphData{
}

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8b641f4bc28454e4aa2c5ddc629b07c2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1,10 +1,105 @@
using TNode.Cache; using System.Collections.Generic;
using TNode.BaseViews;
using TNode.Cache;
using TNode.Models; using TNode.Models;
using UnityEditor.Experimental.GraphView; using UnityEditor.Experimental.GraphView;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
namespace TNode.BaseViews{ namespace TNode.Editor.BaseViews{
/*
public class DialogueGraphView : DataGraphView<DialogueGraph>{
public Action<DialogueNodeView> onNodeAdded;
public Action<DialogueNodeView> onNodeSelected;
public Action<DialogueNodeView> onNodeRemoved;
public Action<DialogueNodeView> 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<ContextualMenuPopulateEvent>(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<DialogueGraph> 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<MouseDownEvent>(evt => {
if (evt.clickCount == 1){
onNodeSelected?.Invoke(nodeView);
}
});
nodeView.OnUnselect += () => { onNodeUnselected?.Invoke(nodeView); };
}
public override List<Port> 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<T>:GraphView where T:GraphData{ public abstract class DataGraphView<T>:GraphView where T:GraphData{
private T _data; private T _data;
@ -64,6 +159,9 @@ namespace TNode.BaseViews{
private void OnInit(){ private void OnInit(){
OnGraphViewCreate(); OnGraphViewCreate();
} }
public virtual void OnGraphViewCreate(){ public virtual void OnGraphViewCreate(){
} }
@ -73,6 +171,14 @@ namespace TNode.BaseViews{
~DataGraphView(){ ~DataGraphView(){
OnGraphViewDestroy(); OnGraphViewDestroy();
} }
//rewrite function of the derived class in the comment on the top of this script file in this class
// public abstract override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter);
//
// public void AddNode(NodeData nodeData){
//
// }
} }
public class DataChangedEventArgs<T>{ public class DataChangedEventArgs<T>{

@ -6,13 +6,13 @@ namespace TNode.BaseViews{
public class SimpleGraphSubWindow:GraphElement{ public class SimpleGraphSubWindow:GraphElement{
private readonly Dragger _dragger = new Dragger(); private readonly Dragger _dragger = new Dragger();
private void ConstructWindowBasicSetting(){ protected void ConstructWindowBasicSetting(){
RegisterCallback<WheelEvent>(evt => { evt.StopPropagation(); }); RegisterCallback<WheelEvent>(evt => { evt.StopPropagation(); });
focusable = false; focusable = false;
capabilities |= Capabilities.Movable | Capabilities.Resizable; capabilities |= Capabilities.Movable | Capabilities.Resizable;
this.AddManipulator(_dragger); this.AddManipulator(_dragger);
} }
private void BuildWindow(VisualTreeAsset visualTreeAsset){ protected void BuildWindow(VisualTreeAsset visualTreeAsset){
if(visualTreeAsset != null){ if(visualTreeAsset != null){
visualTreeAsset.CloneTree(this); visualTreeAsset.CloneTree(this);
} }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using TNode.Attribute; using TNode.Attribute;
using TNode.BaseViews; using TNode.BaseViews;
using TNode.Editor.BaseViews;
using UnityEngine; using UnityEngine;
namespace TNode.Cache{ namespace TNode.Cache{

@ -1,6 +1,7 @@
using Codice.CM.Common; using Codice.CM.Common;
using TNode.BaseViews; using TNode.BaseViews;
using TNode.Cache; using TNode.Cache;
using TNode.Editor.BaseViews;
using TNode.Editor.Model; using TNode.Editor.Model;
using TNode.Models; using TNode.Models;
using UnityEditor; using UnityEditor;
@ -30,12 +31,7 @@ namespace TNode.Editor{
root.Add(labelFromUXML); root.Add(labelFromUXML);
BuildGraphView(); BuildGraphView();
DefineGraphEditorActions(); DefineGraphEditorActions();
OnCreate(); OnCreate();
} }
private void BuildGraphView(){ private void BuildGraphView(){

@ -21,7 +21,7 @@ namespace TNode.Editor.Inspector{
public static InspectorItem<T> DefaultInspectorItem<T>(){ public static InspectorItem<T> DefaultInspectorItem<T>(){
DefaultInspectorItem<T> item = new DefaultInspectorItem<T>(); DefaultInspectorItem<T> item = new DefaultInspectorItem<T>();
if (typeof(string) == typeof(T)){ if (typeof(string) == typeof(T)){
item.FoldOut.Add(new TextField(){ item.foldOut.Add(new TextField(){
name = "StringTextField" name = "StringTextField"
}); });
} }

@ -2,7 +2,7 @@
using UnityEngine; using UnityEngine;
namespace TNode.Editor.Inspector{ namespace TNode.Editor.Inspector{
public interface INodeDataBinding<out T>{ public interface INodeDataBinding<out T>:INodeDataBindingBase{
protected T GetValue(){ protected T GetValue(){
var fieldInfo = typeof(T).GetField(BindingPath, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); 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; return default;
} }
public string BindingPath{ get; set; }
public NodeData BindingNodeData{ get; set; }
public T Value => GetValue(); public T Value => GetValue();
public void OnBindingDataUpdate(){ public void OnBindingDataUpdate(){

@ -0,0 +1,8 @@
using TNode.Models;
namespace TNode.Editor.Inspector{
public interface INodeDataBindingBase{
public string BindingPath{ get; set; }
public NodeData BindingNodeData{ get; set; }
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2445523267fc49d3a17639a5c3ee47c7
timeCreated: 1656210915

@ -2,14 +2,14 @@
namespace TNode.Editor.Inspector.InspectorImplementation{ namespace TNode.Editor.Inspector.InspectorImplementation{
public class DefaultInspectorItem<T>:InspectorItem<T>{ public class DefaultInspectorItem<T>:InspectorItem<T>{
public Foldout FoldOut; public readonly Foldout foldOut;
public DefaultInspectorItem(){ public DefaultInspectorItem(){
var foldout = new Foldout{ foldOut = new Foldout{
text = "" text = ""
}; };
this.Add(foldout); this.Add(foldOut);
OnValueChanged += () => { OnValueChanged += () => {
foldout.text = this.BindingPath; foldOut.text = this.BindingPath;
}; };
} }
} }

@ -29,7 +29,16 @@ namespace TNode.Editor.Inspector{
} }
} }
public InspectorItem(){
OnValueChanged+= OnValueChangedHandler;
}
private void OnValueChangedHandler(){
}
~InspectorItem(){
OnValueChanged-= OnValueChangedHandler;
}
} }
} }

@ -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));
// }
// }
// }
//
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 192a51f6578144c5bbddb5cf77685c71
timeCreated: 1656214219

@ -1,7 +1,10 @@
using TNode.BaseViews; using System.Reflection;
using TNode.BaseViews;
using TNode.Models; using TNode.Models;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.Editor.BaseViews{ namespace TNode.Editor.Inspector{
public class NodeInspector:SimpleGraphSubWindow{ public class NodeInspector:SimpleGraphSubWindow{
private NodeData _data; private NodeData _data;
@ -18,8 +21,30 @@ namespace TNode.Editor.BaseViews{
RefreshInspector(); RefreshInspector();
} }
} }
public NodeInspector(){
var visualTreeAsset = Resources.Load<VisualTreeAsset>("NodeInspector");
ConstructWindowBasicSetting();
BuildWindow(visualTreeAsset);
}
private void RefreshInspector(){ 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;
}
}
}
} }

@ -1,6 +1,7 @@
using TNode.Models; using TNode.Models;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using System;
[CreateAssetMenu(fileName = "New $GraphClassName$", menuName = "TNode/$GraphClassName$")] [CreateAssetMenu(fileName = "New $GraphClassName$", menuName = "TNode/$GraphClassName$")]
[Serializable] [Serializable]
public class $GraphClassName$ : GraphData{ public class $GraphClassName$ : GraphData{

@ -4,14 +4,14 @@ using UnityEditor.Callbacks;
using UnityEditor.Experimental.GraphView; using UnityEditor.Experimental.GraphView;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
using System;
public class $EditorClassName$ : GraphEditor<$GraphClassName$>{ public class $EditorClassName$ : GraphEditor<$GraphClassName$>{
[OnOpenAsset] [OnOpenAsset]
public static bool OnOpenAsset(int instanceID, int line){ public static bool OnOpenAsset(int instanceID, int line){
var graph = EditorUtility.InstanceIDToObject(instanceID) as $GraphClassName$; var graph = EditorUtility.InstanceIDToObject(instanceID) as $GraphClassName$;
if (graph != null) if (graph != null)
{ {
$GraphClassName$ wnd = GetWindow<$EditorClassName$>(); var wnd = GetWindow<$EditorClassName$>();
wnd.titleContent = new GUIContent("$GraphClassName$ Editor"); wnd.titleContent = new GUIContent("$GraphClassName$ Editor");
wnd.CreateGUI(); wnd.CreateGUI();
wnd._graphView.Data = graph; wnd._graphView.Data = graph;

@ -0,0 +1,9 @@
using TNode.Models;
using TNode.Attribute;
using TNode.Editor.BaseViews;
[NodeComponent]
public class $GraphViewClassName$ : DataGraphView<$GraphClassName$>{
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bc741e48f31d4668bd3351eea8a5eaf1
timeCreated: 1656217566

@ -60,6 +60,8 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
CheckIfTextValid(); CheckIfTextValid();
}); });
CheckIfTextValid();
} }
public void CheckIfTextValid(){ public void CheckIfTextValid(){
@ -107,6 +109,7 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
//Query the name of the graph editor //Query the name of the graph editor
string editorName =_editorClassNameTextField.text; string editorName =_editorClassNameTextField.text;
string graphName = _graphClassNameTextField.text; string graphName = _graphClassNameTextField.text;
string graphViewName = graphName+"View";
if (editorName == "") if (editorName == "")
{ {
editorName = "NewGraphEditor"; editorName = "NewGraphEditor";
@ -117,16 +120,15 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
var source = sourceGeneratorForGraphEditor.GenerateGraphEditor(editorName,graphName); var source = sourceGeneratorForGraphEditor.GenerateGraphEditor(editorName,graphName);
var sourceGraph = sourceGeneratorForGraphEditor.GenerateGraph(graphName); var sourceGraph = sourceGeneratorForGraphEditor.GenerateGraph(graphName);
var sourceGraphView = sourceGeneratorForGraphEditor.GenerateGraphView(graphViewName,graphName);
string editorPath = Path.Combine(path, editorName + ".cs"); string editorPath = Path.Combine(path, editorName + ".cs");
string graphPath = Path.Combine(path, graphName + ".cs"); string graphPath = Path.Combine(path, graphName + ".cs");
string graphViewPath = Path.Combine(path, graphViewName + ".cs");
File.WriteAllText(editorPath, source); File.WriteAllText(editorPath, source);
File.WriteAllText(graphPath, sourceGraph); File.WriteAllText(graphPath, sourceGraph);
File.WriteAllText(graphViewPath, sourceGraphView);
//Refresh the AssetDatabase to import the new file //Refresh the AssetDatabase to import the new file
AssetDatabase.Refresh(); AssetDatabase.Refresh();
//Wait for the new file to be imported //Wait for the new file to be imported
@ -135,17 +137,15 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
EditorUtility.DisplayProgressBar("Generating Graph Editor", "Please wait while the new graph editor is being imported", 0.5f); EditorUtility.DisplayProgressBar("Generating Graph Editor", "Please wait while the new graph editor is being imported", 0.5f);
EditorApplication.update(); EditorApplication.update();
} }
//Create an Node Editor Data Instance for the new graph editor //Create an Node Editor Data Instance for the new graph editor
NodeEditorData nodeEditorData = ScriptableObject.CreateInstance<NodeEditorData>(); NodeEditorData nodeEditorData = ScriptableObject.CreateInstance<NodeEditorData>();
nodeEditorData.name = editorName; nodeEditorData.name = editorName;
EditorUtility.SetDirty(nodeEditorData); EditorUtility.SetDirty(nodeEditorData);
//Save it at the same folder as the new graph editor //Save it at the same folder as the new graph editor
string nodeEditorDataPath = Path.Combine(path, editorName + ".asset"); string nodeEditorDataPath = Path.Combine(path, editorName + ".asset");
AssetDatabase.CreateAsset(nodeEditorData, nodeEditorDataPath); AssetDatabase.CreateAsset(nodeEditorData, nodeEditorDataPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
//Wait for the new file to be imported //Wait for the new file to be imported
while (!AssetDatabase.LoadAssetAtPath<NodeEditorData>(nodeEditorDataPath)) while (!AssetDatabase.LoadAssetAtPath<NodeEditorData>(nodeEditorDataPath))
{ {
@ -153,8 +153,6 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
EditorApplication.update(); EditorApplication.update();
} }
var script = AssetDatabase.LoadAssetAtPath<MonoScript>(editorPath); var script = AssetDatabase.LoadAssetAtPath<MonoScript>(editorPath);
//Set the mono importer to the current graph editor script //Set the mono importer to the current graph editor script
MonoImporter monoImporter = AssetImporter.GetAtPath(editorPath) as MonoImporter; MonoImporter monoImporter = AssetImporter.GetAtPath(editorPath) as MonoImporter;
@ -162,10 +160,6 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
monoImporter.SetDefaultReferences(new string[]{"nodeEditorData"}, new Object[]{nodeEditorData}); monoImporter.SetDefaultReferences(new string[]{"nodeEditorData"}, new Object[]{nodeEditorData});
//Refresh the asset ann close it //Refresh the asset ann close it
//Mark it dirty //Mark it dirty

@ -6,7 +6,7 @@
<ui:Label tabindex="-1" text=".cs" display-tooltip-when-elided="true" style="-unity-text-align: middle-left;" /> <ui:Label tabindex="-1" text=".cs" display-tooltip-when-elided="true" style="-unity-text-align: middle-left;" />
</ui:VisualElement> </ui:VisualElement>
<ui:VisualElement name="GraphName" style="flex-direction: row;"> <ui:VisualElement name="GraphName" style="flex-direction: row;">
<ui:TextField picking-mode="Ignore" label="Your Editor Class Name" value="filler text" text="filler text" name="GraphClassNameTextField" style="width: 306px;" /> <ui:TextField picking-mode="Ignore" label="Your Graph Class Name" value="filler text" text="filler text" name="GraphClassNameTextField" style="width: 306px;" />
<ui:Label tabindex="-1" text=".cs" display-tooltip-when-elided="true" style="-unity-text-align: middle-left;" /> <ui:Label tabindex="-1" text=".cs" display-tooltip-when-elided="true" style="-unity-text-align: middle-left;" />
</ui:VisualElement> </ui:VisualElement>
<ui:Button tabindex="-1" text="Create Editor" display-tooltip-when-elided="true" name="CreateButton" /> <ui:Button tabindex="-1" text="Create Editor" display-tooltip-when-elided="true" name="CreateButton" />

@ -23,6 +23,8 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
var source = template.text.Replace("$EditorClassName$",editorClassName).Replace("$GraphClassName$",graphClassName); var source = template.text.Replace("$EditorClassName$",editorClassName).Replace("$GraphClassName$",graphClassName);
return source; return source;
} }
//what's the shortcut to navigate the files
public string GenerateGraph(string graphClassName,string templateName="NewGraph.cs"){ public string GenerateGraph(string graphClassName,string templateName="NewGraph.cs"){
TextAsset template = Resources.Load<TextAsset>("ScriptTemplates/"+templateName); TextAsset template = Resources.Load<TextAsset>("ScriptTemplates/"+templateName);
//Check if graph class name is valid //Check if graph class name is valid
@ -33,5 +35,19 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
var source = template.text.Replace("$GraphClassName$",graphClassName); var source = template.text.Replace("$GraphClassName$",graphClassName);
return source; return source;
} }
public string GenerateGraphView(string graphViewClassName,string graphClassName,string templateName="NewGraphView.cs"){
TextAsset template = Resources.Load<TextAsset>("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;
}
} }
} }
Loading…
Cancel
Save