Skip to content

Commit e338666

Browse files
author
Benoit Hudson
committed
UNI-22401: fix bug found by vkovec
Wasn't reloading when we changed projects. Now we reload a lot more often.
1 parent 165ce69 commit e338666

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
8888
{
8989
public const string kDefaultSavePath = "Objects";
9090

91-
public bool weldVertices = true;
92-
public bool embedTextures = false;
93-
public bool mayaCompatibleNames = true;
94-
public bool centerObjects = true;
91+
// Note: default values are set in LoadDefaults().
92+
public bool weldVertices;
93+
public bool embedTextures;
94+
public bool mayaCompatibleNames;
95+
public bool centerObjects;
9596

9697
/// <summary>
9798
/// The path where Convert To Model will save the new fbx and prefab.
@@ -104,7 +105,16 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
104105
/// value, properly interpreted for the current platform.
105106
/// </summary>
106107
[SerializeField]
107-
string convertToModelSavePath = kDefaultSavePath;
108+
string convertToModelSavePath;
109+
110+
protected override void LoadDefaults()
111+
{
112+
weldVertices = true;
113+
embedTextures = false;
114+
mayaCompatibleNames = true;
115+
centerObjects = true;
116+
convertToModelSavePath = kDefaultSavePath;
117+
}
108118

109119
/// <summary>
110120
/// The path where Convert To Model will save the new fbx and prefab.
@@ -287,6 +297,7 @@ static void ShowManager()
287297
{
288298
instance.name = "Fbx Export Settings";
289299
Selection.activeObject = instance;
300+
instance.Load();
290301
}
291302

292303
public void Save()
@@ -295,7 +306,7 @@ public void Save()
295306
}
296307
}
297308

298-
public class ScriptableSingleton<T> : ScriptableObject where T : ScriptableObject
309+
public abstract class ScriptableSingleton<T> : ScriptableObject where T : ScriptableSingleton<T>
299310
{
300311
private static T s_Instance;
301312
public static T instance
@@ -304,7 +315,8 @@ public static T instance
304315
{
305316
if (s_Instance == null)
306317
{
307-
return CreateAndLoad();
318+
s_Instance = ScriptableObject.CreateInstance<T>();
319+
s_Instance.Load();
308320
}
309321
return s_Instance;
310322
}
@@ -318,26 +330,23 @@ protected ScriptableSingleton()
318330
}
319331
}
320332

321-
private static T CreateAndLoad()
322-
{
323-
// First create.
324-
if (s_Instance == null)
325-
{
326-
s_Instance = ScriptableObject.CreateInstance<T>();
327-
}
333+
protected abstract void LoadDefaults();
328334

329-
// Then load.
335+
protected virtual void Load()
336+
{
330337
string filePath = GetFilePath();
331-
if (System.IO.File.Exists(filePath)) {
338+
if (!System.IO.File.Exists(filePath)) {
339+
LoadDefaults();
340+
} else {
332341
try {
333342
var fileData = System.IO.File.ReadAllText(filePath);
334343
EditorJsonUtility.FromJsonOverwrite(fileData, s_Instance);
335344
} catch(Exception xcp) {
336-
// Quash the exception and go on with the default settings.
345+
// Quash the exception and take the default settings.
337346
Debug.LogException(xcp);
347+
LoadDefaults();
338348
}
339349
}
340-
return s_Instance;
341350
}
342351

343352
protected virtual void Save(bool saveAsText)

0 commit comments

Comments
 (0)