From a18bc35a817c91b833f812eb50a597aa187c7a88 Mon Sep 17 00:00:00 2001 From: z3y Date: Sat, 14 Sep 2024 17:28:32 +0200 Subject: [PATCH] add warnings for properties --- Editor/Generation/PropertyDescriptor.cs | 20 ++++++++++++++++++++ Editor/ShaderGraphView.cs | 16 ++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Editor/Generation/PropertyDescriptor.cs b/Editor/Generation/PropertyDescriptor.cs index 0af5c3d..28373b0 100644 --- a/Editor/Generation/PropertyDescriptor.cs +++ b/Editor/Generation/PropertyDescriptor.cs @@ -576,6 +576,26 @@ public static VisualElement CreateReordableListElement(List e.onGUIHandler += () => { + var warnings = new List(); + if (!properties.Exists(x => x.referenceName == "_MainTex")) + { + warnings.Add("Missing property _MainTex"); + } + if (!properties.Exists(x => x.referenceName == "_Color")) + { + warnings.Add("Missing property _Color"); + } + + if (!properties.Exists(x => x.referenceName == "_BumpMap") && properties.Exists(x => x.defaultAttributes.HasFlag(MaterialPropertyAttribute.Normal))) + { + warnings.Add("Rename Normal Map to _BumpMap"); + } + + if (warnings.Count > 0) + { + EditorGUILayout.HelpBox(string.Join("\n", warnings), MessageType.Warning); + } + foreach (var p in properties) { p.graphView = graphView; diff --git a/Editor/ShaderGraphView.cs b/Editor/ShaderGraphView.cs index 36d88a0..cbca254 100644 --- a/Editor/ShaderGraphView.cs +++ b/Editor/ShaderGraphView.cs @@ -416,6 +416,10 @@ void OnDragPerform(DragPerformEvent evt) { DragAndDrop.AcceptDrag(); + + var pos = evt.localMousePosition; + TransformMousePositionToLocalSpace(ref pos, false); + foreach (var obj in DragAndDrop.objectReferences) { if (obj is Texture2D texture) @@ -423,6 +427,8 @@ void OnDragPerform(DragPerformEvent evt) // Create a new node var node = new Texture2DPropertyNode(); + var sample = new SampleTexture2DNode(); + var desc = new PropertyDescriptor(PropertyType.Texture2D, obj.name); graphData.properties.Add(desc); node.SetReference(desc.guid); @@ -447,9 +453,15 @@ void OnDragPerform(DragPerformEvent evt) } - var pos = evt.localMousePosition; - TransformMousePositionToLocalSpace(ref pos, false); CreateNode(node, pos, false); + CreateNode(sample, new Vector2(pos.x + 200, pos.y), false); + + var texPort = node.Outputs.First(x => x.GetPortID() == 0); + var inPort = sample.Inputs.First(x => x.GetPortID() == 1); + var newEdge = texPort.ConnectTo(inPort); + AddElement(newEdge); + node.GeneratePreviewForAffectedNodes(); + pos.y += 400; } }