feature:port color support

main
taoria 3 years ago
parent 9c5a734ad7
commit 2d1bd4ba1a
  1. 3
      TNode/GraphCreator/Editor/GraphCreator.cs
  2. 2
      TNode/GraphCreator/Runtime/MetaGraph.cs
  3. 1
      TNode/GraphCreator/Runtime/Nodes/GraphMetaNode.cs
  4. 2
      TNode/TNodeCore/Editor/EditorPersistence/GraphEditorData.cs
  5. 4
      TNode/TNodeCore/Editor/Resources/ScriptTemplates/ExampleGraph.cs.txt
  6. 3
      TNode/TNodeCore/Editor/Resources/ScriptTemplates/ExampleGraph.cs.txt.meta
  7. 5
      TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraph.cs.txt
  8. 21
      TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt
  9. 8
      TNode/TNodeCore/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs
  10. 5
      TNode/TNodeCore/Runtime/Attributes/ModelColor.cs
  11. 17
      TNode/TNodeCore/Runtime/Attributes/PortColor.cs
  12. 0
      TNode/TNodeCore/Runtime/Attributes/PortColor.cs.meta
  13. 3
      TNode/TNodeCore/Runtime/Logger.meta
  14. 0
      TNode/TNodeCore/Runtime/Logger/NodeLogger.cs
  15. 0
      TNode/TNodeCore/Runtime/Logger/NodeLogger.cs.meta
  16. 4
      TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs
  17. 26
      TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardDataEntry.cs
  18. 30
      TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs
  19. 16
      TNode/TNodeGraphViewImpl/Editor/Resources/BlackboardDataEntry.uss

@ -1,4 +1,5 @@
using TNodeCore.Editor; using TNode.GraphCreator.Runtime;
using TNodeCore.Editor;
namespace TNode.GraphCreator.Editor{ namespace TNode.GraphCreator.Editor{
public class GraphCreator:GraphEditor<MetaGraph>{ public class GraphCreator:GraphEditor<MetaGraph>{

@ -1,6 +1,6 @@
using TNodeCore.Runtime.Models; using TNodeCore.Runtime.Models;
namespace TNode.GraphCreator.Editor{ namespace TNode.GraphCreator.Runtime{
public class MetaGraph : GraphData{ public class MetaGraph : GraphData{
} }
} }

@ -1,5 +1,4 @@
using System; using System;
using TNode.GraphCreator.Editor;
using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes;
namespace TNode.GraphCreator.Runtime.Nodes{ namespace TNode.GraphCreator.Runtime.Nodes{

@ -23,8 +23,6 @@ namespace TNodeCore.Editor.EditorPersistence{
return (IDataGraphView<T>)GraphViewImplCreator.Invoke(typeof(T)); return (IDataGraphView<T>)GraphViewImplCreator.Invoke(typeof(T));
} }
case GraphImplType.GraphToolsFoundationImpl: case GraphImplType.GraphToolsFoundationImpl:
throw new NotImplementedException(); throw new NotImplementedException();
default: default:

@ -0,0 +1,4 @@

public class Example$GraphClassName$Node:NodeData{
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 608d45120d7a4f5ca5091a1427d8843a
timeCreated: 1659602294

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

@ -1,22 +1,25 @@
using TNode.Editor; using UnityEditor;
using UnityEditor;
using UnityEditor.Callbacks; using UnityEditor.Callbacks;
using UnityEditor.Experimental.GraphView;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using TNodeCore.Editor;
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) {
{
var wnd = GetWindow<$EditorClassName$>(); var wnd = GetWindow<$EditorClassName$>();
wnd.titleContent = new GUIContent("$GraphClassName$ Editor"); wnd.titleContent = new GUIContent("$GraphClassName$ Editor");
wnd.CreateGUI(); wnd.Show();
wnd._graphView.Data = graph; wnd.SetupNonRuntime(graph);
return true; return true;
} }
return false; return false;
} }
[MenuItem("Window/$EditorClassName$")]
public static void ShowWindow(){
var res = GetWindow<$EditorClassName$>();
res.titleContent = new GUIContent("$GraphClassName$ Editor");
res.Show();
}
} }

@ -26,7 +26,7 @@ namespace TNodeCore.Editor.Tools.GraphEditorCreator{
GraphEditorCreator wnd = GetWindow<GraphEditorCreator>(); GraphEditorCreator wnd = GetWindow<GraphEditorCreator>();
wnd.titleContent = new GUIContent("GraphEditorCreator"); wnd.titleContent = new GUIContent("GraphEditorCreator");
//Set position to the center of the screen //Set position to the center of the screen
wnd.position = new(Screen.width / 2, Screen.height / 2, 500, 300); wnd.position = new(Screen.width / 2.0f, Screen.height / 2.0f, 500, 300);
//set this window non resizable //set this window non resizable
wnd.minSize = new Vector2(500, 300); wnd.minSize = new Vector2(500, 300);
wnd.maxSize = new Vector2(500, 300); wnd.maxSize = new Vector2(500, 300);
@ -125,13 +125,13 @@ namespace TNodeCore.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); //var sourceGraphView = _sourceGeneratorForGraphEditor.GenerateGraphView(graphViewName, graphName);
string editorPath = Path.Combine(path, editorName + ".cs"); string editorPath = Path.Combine(path, editorName + ".cs");
string graphPath = Path.Combine(pathBeforeEditor, graphName + ".cs"); string graphPath = Path.Combine(pathBeforeEditor, graphName + ".cs");
string graphViewPath = Path.Combine(path, graphViewName + ".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); //File.WriteAllText(graphViewPath, sourceGraphView);
//Refresh the AssetDatabase to import the new file //Refresh the AssetDatabase to import the new file
AssetDatabase.Refresh(); AssetDatabase.Refresh();

@ -1,5 +0,0 @@
namespace TNodeCore.Runtime.Attributes{
public class ModelColor{
}
}

@ -0,0 +1,17 @@
using System;
using UnityEngine;
namespace TNodeCore.Runtime.Attributes{
/// <summary>
/// this attribute only works on implemented types
/// </summary>
public class PortColorAttribute : Attribute{
public Color Color;
public PortColorAttribute(float r, float g, float b){
Color = new Color(r, g, b);
}
public PortColorAttribute(int r, int g,int b){
Color = new Color(r/255.0f, g/255.0f, b/255.0f);
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f70fd0a222b9459093dff6c2b0679c3c
timeCreated: 1659682655

@ -84,6 +84,10 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{
private IBaseDataGraphView GraphViewImplCreator(Type arg){ private IBaseDataGraphView GraphViewImplCreator(Type arg){
var genericType = typeof(BaseDataGraphView<>).MakeGenericType(arg); var genericType = typeof(BaseDataGraphView<>).MakeGenericType(arg);
var instance = CreateViewComponentFromBaseType(genericType) as IBaseDataGraphView; var instance = CreateViewComponentFromBaseType(genericType) as IBaseDataGraphView;
if (instance == null){
//fallback to default graph view
instance = (IBaseDataGraphView) Activator.CreateInstance(genericType);
}
return instance; return instance;
} }
private void SetGraphUsageAttribute(Type type){ private void SetGraphUsageAttribute(Type type){

@ -1,5 +1,6 @@
using System; using System;
using System.Collections; using System.Reflection;
using TNodeCore.Runtime.Attributes;
using UnityEditor.Experimental.GraphView; using UnityEditor.Experimental.GraphView;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
@ -8,37 +9,34 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
public class BlackboardDataEntry:GraphElement{ public class BlackboardDataEntry:GraphElement{
public Type propertyType; public Type propertyType;
public string propertyPath; public string propertyPath;
private Color _convertedColor;
public BlackboardDataEntry(Type type){ public BlackboardDataEntry(Type type){
propertyType = type; propertyType = type;
if (typeof(Component).IsAssignableFrom(propertyType)){ if (typeof(Component).IsAssignableFrom(propertyType)){
this.AddToClassList("typeComponent"); this.AddToClassList("typeComponent");
} }else if (typeof(GameObject).IsAssignableFrom(propertyType)){
if (typeof(GameObject).IsAssignableFrom(propertyType)){
this.AddToClassList("gameObject"); this.AddToClassList("gameObject");
}else{
this.AddToClassList(propertyType.Name);
} }
if (typeof(Vector2).IsAssignableFrom(propertyType)){
this.AddToClassList("vector");
}
if (typeof(Vector2Int).IsAssignableFrom(propertyType)){
this.AddToClassList("vector");
}
if (typeof(IList).IsAssignableFrom(propertyType)){
this.AddToClassList("list");
}
this.capabilities |= Capabilities.Selectable | Capabilities.Deletable | Capabilities.Droppable | Capabilities.Renamable; this.capabilities |= Capabilities.Selectable | Capabilities.Deletable | Capabilities.Droppable | Capabilities.Renamable;
this.AddManipulator(new SelectionDropper()); this.AddManipulator(new SelectionDropper());
var styleSheet = Resources.Load<StyleSheet>("BlackboardDataEntry"); var styleSheet = Resources.Load<StyleSheet>("BlackboardDataEntry");
this.styleSheets.Add(styleSheet); this.styleSheets.Add(styleSheet);
if (type.GetCustomAttribute<PortColorAttribute>() is {} portColorAttribute){
_convertedColor = portColorAttribute.Color;
}
this.RegisterCallback<MouseEnterEvent>((evt) => { this.RegisterCallback<MouseEnterEvent>((evt) => {
style.borderBottomColor=style.borderRightColor=style.borderLeftColor=style.borderTopColor=new Color(1,1,1,1); style.borderBottomColor=style.borderRightColor=style.borderLeftColor=style.borderTopColor=new Color(1,1,1,1);
}); });
this.RegisterCallback<MouseLeaveEvent>((evt) => { this.RegisterCallback<MouseLeaveEvent>((evt) => {
style.borderBottomColor = style.borderRightColor = style.borderBottomColor = style.borderRightColor =
style.borderLeftColor = style.borderTopColor = StyleKeyword.Null; style.borderLeftColor = style.borderTopColor = _convertedColor==default?StyleKeyword.Null:_convertedColor;
}); });
} }
} }
} }

@ -6,6 +6,7 @@ using TNode.TNodeGraphViewImpl.Editor.Ports;
using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Serialization; using TNodeCore.Editor.Serialization;
using TNodeCore.Runtime; using TNodeCore.Runtime;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Attributes.Ports; using TNodeCore.Runtime.Attributes.Ports;
using TNodeCore.Runtime.Models; using TNodeCore.Runtime.Models;
using UnityEditor; using UnityEditor;
@ -141,24 +142,28 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{
Port port = new CustomPort(Orientation.Horizontal, Direction.Output, Port port = new CustomPort(Orientation.Horizontal, Direction.Output,
attribute.Multiple ? Port.Capacity.Multi : Port.Capacity.Single, attribute.Multiple ? Port.Capacity.Multi : Port.Capacity.Single,
BuildPortType(attribute, propertyInfo)); BuildPortType(attribute, propertyInfo));
BuildPort(port, attribute, propertyInfo,outputContainer);
this.outputContainer.Add(port);
var portName = ObjectNames.NicifyVariableName(BuildPortName(attribute,propertyInfo));
port.portName = portName;
port.name = propertyInfo.Name;
} }
} }
foreach (var propertyInfo in propertyInfos){ foreach (var propertyInfo in propertyInfos){
if(propertyInfo.GetCustomAttributes(typeof(InputAttribute),true).FirstOrDefault() is InputAttribute attribute){ if(propertyInfo.GetCustomAttributes(typeof(InputAttribute),true).FirstOrDefault() is InputAttribute attribute){
Port port = new CustomPort
(Orientation.Horizontal,
Direction.Input,attribute.Multiple?Port.Capacity.Multi: Port.Capacity.Single,BuildPortType(attribute,propertyInfo));
BuildPort(port,attribute,propertyInfo,inputContainer);
}
}
}
private void BuildPort(Port port, PortAttribute attribute, PropertyInfo propertyInfo,VisualElement portContainer){
Port port = new CustomPort(Orientation.Horizontal, Direction.Input,attribute.Multiple?Port.Capacity.Multi:Port.Capacity.Single,BuildPortType(attribute,propertyInfo)); portContainer.Add(port);
this.inputContainer.Add(port); var portName = ObjectNames.NicifyVariableName(BuildPortName(attribute, propertyInfo));
var portName = BuildPortName(attribute,propertyInfo);
port.portName = portName; port.portName = portName;
port.name = propertyInfo.Name; port.name = propertyInfo.Name;
var colorAtt = propertyInfo.PropertyType.GetCustomAttribute<PortColorAttribute>();
} if (colorAtt != null){
var color = colorAtt.Color;
port.portColor = color;
} }
} }
@ -220,8 +225,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{
public override void SetPosition(Rect newPos){ public override void SetPosition(Rect newPos){
var graphView = (GraphView)BaseDataGraphView; var graphView = (GraphView)BaseDataGraphView;
//Cast newPos s position to global space //Cast newPos s position to global space
var globalPos = graphView.contentViewContainer.LocalToWorld(newPos.position); _data.positionInView.position = newPos.position;
_data.positionInView.position = globalPos;
base.SetPosition(newPos); base.SetPosition(newPos);
} }

@ -6,7 +6,19 @@
border-width: 1px; border-width: 1px;
border-color: rgba(201, 249, 116, 255); border-color: rgba(201, 249, 116, 255);
} }
.vector{ .Int32{
border-width: 1px; border-width: 1px;
border-color: rgba(0.788, 0.969, 0.455, 1.000); border-color: rgba(148,130,230,255);
}
.Float{
border-width: 1px;
border-color: aquamarine;
}
.System32{
border-width: 1px;
border-color: aquamarine;
}
.String{
border-width: 1px;
border-color: crimson;
} }
Loading…
Cancel
Save