Merge pull request #7 from taoria/working-in-process

Working in process
main
taoria 3 years ago committed by GitHub
commit fe8a90ec58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      EasyRandomGenerator.meta
  2. 15
      Sample/Editor/HelloGraphView.cs
  3. 13
      Sample/HelloComponent.cs
  4. 3
      Sample/HelloComponent.cs.meta
  5. 11
      Sample/HelloGraph.cs
  6. 11
      Sample/HelloNode.cs
  7. 3
      Sample/HelloNode.cs.meta
  8. 8
      Sample/MathGraph.meta
  9. 2
      Sample/MathGraph/Editor.meta
  10. 2
      Sample/MathGraph/Editor/MathEditor.asset
  11. 2
      Sample/MathGraph/Editor/MathEditor.asset.meta
  12. 18
      Sample/MathGraph/Editor/MathEditor.cs
  13. 4
      Sample/MathGraph/Editor/MathEditor.cs.meta
  14. 9
      Sample/MathGraph/Editor/MathGraphView.cs
  15. 2
      Sample/MathGraph/Editor/MathGraphView.cs.meta
  16. 9
      Sample/MathGraph/MathGraph.cs
  17. 2
      Sample/MathGraph/MathGraph.cs.meta
  18. 4
      Sample/MathGraph/New MathGraph.asset
  19. 2
      Sample/MathGraph/New MathGraph.asset.meta
  20. 294
      Scenes/SampleScene.unity
  21. 11
      TNode/Attribute/DisableOnInspector.cs
  22. 3
      TNode/Attribute/DisableOnInspector.cs.meta
  23. 8
      TNode/Attribute/GraphUsageAttribute.cs
  24. 17
      TNode/Attribute/InputPortAttribute.cs
  25. 3
      TNode/Attribute/Ports.meta
  26. 17
      TNode/Attribute/Ports/InputAttribute.cs
  27. 0
      TNode/Attribute/Ports/InputAttribute.cs.meta
  28. 5
      TNode/Attribute/Ports/OutputAttribute.cs
  29. 3
      TNode/Attribute/Ports/OutputAttribute.cs.meta
  30. 2
      TNode/Attribute/Ports/PortAttribute.cs
  31. 0
      TNode/Attribute/Ports/PortAttribute.cs.meta
  32. 47
      TNode/Editor/BaseViews/DataGraphView.cs
  33. 36
      TNode/Editor/BaseViews/NodeView.cs
  34. 2
      TNode/Editor/Cache/NodeEditorExtensions.cs
  35. 7
      TNode/Editor/GraphEditor.cs
  36. 1
      TNode/Editor/Inspector/InspectorItem.cs
  37. 7
      TNode/Editor/Inspector/NodeInspector.cs
  38. 1
      TNode/Editor/Inspector/NodeInspectorInNode.cs
  39. 5
      TNode/Editor/Model/NodeEditorData.cs
  40. 0
      TNode/Editor/Resources/GraphEditor.uss
  41. 0
      TNode/Editor/Resources/GraphEditor.uss.meta
  42. 0
      TNode/Editor/Resources/GraphEditor.uxml
  43. 0
      TNode/Editor/Resources/GraphEditor.uxml.meta
  44. 58
      TNode/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs
  45. 4
      TNode/Models/NodeData.cs

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

@ -1,15 +0,0 @@
using TNode.Attribute;
using TNode.Editor.BaseViews;
using TNode.Editor.Inspector;
using UnityEngine;
namespace Sample.Editor{
[NodeComponent]
public class HelloGraphView : DataGraphView<HelloGraph>{
public override void OnGraphViewCreate(){
CreateInspector();
}
}
}

@ -1,13 +0,0 @@
using System;
using UnityEngine;
namespace Sample{
public class HelloComponent:MonoBehaviour{
public void Update(){
var trans1 = gameObject.transform;
var trans2 = gameObject.GetComponent<Transform>();
var tran3 = GetComponent<Transform>();
var tran4 = transform;
}
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: aba7d5b338ab470aa820882d309d1f7c
timeCreated: 1656587766

@ -1,11 +0,0 @@
using System;
using TNode.Models;
using UnityEngine;
namespace Sample{
[CreateAssetMenu(fileName = "New HelloGraph", menuName = "TNode/HelloGraph")]
[Serializable]
public class HelloGraph : GraphData{
}
}

@ -1,11 +0,0 @@
using TNode.Attribute;
using TNode.Models;
using UnityEngine;
namespace Sample{
[GraphUsage(typeof(HelloGraph))]
public class HelloNode:NodeData{
[ShowInNodeView]
public string SayHelloText = "";
}
}

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 928bb3292c464ae0b811455e9f4e8667
timeCreated: 1656391464

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

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: dc673adb081e1f841bdf4998bdb7b50a
guid: 73ee98eea19fa9b42b9c7990a8161d56
folderAsset: yes
DefaultImporter:
externalObjects: {}

@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cde084f079a7426daa86ed86cb80ed1b, type: 3}
m_Name: HelloEditor
m_Name: MathEditor
m_EditorClassIdentifier:
nodeData:
rid: -2

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0ecaf7effd4cb5545b03d4f552942c80
guid: acb7b8ebcdf5f4f40bccf1e405c94da3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

@ -1,26 +1,22 @@
using TNode.Editor;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
namespace Sample.Editor{
public class HelloEditor : GraphEditor<HelloGraph>{
using UnityEngine.UIElements;
using System;
public class MathEditor : GraphEditor<MathGraph>{
[OnOpenAsset]
public static bool OnOpenAsset(int instanceID, int line){
var graph = EditorUtility.InstanceIDToObject(instanceID) as HelloGraph;
var graph = EditorUtility.InstanceIDToObject(instanceID) as MathGraph;
if (graph != null)
{
var wnd = GetWindow<HelloEditor>();
wnd.titleContent = new GUIContent("HelloGraph Editor");
var wnd = GetWindow<MathEditor>();
wnd.titleContent = new GUIContent("MathGraph Editor");
wnd.CreateGUI();
wnd._graphView.Data = graph;
return true;
}
return false;
}
public HelloEditor(){
}
}
}

@ -1,12 +1,12 @@
fileFormatVersion: 2
guid: a5c15a07ff247a247a73d6991b540e27
guid: c9041cb574597424fa4124edc3f99af1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_ViewDataDictionary: {instanceID: 0}
- mVisualTreeAsset: {fileID: 9197481963319205126, guid: b67f6dcbe2361b649ad2b7845207321b, type: 3}
- nodeEditorData: {fileID: 11400000, guid: 0ecaf7effd4cb5545b03d4f552942c80, type: 2}
- nodeEditorData: {fileID: 11400000, guid: acb7b8ebcdf5f4f40bccf1e405c94da3, type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:

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

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8ec139b86ff8c10488c233a10e6106f4
guid: 7f4d84b648626d24eb29bfeb81c85e3f
MonoImporter:
externalObjects: {}
serializedVersion: 2

@ -0,0 +1,9 @@
using TNode.Models;
using UnityEngine;
using UnityEditor;
using System;
[CreateAssetMenu(fileName = "New MathGraph", menuName = "TNode/MathGraph")]
[Serializable]
public class MathGraph : GraphData{
}

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9eda9b79596ecc746bb59fa8939c6ac3
guid: 73baeb2c71a23da4ca06e3e3e52d5a78
MonoImporter:
externalObjects: {}
serializedVersion: 2

@ -9,8 +9,8 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9eda9b79596ecc746bb59fa8939c6ac3, type: 3}
m_Name: New HelloGraph
m_Script: {fileID: 11500000, guid: 73baeb2c71a23da4ca06e3e3e52d5a78, type: 3}
m_Name: New MathGraph
m_EditorClassIdentifier:
nodes: []
nodeLinks: []

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: edfa4bd023c6a7641aec2257a5e1248e
guid: 4b23c513fb78ea44b8a11a0bf7c8479e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

@ -215,7 +215,9 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children: []
m_Children:
- {fileID: 1608359614}
- {fileID: 893739497}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -391,6 +393,153 @@ SpriteMask:
m_BackSortingOrder: 0
m_IsCustomRangeActive: 0
m_SpriteSortPoint: 0
--- !u!1 &893739496
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 893739497}
- component: {fileID: 893739501}
- component: {fileID: 893739500}
- component: {fileID: 893739499}
- component: {fileID: 893739498}
m_Layer: 5
m_Name: Button
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &893739497
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 893739496}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1751393470}
m_Father: {fileID: 507038910}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &893739498
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 893739496}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aba7d5b338ab470aa820882d309d1f7c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &893739499
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 893739496}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 893739500}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 893739498}
m_TargetAssemblyTypeName: Sample.HelloComponent, Assembly-CSharp
m_MethodName: ClickButtonAction
m_Mode: 2
m_Arguments:
m_ObjectArgument: {fileID: 893739499}
m_ObjectArgumentAssemblyTypeName: UnityEngine.UI.Button, UnityEngine.UI
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &893739500
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 893739496}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &893739501
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 893739496}
m_CullTransparentMesh: 1
--- !u!1 &1608359612
GameObject:
m_ObjectHideFlags: 0
@ -467,14 +616,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1608359612}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 16.183, y: 14.154, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -534.317, y: -235.346, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 691266390}
m_Father: {fileID: 0}
m_RootOrder: 3
m_Father: {fileID: 507038910}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1701140682
GameObject:
@ -543,3 +692,138 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1751393469
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1751393470}
- component: {fileID: 1751393472}
- component: {fileID: 1751393471}
m_Layer: 5
m_Name: Text (TMP)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1751393470
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1751393469}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 893739497}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1751393471
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1751393469}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: Button
m_isRightToLeft: 0
m_fontAsset: {fileID: 0}
m_sharedMaterial: {fileID: 0}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: 0
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 0
m_fontSizeMax: 0
m_fontStyle: 0
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 0
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 0
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 0
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &1751393472
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1751393469}
m_CullTransparentMesh: 1

@ -0,0 +1,11 @@
using System;
namespace TNode.Attribute{
/// <summary>
/// Use this attribute to mark a field as disabled.An disable field will not be edit by the inspector.
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
public class DisableOnInspectorAttribute:System.Attribute{
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e3d9cad2647b42dc8db0ce63f1291343
timeCreated: 1656669029

@ -14,13 +14,17 @@ namespace TNode.Attribute{
[AttributeUsage(AttributeTargets.Class)]
[BaseTypeRequired(typeof(NodeData))]
public class GraphUsageAttribute:System.Attribute{
public Type GraphDataType;
public GraphUsageAttribute(Type t){
public readonly Type GraphDataType;
public string Category;
public GraphUsageAttribute(Type t,string category = null){
//check if the type t is graph
if(!typeof(GraphData).IsAssignableFrom(t)){
throw new Exception("The type must be a graph");
}
GraphDataType = t;
if (category != null){
Category = category;
}
}
}
}

@ -1,17 +0,0 @@
using System;
using JetBrains.Annotations;
using TNode.Models;
using UnityEditor.Experimental.GraphView;
namespace TNode.Attribute{
[MeansImplicitUse]
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
public class InputPortAttribute : PortAttribute{
public InputPortAttribute(string portName, Type nodeLinkType, Port.Capacity capacity, string portAccepted = "*") : base(portName, nodeLinkType, capacity, portAccepted){
}
public InputPortAttribute(Type nodeLinkType, Port.Capacity capacity, string portAccepted="*") : base(nodeLinkType, capacity, portAccepted){
}
public InputPortAttribute(string portName="*",string portAccepted = "*") :base(portName, typeof(NodeLink),Port.Capacity.Multi,portAccepted){
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8d6c138cbd3849ddb631107ca9253252
timeCreated: 1656659934

@ -0,0 +1,17 @@
using System;
using JetBrains.Annotations;
using TNode.Models;
using UnityEditor.Experimental.GraphView;
namespace TNode.Attribute{
[MeansImplicitUse]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class InputAttribute : PortAttribute{
public InputAttribute(string portName, Type nodeLinkType, Port.Capacity capacity, string portAccepted = "*") : base(portName, nodeLinkType, capacity, portAccepted){
}
public InputAttribute(Type nodeLinkType, Port.Capacity capacity, string portAccepted="*") : base(nodeLinkType, capacity, portAccepted){
}
public InputAttribute(string portName="*",string portAccepted = "*") :base(portName, typeof(NodeLink),Port.Capacity.Multi,portAccepted){
}
}
}

@ -0,0 +1,5 @@
namespace TNode.Attribute.Ports{
public class OutputAttribute:System.Attribute{
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 39a482c948504fab9f89169843646c02
timeCreated: 1656659954

@ -4,7 +4,7 @@ using UnityEditor.Experimental.GraphView;
namespace TNode.Attribute{
[MeansImplicitUse]
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class PortAttribute:System.Attribute{
public string PortName;

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TNode.BaseViews;
using TNode.Cache;
using TNode.Editor.Inspector;
using TNode.Editor.Model;
using TNode.Models;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
@ -182,6 +184,20 @@ namespace TNode.Editor.BaseViews{
_nodeInspector = nodeInspector;
_isInspectorOn = true;
}
public void CreateMiniMap(Rect rect){
var miniMap = new MiniMap();
this.Add(miniMap);
miniMap.SetPosition(rect);
}
public void CreateBlackBoard(){
var blackboard = new Blackboard();
//Set black board to left side of the view
blackboard.SetPosition(new Rect(0,0,200,600));
this.Add(blackboard);
}
public virtual void DestroyInspector(){
if(_nodeInspector!=null){
this.Remove(_nodeInspector);
@ -197,6 +213,37 @@ namespace TNode.Editor.BaseViews{
}
}
public void SaveEditorData(GraphEditorData graphEditorData){
graphEditorData.nodesData.Clear();
//iterator nodes
foreach (var node in this.nodes){
var nodeEditorData = new NodeEditorData{
nodePos = node.GetPosition(),
};
if (node is INodeView nodeView){
nodeEditorData.nodeGuid = nodeView.GetNodeData().id;
}
graphEditorData.nodesData.Add(nodeEditorData);
}
}
public void LoadEditorData(GraphEditorData graphEditorData){
//Load node position
foreach (var nodeEditorData in graphEditorData.nodesData){
var node = this.nodes.Select(x => x as INodeView).First(x=>x?.GetNodeData().id==nodeEditorData.nodeGuid);
if (node != null){
((GraphElement)node).SetPosition(nodeEditorData.nodePos);
}
}
}
public void SaveWithEditorData(GraphEditorData graphEditorData){
SaveEditorData(graphEditorData);
}
public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter){
return ports.Where(x => x.portType == startPort.portType).ToList();
}
public virtual void OnGraphViewCreate(){

@ -1,4 +1,7 @@
using TNode.Editor.Inspector;
using System;
using TNode.Attribute;
using TNode.Attribute.Ports;
using TNode.Editor.Inspector;
using TNode.Models;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
@ -47,8 +50,35 @@ namespace TNode.Editor.BaseViews{
this.title = _data.nodeName;
if (_nodeInspectorInNode != null){
_nodeInspectorInNode.Data = obj;
this.RefreshExpandedState();
this.expanded = true;
}
BuildInputAndOutputPort();
this.expanded = true;
this.RefreshExpandedState();
}
private void BuildInputAndOutputPort(){
var propertyInfos = _data.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos){
Debug.Log(propertyInfos);
var attribute = propertyInfo.GetCustomAttributes(typeof(OutputAttribute),true);
if (attribute.Length > 0){
Port port = InstantiatePort(Orientation.Horizontal, Direction.Output,Port.Capacity.Multi,propertyInfo.PropertyType);
this.outputContainer.Add(port);
port.portName = propertyInfo.Name;
}
}
foreach (var propertyInfo in propertyInfos){
Debug.Log(propertyInfos);
var attribute = propertyInfo.GetCustomAttributes(typeof(InputAttribute),true);
if (attribute.Length > 0){
Port port = InstantiatePort(Orientation.Horizontal, Direction.Input,Port.Capacity.Multi,propertyInfo.PropertyType);
this.inputContainer.Add(port);
port.portName = propertyInfo.Name;
}
}
}

@ -76,13 +76,11 @@ namespace TNode.Cache{
//Outer wrapper for the singleton class
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;

@ -16,12 +16,10 @@ namespace TNode.Editor{
public abstract class GraphEditor<T> : EditorWindow where T:GraphData{
protected DataGraphView<T> _graphView;
[FormerlySerializedAs("m_VisualTreeAsset")] [SerializeField]
[SerializeField]
private VisualTreeAsset mVisualTreeAsset = default;
//Persist editor data ,such as node position,node size ,etc ,in this script object
public NodeEditorData nodeEditorData;
public GraphEditorData nodeEditorData;
public void CreateGUI(){
@ -51,7 +49,6 @@ namespace TNode.Editor{
SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200);
var searchWindow = CreateInstance<SearchWindowProvider>();
searchWindow.Setup(typeof(T),_graphView,this);
Debug.Log(searchWindow);
SearchWindow.Open(searchWindowContext, searchWindow);
});
});

@ -54,7 +54,6 @@ namespace TNode.Editor.Inspector{
protected void SetValue(T value){
NodeDataWrapper wrapper = _bindingNodeData;
Debug.Log(wrapper);
wrapper.SetValue(BindingPath,value);
}
public InspectorItem(){

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using TNode.Attribute;
using TNode.BaseViews;
using TNode.Editor.BaseViews;
using TNode.Models;
@ -54,12 +55,16 @@ namespace TNode.Editor.Inspector{
if (methodInfo != null){
var genericMethod = methodInfo.MakeGenericMethod(type);
var createdItem = genericMethod.Invoke(inspectorItemFactory,null) as VisualElement;
body.Add(createdItem);
if (createdItem is INodeDataBindingBase castedItem){
castedItem.BindingNodeData = _data;
castedItem.BindingPath = bindingPath;
}
//Check if field has DisableOnInspector attribute and if so,disable it
if (field.GetCustomAttribute<DisableOnInspectorAttribute>() != null){
createdItem?.SetEnabled(false);
}
}
}
}

@ -25,7 +25,6 @@ namespace TNode.Editor.Inspector{
private void RefreshInspector(){
Clear();
Debug.Log("In Node node inspector refresh for new data " + _data);
InspectorItemFactory inspectorItemFactory = new InspectorItemFactory();
foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){
var bindingPath = field.Name;

@ -1,12 +1,13 @@
using System;
using TNode.Models;
using UnityEngine;
using UnityEngine.Serialization;
namespace TNode.Editor.Model{
[Serializable]
public class NodeEditorData:ScriptableObject{
[SerializeReference] public NodeData nodeData;
public class NodeEditorData{
public string nodeGuid;
public Rect nodePos;
}
}

@ -18,7 +18,7 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
private TextField _editorClassNameTextField;
private TextField _graphClassNameTextField;
private Button _createButton;
private readonly SourceGeneratorForGraphEditor _sourceGeneratorForGraphEditor = new SourceGeneratorForGraphEditor();
[MenuItem("Assets/Create/TNode/Create New Graph Editor")]
[MenuItem("TNode/Create New Graph Editor")]
public static void ShowExample()
@ -92,19 +92,21 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
private void OnCreateButtonClicked(){
//Create a new .cs file at current opened asset folder
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (path == "")
{
if (path == ""){
path = "Assets";
}
else if (Path.GetExtension(path) != "")
{
else if (Path.GetExtension(path) != ""){
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
}
var pathBeforeEditor = path;
//if the path is not named with editor, create a new folder called editor at the path
if (!path.EndsWith("Editor"))
if (!path.EndsWith("/Editor"))
{
AssetDatabase.CreateFolder(path, "Editor");
path = path + "/Editor";
pathBeforeEditor = path;
path += "/Editor";
}
//Query the name of the graph editor
string editorName =_editorClassNameTextField.text;
@ -115,15 +117,17 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
editorName = "NewGraphEditor";
}
SourceGeneratorForGraphEditor sourceGeneratorForGraphEditor = new SourceGeneratorForGraphEditor();
var source = sourceGeneratorForGraphEditor.GenerateGraphEditor(editorName,graphName);
CreateResource(editorName, graphName, graphViewName, path, pathBeforeEditor);
}
var sourceGraph = sourceGeneratorForGraphEditor.GenerateGraph(graphName);
private void CreateResource(string editorName, string graphName, string graphViewName, string path,
string pathBeforeEditor){
var source = _sourceGeneratorForGraphEditor.GenerateGraphEditor(editorName, graphName);
var sourceGraphView = sourceGeneratorForGraphEditor.GenerateGraphView(graphViewName,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 graphPath = Path.Combine(pathBeforeEditor, graphName + ".cs");
string graphViewPath = Path.Combine(path, graphViewName + ".cs");
File.WriteAllText(editorPath, source);
File.WriteAllText(graphPath, sourceGraph);
@ -132,32 +136,36 @@ namespace TNode.Editor.Tools.GraphEditorCreator{
AssetDatabase.Refresh();
//Wait for the new file to be imported
while (!AssetDatabase.LoadAssetAtPath<MonoScript>(editorPath))
{
EditorUtility.DisplayProgressBar("Generating Graph Editor", "Please wait while the new graph editor is being imported", 0.5f);
while (!AssetDatabase.LoadAssetAtPath<MonoScript>(editorPath)){
EditorUtility.DisplayProgressBar("Generating Graph Editor",
"Please wait while the new graph editor is being imported", 0.5f);
EditorApplication.update();
}
//Create an NodeAttribute Editor Data Instance for the new graph editor
NodeEditorData nodeEditorData = ScriptableObject.CreateInstance<NodeEditorData>();
nodeEditorData.name = editorName;
EditorUtility.SetDirty(nodeEditorData);
var graphEditorData = ScriptableObject.CreateInstance<GraphEditorData>();
graphEditorData.name = editorName;
VisualTreeAsset defaultEditorTree = Resources.Load<VisualTreeAsset>("GraphEditor");
EditorUtility.SetDirty(graphEditorData);
//Save it at the same folder as the new graph editor
string nodeEditorDataPath = Path.Combine(path, editorName + ".asset");
AssetDatabase.CreateAsset(nodeEditorData, nodeEditorDataPath);
string grapEditorPath = Path.Combine(path, editorName + ".asset");
AssetDatabase.CreateAsset(graphEditorData, grapEditorPath);
//Wait for the new file to be imported
while (!AssetDatabase.LoadAssetAtPath<NodeEditorData>(nodeEditorDataPath))
{
EditorUtility.DisplayProgressBar("Generating Graph Editor", "Please wait while the new graph editor is being imported", 0.5f);
while (!AssetDatabase.LoadAssetAtPath<GraphEditorData>(grapEditorPath)){
EditorUtility.DisplayProgressBar("Generating Graph Editor",
"Please wait while the new graph editor is being imported", 0.5f);
EditorApplication.update();
}
var script = AssetDatabase.LoadAssetAtPath<MonoScript>(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});
monoImporter.SetDefaultReferences(new string[]{"graphEditorData", "mVisualTreeAsset"},
new Object[]{graphEditorData, defaultEditorTree});
//Refresh the asset ann close it

@ -16,9 +16,11 @@ namespace TNode.Models{
public NodeData() : base(){
//Object Registration
id = Guid.NewGuid().ToString();
}
[DisableOnInspector]
public string id;
public string nodeName;
[ShowInNodeView]
public bool entryPoint;
// #if UNITY_EDITOR
// public Rect rect;

Loading…
Cancel
Save