@ -1,4 +1,5 @@
using System.IO ;
using System.Text.RegularExpressions ;
using TNode.Editor.Model ;
using UnityEditor ;
using UnityEngine ;
@ -14,6 +15,10 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
[SerializeField]
private VisualTreeAsset m_VisualTreeAsset = default ;
private TextField _ editorClassNameTextField ;
private TextField _ graphClassNameTextField ;
private Button _ createButton ;
[MenuItem("Assets/Create/TNode/Create New Graph Editor")]
[MenuItem("TNode/Create New Graph Editor")]
public static void ShowExample ( )
@ -42,8 +47,43 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
root . Add ( labelFromUXML ) ;
//Register a callback when Create Button is clicked
Button createButton = root . Q < Button > ( "CreateButton" ) ;
createButton . clickable . clicked + = OnCreateButtonClicked ;
_ createButton = root . Q < Button > ( "CreateButton" ) ;
_ createButton . clickable . clicked + = OnCreateButtonClicked ;
_ editorClassNameTextField = root . Q < TextField > ( "EditorClassNameTextField" ) ;
_ graphClassNameTextField = root . Q < TextField > ( "GraphClassNameTextField" ) ;
_ editorClassNameTextField . RegisterCallback < ChangeEvent < string > > ( ( evt ) = > {
CheckIfTextValid ( ) ;
} ) ;
_ graphClassNameTextField . RegisterCallback < ChangeEvent < string > > ( ( evt ) = > {
CheckIfTextValid ( ) ;
} ) ;
}
public void CheckIfTextValid ( ) {
Regex regex = new System . Text . RegularExpressions . Regex ( "^[a-zA-Z0-9_]+$" ) ;
var matchEditor = regex . IsMatch ( _ editorClassNameTextField . value ) ;
var matchGraph = regex . IsMatch ( _ graphClassNameTextField . value ) ;
if ( matchEditor ) {
//Set background color to green
_ editorClassNameTextField . style . backgroundColor = new Color ( 0.5f , 1f , 0.5f ) ;
}
else {
//Set background color to red
_ editorClassNameTextField . style . backgroundColor = new Color ( 1f , 0.5f , 0.5f ) ;
}
if ( matchGraph ) {
//Set background color to green
_ graphClassNameTextField . style . backgroundColor = new Color ( 0.5f , 1f , 0.5f ) ;
}
else {
//Set background color to red
_ graphClassNameTextField . style . backgroundColor = new Color ( 1f , 0.5f , 0.5f ) ;
}
_ createButton . SetEnabled ( matchGraph & & matchEditor ) ;
}
@ -65,8 +105,8 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
path = path + "/Editor" ;
}
//Query the name of the graph editor
string editorName = rootVisualElement . Q < TextField > ( "EditorClassNameTextField" ) . text ;
string graphName = rootVisualElement . Q < TextField > ( "GraphClassNameTextField" ) . text ;
string editorName = _ editorClassNameTextField . text ;
string graphName = _ graphClassNameTextField . text ;
if ( editorName = = "" )
{
editorName = "NewGraphEditor" ;