@@ -88,10 +88,11 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
88
88
{
89
89
public const string kDefaultSavePath = "Objects" ;
90
90
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 ;
95
96
96
97
/// <summary>
97
98
/// The path where Convert To Model will save the new fbx and prefab.
@@ -104,7 +105,16 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
104
105
/// value, properly interpreted for the current platform.
105
106
/// </summary>
106
107
[ 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
+ }
108
118
109
119
/// <summary>
110
120
/// The path where Convert To Model will save the new fbx and prefab.
@@ -287,6 +297,7 @@ static void ShowManager()
287
297
{
288
298
instance . name = "Fbx Export Settings" ;
289
299
Selection . activeObject = instance ;
300
+ instance . Load ( ) ;
290
301
}
291
302
292
303
public void Save ( )
@@ -295,7 +306,7 @@ public void Save()
295
306
}
296
307
}
297
308
298
- public class ScriptableSingleton < T > : ScriptableObject where T : ScriptableObject
309
+ public abstract class ScriptableSingleton < T > : ScriptableObject where T : ScriptableSingleton < T >
299
310
{
300
311
private static T s_Instance ;
301
312
public static T instance
@@ -304,7 +315,8 @@ public static T instance
304
315
{
305
316
if ( s_Instance == null )
306
317
{
307
- return CreateAndLoad ( ) ;
318
+ s_Instance = ScriptableObject . CreateInstance < T > ( ) ;
319
+ s_Instance . Load ( ) ;
308
320
}
309
321
return s_Instance ;
310
322
}
@@ -318,26 +330,23 @@ protected ScriptableSingleton()
318
330
}
319
331
}
320
332
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 ( ) ;
328
334
329
- // Then load.
335
+ protected virtual void Load ( )
336
+ {
330
337
string filePath = GetFilePath ( ) ;
331
- if ( System . IO . File . Exists ( filePath ) ) {
338
+ if ( ! System . IO . File . Exists ( filePath ) ) {
339
+ LoadDefaults ( ) ;
340
+ } else {
332
341
try {
333
342
var fileData = System . IO . File . ReadAllText ( filePath ) ;
334
343
EditorJsonUtility . FromJsonOverwrite ( fileData , s_Instance ) ;
335
344
} catch ( Exception xcp ) {
336
- // Quash the exception and go on with the default settings.
345
+ // Quash the exception and take the default settings.
337
346
Debug . LogException ( xcp ) ;
347
+ LoadDefaults ( ) ;
338
348
}
339
349
}
340
- return s_Instance ;
341
350
}
342
351
343
352
protected virtual void Save ( bool saveAsText )
0 commit comments