Skip to content

Commit 1d1d628

Browse files
[Editor] Fixes to creating assets missing Guids;
1 parent 9ff9117 commit 1d1d628

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Engine/Core/Jobs/JobSheduler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Threading.Tasks;
43

54
namespace Staple.Jobs;

Engine/Editor/StapleEditor+Panels.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,17 @@ private void CreateAssetMenu()
194194
{
195195
var assetInstance = (IStapleAsset)Activator.CreateInstance(pair.Value);
196196

197-
if (assetInstance != null && SaveAsset(assetPath, assetInstance))
197+
if (assetInstance != null)
198198
{
199-
RefreshAssets(false, null);
199+
if(assetInstance is IGuidAsset guidAsset)
200+
{
201+
guidAsset.Guid.Guid = GuidGenerator.Generate().ToString();
202+
}
203+
204+
if(SaveAsset(assetPath, assetInstance))
205+
{
206+
RefreshAssets(false, null);
207+
}
200208
}
201209
}
202210
catch (Exception e)

Engine/Editor/StapleEditor+Project.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,12 @@ public static bool SaveAsset(string assetPath, IStapleAsset assetInstance)
567567

568568
try
569569
{
570-
var guidField = assetInstance.GetType().GetProperty("Guid");
570+
var guidField = assetInstance.GetType().GetProperty(nameof(IGuidAsset.Guid), BindingFlags.Public | BindingFlags.Instance);
571571
var guid = Guid.NewGuid().ToString();
572572

573-
if (guidField != null && guidField.PropertyType == typeof(string) && guidField.GetValue(assetInstance) != null)
573+
if (guidField != null && guidField.PropertyType == typeof(GuidHasher) && guidField.GetValue(assetInstance) != null)
574574
{
575-
guid = (string)guidField.GetValue(assetInstance);
575+
guid = ((GuidHasher)guidField.GetValue(assetInstance)).Guid;
576576
}
577577

578578
var serialized = AssetSerialization.Serialize(assetInstance, StapleSerializationMode.Text);

0 commit comments

Comments
 (0)