1.Init pack

main
taoria 3 years ago
commit aafab2bc4b
  1. 1
      .gitignore
  2. 8
      Dialogue.meta
  3. 8
      Scenes.meta
  4. 208
      Scenes/SampleScene.unity
  5. 7
      Scenes/SampleScene.unity.meta
  6. 8
      TNode.meta
  7. 3
      TNode/Attribute.meta
  8. 12
      TNode/Attribute/InputPortAttribute.cs
  9. 3
      TNode/Attribute/InputPortAttribute.cs.meta
  10. 19
      TNode/Attribute/NodeComponentAttribute.cs
  11. 3
      TNode/Attribute/NodeComponentAttribute.cs.meta
  12. 3
      TNode/BaseViews.meta
  13. 85
      TNode/BaseViews/DataGraphView.cs
  14. 3
      TNode/BaseViews/DataGraphView.cs.meta
  15. 27
      TNode/BaseViews/NodeView.cs
  16. 3
      TNode/BaseViews/NodeView.cs.meta
  17. 35
      TNode/BaseViews/SimpleGraphSubWindow.cs
  18. 3
      TNode/BaseViews/SimpleGraphSubWindow.cs.meta
  19. 3
      TNode/Editor.meta
  20. 69
      TNode/Editor/GraphEditor.cs
  21. 12
      TNode/Editor/GraphEditor.cs.meta
  22. 5
      TNode/Editor/GraphEditor.uss
  23. 11
      TNode/Editor/GraphEditor.uss.meta
  24. 3
      TNode/Editor/GraphEditor.uxml
  25. 10
      TNode/Editor/GraphEditor.uxml.meta
  26. 19
      TNode/GraphData.cs
  27. 3
      TNode/GraphData.cs.meta
  28. 18
      TNode/NodeData.cs
  29. 3
      TNode/NodeData.cs.meta
  30. 29
      TNode/NodeLink.cs
  31. 3
      TNode/NodeLink.cs.meta
  32. 3
      TNode/TNodeSample.meta
  33. 8
      TNode/TNodeSample/GraphViewTest.cs
  34. 3
      TNode/TNodeSample/GraphViewTest.cs.meta
  35. 12
      TNode/TNodeSample/NodeDataTest.cs
  36. 3
      TNode/TNodeSample/NodeDataTest.cs.meta
  37. 3
      TNode/Tools.meta
  38. 50
      TNode/Tools/NodeEditorExtensions.cs
  39. 3
      TNode/Tools/NodeEditorExtensions.cs.meta
  40. 8
      Usage.meta
  41. 23
      Usage/Hello.asset
  42. 8
      Usage/Hello.asset.meta
  43. 30
      Usage/TestGraphEditor.cs
  44. 11
      Usage/TestGraphEditor.cs.meta
  45. 5
      Usage/TestGraphEditor.uss
  46. 11
      Usage/TestGraphEditor.uss.meta
  47. 12
      Usage/TestGraphEditor.uxml
  48. 10
      Usage/TestGraphEditor.uxml.meta

1
.gitignore vendored

@ -0,0 +1 @@
/Dialogue/

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 95903e6a18543fb46ba6bd05887b9e85
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 131a6b21c8605f84396be9f6751fb6e3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,208 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 500
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 2
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 0
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 0
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 519420032}
- component: {fileID: 519420031}
- component: {fileID: 519420029}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &519420029
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
--- !u!20 &519420031
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 0
m_HDR: 1
m_AllowMSAA: 0
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 0
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &519420032
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2cda990e2423bbf4892e6590ba056729
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8b1257251e593d24e807cb3c1b690097
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b3f6a86bf1f548a99d4981d0bcd7ab89
timeCreated: 1655794118

@ -0,0 +1,12 @@
using System;
using JetBrains.Annotations;
using UnityEditor.Experimental.GraphView;
namespace TNode.Attribute{
[MeansImplicitUse]
public class InputPortAttribute : System.Attribute{
public Type NodeLinkType;
public string PortAccepted;
public Port.Capacity Capacity;
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9dd097ab6c3f4c7fb651e8f1eab0062a
timeCreated: 1655874603

@ -0,0 +1,19 @@
using System;
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using TNode.BaseViews;
namespace TNode.Attribute{
//Check if the ide is Rider
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
[MeansImplicitUse]
public class NodeComponentAttribute:System.Attribute{
public Type GenericType{ get; set; }
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 12b3b35cc0804fef88fb11ed004fd18d
timeCreated: 1655794126

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: be6b702224dc40098aadadb3749d8c81
timeCreated: 1655394343

@ -0,0 +1,85 @@

using TNode.Tools;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.BaseViews{
public abstract class DataGraphView<T>:GraphView where T:GraphData{
private T _data;
public T Data{
get{ return _data; }
set{
_data = value;
if(OnDataChanged != null){
OnDataChanged(this, new DataChangedEventArgs<T>(_data));
}
ResetGraphView();
}
}
public void ResetGraphView(){
//Clear all nodes
foreach (var node in nodes){
RemoveElement(node);
}
foreach (var edge in edges){
RemoveElement(edge);
}
foreach (var dataNode in _data.nodes){
if(dataNode==null)
continue;
//Get the node type
var nodeType = dataNode.GetType();
//Get the derived type of Node View from the node type
var nodeViewType = typeof(NodeView<>).MakeGenericType(nodeType);
//Fetch the node view from the node view type
var nodeView = NodeEditorExtensions.CreateInstance(nodeViewType);
//Cast the node view to the nodeViewType
AddElement((Node)nodeView);
}
}
//A Constructor for the DataGraphView ,never to override it
public DataGraphView(){
this.AddManipulator(new ContentDragger());
this.AddManipulator(new SelectionDragger());
this.AddManipulator(new RectangleSelector());
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
//Default Color
style.backgroundColor = new Color(0.1f, 0.1f, 0.1f, 1);
// ReSharper disable once VirtualMemberCallInConstructor
OnInit();
}
//OnDataChanged event
public event DataChangedEventHandler OnDataChanged;
public delegate void DataChangedEventHandler(object sender, DataChangedEventArgs<T> e);
private void OnInit(){
OnGraphViewCreate();
}
public virtual void OnGraphViewCreate(){
}
public virtual void OnGraphViewDestroy(){
}
~DataGraphView(){
OnGraphViewDestroy();
}
}
public class DataChangedEventArgs<T>{
public DataChangedEventArgs(T data){
NewData = data;
}
public T NewData{ get; private set; }
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a8b5fae9e2b6465787771ab8196b85d6
timeCreated: 1655684370

@ -0,0 +1,27 @@
using Dialogue;
using UnityEditor.Experimental.GraphView;
namespace TNode.BaseViews{
//A Node monitor some type of node in the graph
public abstract class NodeView<T> : Node where T:NodeData,new(){
protected T _data;
public T Data{
get => _data;
set{
_data = value;
OnDataChanged?.Invoke(value);
}
}
public sealed override string title{
get => base.title;
set => base.title = value;
}
public event System.Action<T> OnDataChanged;
public NodeView(){
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d527b6508eab4cb68eda4604bb6988ed
timeCreated: 1655506205

@ -0,0 +1,35 @@
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine.UIElements;
namespace TNode.BaseViews{
public class SimpleGraphSubWindow:GraphElement{
private readonly Dragger _dragger = new Dragger();
private void ConstructWindowBasicSetting(){
RegisterCallback<WheelEvent>(evt => { evt.StopPropagation(); });
focusable = false;
capabilities |= Capabilities.Movable | Capabilities.Resizable;
this.AddManipulator(_dragger);
}
private void BuildWindow(VisualTreeAsset visualTreeAsset){
if(visualTreeAsset != null){
visualTreeAsset.CloneTree(this);
}
}
public SimpleGraphSubWindow(string defaultUxml=null){
ConstructWindowBasicSetting();
if (defaultUxml != null){
var uxml = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(defaultUxml);
BuildWindow(uxml);
}
}
public SimpleGraphSubWindow(VisualTreeAsset visualTreeAsset){
ConstructWindowBasicSetting();
BuildWindow(visualTreeAsset);
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d1cda92db3a54c1cb4eee9e07c2235a9
timeCreated: 1655394382

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1edd7a0452924467b57a5e5e7dfc6e34
timeCreated: 1655791756

@ -0,0 +1,69 @@
using Codice.CM.Common;
using TNode.BaseViews;
using TNode.Tools;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
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;
public void CreateGUI()
{
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;
// Instantiate UXML
VisualElement labelFromUXML = mVisualTreeAsset.Instantiate();
root.Add(labelFromUXML);
BuildGraphView();
DefineGraphEditorActions();
OnCreate();
}
private void BuildGraphView(){
_graphView = NodeEditorExtensions.CreateInstance<DataGraphView<T>>();
rootVisualElement.Add(_graphView);
_graphView.StretchToParentSize();
}
private void DefineGraphEditorActions(){
//Register a event when user press ctrl + s
rootVisualElement.RegisterCallback<KeyUpEvent>((evt) => {
if (evt.keyCode == KeyCode.S && evt.ctrlKey)
{
Save();
}
});
}
private void Save(){
//if no graph is loaded ,create a file save dialogue
if (_graphView.Data == null)
{
string path = EditorUtility.SaveFilePanel("Save Graph", "", "", "asset");
if (path.Length != 0){
//Create a new asset file with type of T
T asset = ScriptableObject.CreateInstance<T>();
AssetDatabase.CreateAsset(asset, path);
}
}
}
protected virtual void OnCreate(){
}
}
}

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 392314ca0623a2f4eba9178374a650e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_VisualTreeAsset: {fileID: 9197481963319205126, guid: b67f6dcbe2361b649ad2b7845207321b, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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

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

@ -0,0 +1,3 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<Style src="project://database/Assets/TNode/Editor/GraphEditor.uss?fileID=7433441132597879392&amp;guid=695180bcb9ddc3b47bbf70fe1f5dd651&amp;type=3#TGraphView" />
</ui:UXML>

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

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using Dialogue;
using UnityEngine;
namespace TNode{
[Serializable]
public class GraphData:ScriptableObject{
[SerializeReference]
public List<NodeData> nodes;
[SerializeReference]
public List<NodeLink> nodeLinks;
[HideInInspector]
[SerializeReference]
public NodeData entryNode;
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5283e3ad636149fda6ecd6472e664d33
timeCreated: 1655791838

@ -0,0 +1,18 @@
using System;
using UnityEngine;
namespace TNode{
[Serializable]
public class NodeData{
public NodeData() : base(){
//Object Registration
}
public string nodeName;
public bool entryPoint;
#if UNITY_EDITOR
public Rect rect;
#endif
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c57e16a9da5242e7959654469802f164
timeCreated: 1655506898

@ -0,0 +1,29 @@
using System;
namespace Dialogue{
//Node links are stored in output side of the two node port.
[Serializable]
public class NodeLink{
// public DialogueNodePortData From{ get; }
public bool ConditionEdge = false;
public DialogueNodePortData To{ get; }
public NodeLink(DialogueNodePortData to){
// From = from;
To = to;
}
public delegate bool Condition(DialogueNodePortData to);
public Condition ConditionFunction;
public bool Accessible{
get{
if (To == null) return false;
if(ConditionFunction == null)
return true;
return ConditionFunction(To);
}
}
public void SetCondition(Condition condition){
ConditionFunction = condition;
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a28072761ea6416f9718904cdb417cb4
timeCreated: 1655027566

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab3bb3578bf34dafad6ff9fb71f040e1
timeCreated: 1655794910

@ -0,0 +1,8 @@
using Dialogue;
using TNode.Attribute;
using TNode.BaseViews;
namespace TNode.TNodeSample{
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a7d4101454c84539b936140f3b54a3a6
timeCreated: 1655794926

@ -0,0 +1,12 @@
using Dialogue;
using TNode.Attribute;
namespace TNode.TNodeSample{
public class NodeDataTest:NodeData{
[InputPort] private float _floatInput;
public NodeDataTest(string name):base(){
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2d66df6e04694c51818042134869583f
timeCreated: 1655794954

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 23c0ed68e61d44569a7953e637c3da5e
timeCreated: 1655793491

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using TNode.Attribute;
using TNode.BaseViews;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
namespace TNode.Tools{
internal class NodeEditorSingleton{
private static NodeEditorSingleton _instance;
public readonly Dictionary<Type,Type> FromGenericToSpecific = new Dictionary<Type, Type>();
public static NodeEditorSingleton Instance{
get{ return _instance ??= new NodeEditorSingleton(); }
}
private NodeEditorSingleton(){
foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies()){
foreach(var type in assembly.GetTypes()){
if(type.IsClass && !type.IsAbstract){
foreach(var attribute in type.GetCustomAttributes(typeof(NodeComponentAttribute), false)){
//fetch this type 's parent class
var parent = type.BaseType;
//Check if this type is a generic type and is a generic type of NodeView or DataGraphView
if(parent is{IsGenericType: true} && (parent.GetGenericTypeDefinition() == typeof(NodeView<>) || parent.GetGenericTypeDefinition() == typeof(DataGraphView<>))){
//Get the generic type of this type
//Add this type to the dictionary
Debug.Log($"Find a component named {type} and its parent is {parent}" );
FromGenericToSpecific.Add(parent, type);
}
}
}
}
}
}
}
public static class NodeEditorExtensions{
public static T CreateInstance<T>(){
Debug.Log($"Create A instance of {typeof(T)}");
var implementedType = NodeEditorSingleton.Instance.FromGenericToSpecific[typeof(T)];
var instance = (T)Activator.CreateInstance(implementedType);
return instance;
}
public static object CreateInstance(Type t){
Debug.Log($"Create A instance of {t}");
var implementedType = NodeEditorSingleton.Instance.FromGenericToSpecific[t];
var instance = Activator.CreateInstance(implementedType);
return instance;
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 459e71a469954c3a832875e3e78c1c17
timeCreated: 1655793505

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 18f38c39496afae47ab40fb512c3ce7c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,23 @@
%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: }

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

@ -0,0 +1,30 @@
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);
}
}

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

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

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

@ -0,0 +1,12 @@
<?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>

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