diff --git a/TNode/GraphCreator/Editor/GraphCreator.cs b/TNode/GraphCreator/Editor/GraphCreator.cs index 3d407ee..18a3656 100644 --- a/TNode/GraphCreator/Editor/GraphCreator.cs +++ b/TNode/GraphCreator/Editor/GraphCreator.cs @@ -1,4 +1,5 @@ -using TNodeCore.Editor; +using TNode.GraphCreator.Runtime; +using TNodeCore.Editor; namespace TNode.GraphCreator.Editor{ public class GraphCreator:GraphEditor{ diff --git a/TNode/GraphCreator/Runtime/MetaGraph.cs b/TNode/GraphCreator/Runtime/MetaGraph.cs index 61e8d3c..3f0c953 100644 --- a/TNode/GraphCreator/Runtime/MetaGraph.cs +++ b/TNode/GraphCreator/Runtime/MetaGraph.cs @@ -1,6 +1,6 @@ using TNodeCore.Runtime.Models; -namespace TNode.GraphCreator.Editor{ +namespace TNode.GraphCreator.Runtime{ public class MetaGraph : GraphData{ } } \ No newline at end of file diff --git a/TNode/GraphCreator/Runtime/Nodes/GraphMetaNode.cs b/TNode/GraphCreator/Runtime/Nodes/GraphMetaNode.cs index 6accd68..4b4241a 100644 --- a/TNode/GraphCreator/Runtime/Nodes/GraphMetaNode.cs +++ b/TNode/GraphCreator/Runtime/Nodes/GraphMetaNode.cs @@ -1,5 +1,4 @@ using System; -using TNode.GraphCreator.Editor; using TNodeCore.Runtime.Attributes; namespace TNode.GraphCreator.Runtime.Nodes{ diff --git a/TNode/TNodeCore/Editor/EditorPersistence/GraphEditorData.cs b/TNode/TNodeCore/Editor/EditorPersistence/GraphEditorData.cs index 10414d7..5f5f5ac 100644 --- a/TNode/TNodeCore/Editor/EditorPersistence/GraphEditorData.cs +++ b/TNode/TNodeCore/Editor/EditorPersistence/GraphEditorData.cs @@ -23,8 +23,6 @@ namespace TNodeCore.Editor.EditorPersistence{ return (IDataGraphView)GraphViewImplCreator.Invoke(typeof(T)); } - - case GraphImplType.GraphToolsFoundationImpl: throw new NotImplementedException(); default: diff --git a/TNode/TNodeCore/Editor/Resources/ScriptTemplates/ExampleGraph.cs.txt b/TNode/TNodeCore/Editor/Resources/ScriptTemplates/ExampleGraph.cs.txt new file mode 100644 index 0000000..4c1f292 --- /dev/null +++ b/TNode/TNodeCore/Editor/Resources/ScriptTemplates/ExampleGraph.cs.txt @@ -0,0 +1,4 @@ + +public class Example$GraphClassName$Node:NodeData{ + +} diff --git a/TNode/TNodeCore/Editor/Resources/ScriptTemplates/ExampleGraph.cs.txt.meta b/TNode/TNodeCore/Editor/Resources/ScriptTemplates/ExampleGraph.cs.txt.meta new file mode 100644 index 0000000..a6ca584 --- /dev/null +++ b/TNode/TNodeCore/Editor/Resources/ScriptTemplates/ExampleGraph.cs.txt.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 608d45120d7a4f5ca5091a1427d8843a +timeCreated: 1659602294 \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraph.cs.txt b/TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraph.cs.txt index 913d60c..112aa49 100644 --- a/TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraph.cs.txt +++ b/TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraph.cs.txt @@ -1,7 +1,6 @@ -using TNode.Models; -using UnityEngine; -using UnityEditor; +using UnityEngine; using System; +using TNodeCore.Runtime.Models; [CreateAssetMenu(fileName = "New $GraphClassName$", menuName = "TNode/$GraphClassName$")] [Serializable] public class $GraphClassName$ : GraphData{ diff --git a/TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt b/TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt index 1f5ad7e..c8f187e 100644 --- a/TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt +++ b/TNode/TNodeCore/Editor/Resources/ScriptTemplates/NewGraphEditor.cs.txt @@ -1,22 +1,25 @@ -using TNode.Editor; -using UnityEditor; +using UnityEditor; using UnityEditor.Callbacks; -using UnityEditor.Experimental.GraphView; using UnityEngine; -using UnityEngine.UIElements; -using System; +using TNodeCore.Editor; public class $EditorClassName$ : GraphEditor<$GraphClassName$>{ [OnOpenAsset] public static bool OnOpenAsset(int instanceID, int line){ - var graph = EditorUtility.InstanceIDToObject(instanceID) as $GraphClassName$; - if (graph != null) - { - var wnd = GetWindow<$EditorClassName$>(); - wnd.titleContent = new GUIContent("$GraphClassName$ Editor"); - wnd.CreateGUI(); - wnd._graphView.Data = graph; - return true; - } - return false; + var graph = EditorUtility.InstanceIDToObject(instanceID) as $GraphClassName$; + if (graph != null) { + var wnd = GetWindow<$EditorClassName$>(); + wnd.titleContent = new GUIContent("$GraphClassName$ Editor"); + wnd.Show(); + wnd.SetupNonRuntime(graph); + return true; + } + return false; } + [MenuItem("Window/$EditorClassName$")] + public static void ShowWindow(){ + var res = GetWindow<$EditorClassName$>(); + res.titleContent = new GUIContent("$GraphClassName$ Editor"); + res.Show(); + } + } \ No newline at end of file diff --git a/TNode/TNodeCore/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs b/TNode/TNodeCore/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs index 0d166b1..c845d76 100644 --- a/TNode/TNodeCore/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs +++ b/TNode/TNodeCore/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs @@ -26,7 +26,7 @@ namespace TNodeCore.Editor.Tools.GraphEditorCreator{ GraphEditorCreator wnd = GetWindow(); wnd.titleContent = new GUIContent("GraphEditorCreator"); //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 wnd.minSize = 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 sourceGraph = _sourceGeneratorForGraphEditor.GenerateGraph(graphName); - var sourceGraphView = _sourceGeneratorForGraphEditor.GenerateGraphView(graphViewName, graphName); + //var sourceGraphView = _sourceGeneratorForGraphEditor.GenerateGraphView(graphViewName, graphName); string editorPath = Path.Combine(path, editorName + ".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(graphPath, sourceGraph); - File.WriteAllText(graphViewPath, sourceGraphView); + //File.WriteAllText(graphViewPath, sourceGraphView); //Refresh the AssetDatabase to import the new file AssetDatabase.Refresh(); diff --git a/TNode/TNodeCore/Runtime/Attributes/ModelColor.cs b/TNode/TNodeCore/Runtime/Attributes/ModelColor.cs deleted file mode 100644 index ae7106c..0000000 --- a/TNode/TNodeCore/Runtime/Attributes/ModelColor.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace TNodeCore.Runtime.Attributes{ - public class ModelColor{ - - } -} \ No newline at end of file diff --git a/TNode/TNodeCore/Runtime/Attributes/PortColor.cs b/TNode/TNodeCore/Runtime/Attributes/PortColor.cs new file mode 100644 index 0000000..998f75b --- /dev/null +++ b/TNode/TNodeCore/Runtime/Attributes/PortColor.cs @@ -0,0 +1,17 @@ +using System; +using UnityEngine; + +namespace TNodeCore.Runtime.Attributes{ + /// + /// this attribute only works on implemented types + /// + 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); + } + } +} \ No newline at end of file diff --git a/TNode/TNodeCore/Runtime/Attributes/ModelColor.cs.meta b/TNode/TNodeCore/Runtime/Attributes/PortColor.cs.meta similarity index 100% rename from TNode/TNodeCore/Runtime/Attributes/ModelColor.cs.meta rename to TNode/TNodeCore/Runtime/Attributes/PortColor.cs.meta diff --git a/TNode/TNodeCore/Runtime/Logger.meta b/TNode/TNodeCore/Runtime/Logger.meta new file mode 100644 index 0000000..841905b --- /dev/null +++ b/TNode/TNodeCore/Runtime/Logger.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f70fd0a222b9459093dff6c2b0679c3c +timeCreated: 1659682655 \ No newline at end of file diff --git a/TNode/TNodeCore/Runtime/NodeLogger.cs b/TNode/TNodeCore/Runtime/Logger/NodeLogger.cs similarity index 100% rename from TNode/TNodeCore/Runtime/NodeLogger.cs rename to TNode/TNodeCore/Runtime/Logger/NodeLogger.cs diff --git a/TNode/TNodeCore/Runtime/NodeLogger.cs.meta b/TNode/TNodeCore/Runtime/Logger/NodeLogger.cs.meta similarity index 100% rename from TNode/TNodeCore/Runtime/NodeLogger.cs.meta rename to TNode/TNodeCore/Runtime/Logger/NodeLogger.cs.meta diff --git a/TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs b/TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs index 598fe9d..738cd85 100644 --- a/TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs +++ b/TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs @@ -84,6 +84,10 @@ namespace TNode.TNodeGraphViewImpl.Editor.Cache{ private IBaseDataGraphView GraphViewImplCreator(Type arg){ var genericType = typeof(BaseDataGraphView<>).MakeGenericType(arg); var instance = CreateViewComponentFromBaseType(genericType) as IBaseDataGraphView; + if (instance == null){ + //fallback to default graph view + instance = (IBaseDataGraphView) Activator.CreateInstance(genericType); + } return instance; } private void SetGraphUsageAttribute(Type type){ diff --git a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardDataEntry.cs b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardDataEntry.cs index b94a32f..3097e50 100644 --- a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardDataEntry.cs +++ b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardDataEntry.cs @@ -1,5 +1,6 @@ using System; -using System.Collections; +using System.Reflection; +using TNodeCore.Runtime.Attributes; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; @@ -8,37 +9,34 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{ public class BlackboardDataEntry:GraphElement{ public Type propertyType; public string propertyPath; + private Color _convertedColor; public BlackboardDataEntry(Type type){ propertyType = type; if (typeof(Component).IsAssignableFrom(propertyType)){ this.AddToClassList("typeComponent"); - } - if (typeof(GameObject).IsAssignableFrom(propertyType)){ + }else if (typeof(GameObject).IsAssignableFrom(propertyType)){ 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.AddManipulator(new SelectionDropper()); var styleSheet = Resources.Load("BlackboardDataEntry"); this.styleSheets.Add(styleSheet); + if (type.GetCustomAttribute() is {} portColorAttribute){ + _convertedColor = portColorAttribute.Color; + } this.RegisterCallback((evt) => { style.borderBottomColor=style.borderRightColor=style.borderLeftColor=style.borderTopColor=new Color(1,1,1,1); }); this.RegisterCallback((evt) => { style.borderBottomColor = style.borderRightColor = - style.borderLeftColor = style.borderTopColor = StyleKeyword.Null; + style.borderLeftColor = style.borderTopColor = _convertedColor==default?StyleKeyword.Null:_convertedColor; }); - } } } \ No newline at end of file diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs index a94b9cf..ccca056 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs @@ -6,6 +6,7 @@ using TNode.TNodeGraphViewImpl.Editor.Ports; using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.Serialization; using TNodeCore.Runtime; +using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes.Ports; using TNodeCore.Runtime.Models; using UnityEditor; @@ -141,27 +142,31 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{ Port port = new CustomPort(Orientation.Horizontal, Direction.Output, attribute.Multiple ? Port.Capacity.Multi : Port.Capacity.Single, BuildPortType(attribute, propertyInfo)); - - this.outputContainer.Add(port); - var portName = ObjectNames.NicifyVariableName(BuildPortName(attribute,propertyInfo)); - port.portName = portName; - port.name = propertyInfo.Name; + BuildPort(port, attribute, propertyInfo,outputContainer); } } foreach (var propertyInfo in propertyInfos){ 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)); - this.inputContainer.Add(port); - var portName = BuildPortName(attribute,propertyInfo); - port.portName = portName; - port.name = propertyInfo.Name; - + 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){ + portContainer.Add(port); + var portName = ObjectNames.NicifyVariableName(BuildPortName(attribute, propertyInfo)); + port.portName = portName; + port.name = propertyInfo.Name; + var colorAtt = propertyInfo.PropertyType.GetCustomAttribute(); + if (colorAtt != null){ + var color = colorAtt.Color; + port.portColor = color; + } + } + public void StartARenameTitleTextField(){ var textField = new TextField{ value = title, @@ -220,8 +225,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{ public override void SetPosition(Rect newPos){ var graphView = (GraphView)BaseDataGraphView; //Cast newPos s position to global space - var globalPos = graphView.contentViewContainer.LocalToWorld(newPos.position); - _data.positionInView.position = globalPos; + _data.positionInView.position = newPos.position; base.SetPosition(newPos); } diff --git a/TNode/TNodeGraphViewImpl/Editor/Resources/BlackboardDataEntry.uss b/TNode/TNodeGraphViewImpl/Editor/Resources/BlackboardDataEntry.uss index e0ad638..b51fec5 100644 --- a/TNode/TNodeGraphViewImpl/Editor/Resources/BlackboardDataEntry.uss +++ b/TNode/TNodeGraphViewImpl/Editor/Resources/BlackboardDataEntry.uss @@ -6,7 +6,19 @@ border-width: 1px; border-color: rgba(201, 249, 116, 255); } -.vector{ +.Int32{ 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; } \ No newline at end of file