Skip to content

Commit d17013e

Browse files
dhsavellEvergreen
authored andcommitted
[UUM-98657] Fix missing SG icons during initial asset name entry
1 parent a5b74c4 commit d17013e

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

Packages/com.unity.shadergraph/Editor/AssetCallbacks/CreateShaderSubGraph.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CreateShaderSubGraph : EndNameEditAction
1010
public static void CreateMaterialSubGraph()
1111
{
1212
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateShaderSubGraph>(),
13-
string.Format("New Shader Sub Graph.{0}", ShaderSubGraphImporter.Extension), null, null);
13+
string.Format("New Shader Sub Graph.{0}", ShaderSubGraphImporter.Extension), ShaderSubGraphImporter.GetIcon(), null);
1414
}
1515

1616
public override void Action(int instanceId, string pathName, string resourceFile)

Packages/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public static void CreateNewGraph()
188188
var graphItem = ScriptableObject.CreateInstance<NewGraphAction>();
189189
graphItem.targets = null;
190190
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, graphItem,
191-
string.Format("New Shader Graph.{0}", ShaderGraphImporter.Extension), null, null);
191+
string.Format("New Shader Graph.{0}", ShaderGraphImporter.Extension), ShaderGraphImporter.GetIcon(), null);
192192
}
193193

194194
public static void CreateNewGraphWithOutputs(Target[] targets, BlockFieldDescriptor[] blockDescriptors)
@@ -197,7 +197,7 @@ public static void CreateNewGraphWithOutputs(Target[] targets, BlockFieldDescrip
197197
graphItem.targets = targets;
198198
graphItem.blocks = blockDescriptors;
199199
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, graphItem,
200-
string.Format("New Shader Graph.{0}", ShaderGraphImporter.Extension), null, null);
200+
string.Format("New Shader Graph.{0}", ShaderGraphImporter.Extension), ShaderGraphImporter.GetIcon(), null);
201201
}
202202

203203
public static bool TryGetMetadataOfType<T>(this Shader shader, out T obj) where T : ScriptableObject

Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ fixed4 frag (v2f i) : SV_Target
6464
Fallback Off
6565
}";
6666

67+
public static Texture2D GetIcon() => EditorGUIUtility.IconContent(IconBasePath)?.image as Texture2D;
68+
6769
[SuppressMessage("ReSharper", "UnusedMember.Local")]
6870
static string[] GatherDependenciesFromSourceFile(string assetPath)
6971
{
@@ -237,11 +239,7 @@ public override void OnImportAsset(AssetImportContext ctx)
237239
mainObject = ShaderUtil.CreateShaderAsset(ctx, k_ErrorShader, false);
238240
}
239241

240-
if (EditorGUIUtility.IconContent(IconBasePath)?.image is Texture2D icon)
241-
{
242-
ctx.AddObjectToAsset("MainAsset", mainObject, icon);
243-
}
244-
242+
ctx.AddObjectToAsset("MainAsset", mainObject, GetIcon());
245243
ctx.SetMainObject(mainObject);
246244

247245
var graphDataReadOnly = new GraphDataReadOnly(graph);

Packages/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class ShaderSubGraphImporter : ScriptedImporter
2525
public const string Extension = "shadersubgraph";
2626
const string IconBasePath = "Packages/com.unity.shadergraph/Editor/Resources/Icons/sg_subgraph_icon.png";
2727

28+
public static Texture2D GetIcon() => EditorGUIUtility.IconContent(IconBasePath)?.image as Texture2D;
29+
2830
[SuppressMessage("ReSharper", "UnusedMember.Local")]
2931
static string[] GatherDependenciesFromSourceFile(string assetPath)
3032
{
@@ -113,11 +115,7 @@ public override void OnImportAsset(AssetImportContext ctx)
113115
messageManager.ClearAll();
114116
}
115117

116-
if (EditorGUIUtility.IconContent(IconBasePath)?.image is Texture2D icon)
117-
{
118-
ctx.AddObjectToAsset("MainAsset", graphAsset, icon);
119-
}
120-
118+
ctx.AddObjectToAsset("MainAsset", graphAsset, GetIcon());
121119
ctx.SetMainObject(graphAsset);
122120

123121
var metadata = ScriptableObject.CreateInstance<ShaderSubGraphMetadata>();

0 commit comments

Comments
 (0)