Skip to content

Commit

Permalink
add warnings for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
z3y committed Sep 14, 2024
1 parent 7f88dee commit a18bc35
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
20 changes: 20 additions & 0 deletions Editor/Generation/PropertyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,26 @@ public static VisualElement CreateReordableListElement(List<PropertyDescriptor>

e.onGUIHandler += () =>
{
var warnings = new List<string>();
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;
Expand Down
16 changes: 14 additions & 2 deletions Editor/ShaderGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,19 @@ 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)
{
// 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);
Expand All @@ -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;
}
}

Expand Down

0 comments on commit a18bc35

Please sign in to comment.