//Create an menu item for TNode

main
taoria 3 years ago
parent 3b9a377fb4
commit 5a2c5e7e96
  1. 12
      TNode/Attribute/AssetMenuCreateAsGraphEditor.cs
  2. 3
      TNode/Attribute/AssetMenuCreateAsGraphEditor.cs.meta
  3. 0
      TNode/BaseModels/IModel.cs
  4. 0
      TNode/BaseModels/IModel.cs.meta
  5. 13
      TNode/Editor/GraphEditor.cs
  6. 4
      TNode/Editor/Model/NodeEditorData.cs
  7. 3
      TNode/Editor/Resources/ScriptTemplates.meta
  8. 10
      TNode/Editor/Resources/ScriptTemplates/NewGraph.cs.txt
  9. 3
      TNode/Editor/Resources/ScriptTemplates/NewGraph.cs.txt.meta
  10. 10
      TNode/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt
  11. 3
      TNode/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt.meta
  12. 3
      TNode/Editor/Tools.meta
  13. 3
      TNode/Editor/Tools/GraphEditorCreator.meta
  14. 37
      TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs
  15. 3
      TNode/Editor/Tools/GraphEditorCreator/SourceGeneratorForGraphEditor.cs.meta
  16. 23
      Usage/Hello.asset
  17. 8
      Usage/Hello.asset.meta
  18. 30
      Usage/TestGraphEditor.cs
  19. 11
      Usage/TestGraphEditor.cs.meta
  20. 5
      Usage/TestGraphEditor.uss
  21. 11
      Usage/TestGraphEditor.uss.meta
  22. 12
      Usage/TestGraphEditor.uxml
  23. 10
      Usage/TestGraphEditor.uxml.meta

@ -0,0 +1,12 @@
using System;
using JetBrains.Annotations;
using UnityEngine;
namespace TNode.Attribute{
[MeansImplicitUse]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
[BaseTypeRequired(typeof(ScriptableObject))]
public class AssetMenuCreateAsGraphEditorAttribute:System.Attribute{
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 536eae3bd21b49609d88e3bd24b4d7d0
timeCreated: 1656038984

@ -1,6 +1,7 @@
using Codice.CM.Common;
using TNode.BaseViews;
using TNode.Cache;
using TNode.Editor.Model;
using TNode.Models;
using UnityEditor;
using UnityEngine;
@ -9,16 +10,21 @@ using UnityEngine.UIElements;
namespace TNode.Editor{
public abstract class GraphEditor<T> : EditorWindow where T:GraphData{
protected DataGraphView<T> _graphView;
[FormerlySerializedAs("m_VisualTreeAsset")] [SerializeField]
private VisualTreeAsset mVisualTreeAsset = default;
//Persist editor data ,such as node position,node size ,etc ,in this script object
public NodeEditorData nodeEditorData;
public void CreateGUI()
{
public void CreateGUI(){
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;
// Instantiate UXML
VisualElement labelFromUXML = mVisualTreeAsset.Instantiate();
root.Add(labelFromUXML);
@ -66,5 +72,6 @@ namespace TNode.Editor{
protected virtual void OnCreate(){
}
}
}

@ -4,8 +4,8 @@ using UnityEngine;
namespace TNode.Editor.Model{
[Serializable]
public class NodeEditorData{
public class NodeEditorData:ScriptableObject{
[SerializeReference] public NodeData nodeData;
public Rect nodePos;
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 299cd93109da49408e38effcc26b8287
timeCreated: 1656052583

@ -0,0 +1,10 @@
using TNode.Editor;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
public class $GraphClassName$ : GraphData{
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 31fa431b7bdc4f1db16057eef0975d36
timeCreated: 1656054430

@ -0,0 +1,10 @@
using TNode.Editor;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
public class $EditorClassName$ : GraphEditor<$GraphClassName$>{
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 574dbcc7c8844b4fa3ded9d767b648bd
timeCreated: 1656052800

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ca83c0440a6942dba843d3912d8a246d
timeCreated: 1656050466

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: da92e3f72aeb448d90153ed496afaf1f
timeCreated: 1656050509

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis;
using UnityEngine;
namespace TNode.Editor.Tools.GraphEditorCreator{
public class SourceGeneratorForGraphEditor{
private readonly Regex Regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9_]+$");
public string GenerateGraphEditor(string editorClassName,string graphClassName,string templateName="NewGraphEditor.cs"){
//Load Text Asset by Name
TextAsset template = Resources.Load<TextAsset>("ScriptTemplates/"+templateName);
//Check if the class name is valid
if(!Regex.IsMatch(editorClassName)){
Debug.LogError("The editor class name is invalid. It must be a valid C# identifier.");
}
//Check if the graph class name is valid
if(!Regex.IsMatch(graphClassName)){
Debug.LogError("The graph class name is invalid. It must be a valid C# identifier.");
}
var source = template.text.Replace("$EditorClassName$",editorClassName).Replace("$GraphClassName$",graphClassName);
return source;
}
public string GenerateGraph(string graphClassName,string templatePath){
//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.");
}
var template = File.ReadAllText(templatePath);
var source = template.Replace("$GraphClassName$",graphClassName);
return source;
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 00c37e0c9a6445af80e17a617dfd1b04
timeCreated: 1656052182

@ -1,23 +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: b991a97e1e8f4ac7bbebd5263dafb1c3, type: 3}
m_Name: Hello
m_EditorClassIdentifier:
nodes: []
nodeLinks: []
entryNode:
rid: -2
references:
version: 2
RefIds:
- rid: -2
type: {class: , ns: , asm: }

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

@ -1,30 +0,0 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
public class TestGraphEditor : EditorWindow
{
[SerializeField]
private VisualTreeAsset m_VisualTreeAsset = default;
[MenuItem("Window/UI Toolkit/TestGraphEditor")]
public static void ShowExample()
{
TestGraphEditor wnd = GetWindow<TestGraphEditor>();
wnd.titleContent = new GUIContent("TestGraphEditor");
}
public void CreateGUI()
{
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;
// VisualElements objects can contain other VisualElement following a tree hierarchy.
VisualElement label = new Label("Hello World! From C#");
root.Add(label);
// Instantiate UXML
VisualElement labelFromUXML = m_VisualTreeAsset.Instantiate();
root.Add(labelFromUXML);
}
}

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

@ -1,5 +0,0 @@
.custom-label {
font-size: 20px;
-unity-font-style: bold;
color: rgb(68, 138, 255);
}

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 867e511d719e0f14e871be51fb547391
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<engine:UXML
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:engine="UnityEngine.UIElements"
xmlns:editor="UnityEditor.UIElements"
xsi:noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd"
>
<Style src="project://database/Assets/Usage/TestGraphEditor.uss?fileID=7433441132597879392&amp;guid=867e511d719e0f14e871be51fb547391&amp;type=3#TestGraphEditor" />
<engine:Label text="Hello World! From UXML" />
<engine:Label class="custom-label" text="Hello World! With Style" />
</engine:UXML>

@ -1,10 +0,0 @@
fileFormatVersion: 2
guid: ffc40a0c26876d9409f59e3252e7c29b
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
Loading…
Cancel
Save