Skip to content

Commit a579079

Browse files
author
Bruno Mikoski
committed
fix: AOT compilation warnings
1 parent 6db3e9d commit a579079

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

CHANGELOG.MD

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
8+
## [1.1.9]
9+
## Changed
10+
- Fixed AOT compilation issue
11+
712
## [1.1.8]
813
## Changed
914
- Fixed mobile builds (using editor references on runtime files)
1015

11-
1216
## [1.1.7]
1317
## Added
1418
- Proper error when there's no static script folder defined
@@ -96,6 +100,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
96100
## [Unreleased]
97101
- Add a setup wizzard for first time settings creation
98102

103+
[1.1.9]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.1.9
99104
[1.1.8]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.1.8
100105
[1.1.7]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.1.7
101106
[1.1.6]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.1.6

Scripts/Editor/Utils/CollectionUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static void CreateNewItem()
2727
[MenuItem("Assets/Create/ScriptableObject Collection/Create Settings", false, 200)]
2828
private static void CreateSettings()
2929
{
30-
ScriptableObjectCollectionSettings.LoadOrCreateInstance();
30+
ScriptableObjectCollectionSettings.LoadOrCreateInstance<ScriptableObjectCollectionSettings>();
3131
}
3232

3333
public static Editor GetEditorForItem(CollectableScriptableObject collectionItem)

Scripts/Runtime/CollectionsRegistry.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ public class CollectionsRegistry : ResourceScriptableObjectSingleton<Collections
1313
[SerializeField, HideInInspector]
1414
private List<string> collectionGUIDs = new List<string>();
1515

16+
public void UsedOnlyForAOTCodeGeneration()
17+
{
18+
LoadOrCreateInstance<CollectionsRegistry>();
19+
// Include an exception so we can be sure to know if this method is ever called.
20+
throw new InvalidOperationException("This method is used for AOT code generation only. Do not call it at runtime.");
21+
}
22+
1623
public bool IsKnowCollectionGUID(string guid)
1724
{
1825
ValidateCurrentGUIDs();

Scripts/Runtime/ResourceScriptableObjectSingleton.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,45 @@ public static T Instance
1010
{
1111
get
1212
{
13-
LoadOrCreateInstance();
13+
if (instance == null)
14+
instance = LoadOrCreateInstance<T>();
1415
return instance;
1516
}
1617
}
1718

1819
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
19-
public static void LoadOrCreateInstance()
20+
public static T LoadOrCreateInstance<T>() where T: ScriptableObject
2021
{
21-
if (instance != null)
22-
return;
23-
24-
instance = FindObjectOfType<T>();
25-
26-
if (instance != null)
27-
return;
28-
29-
instance = Resources.Load<T>(typeof(T).Name);
22+
T newInstance = Resources.Load<T>(typeof(T).Name);
3023

31-
if (instance != null)
32-
return;
24+
if (newInstance != null)
25+
return newInstance;
3326

3427
#if UNITY_EDITOR
3528
if (Application.isPlaying)
36-
return;
29+
return null;
3730

3831
string registryGUID = UnityEditor.AssetDatabase.FindAssets($"t:{typeof(T).Name}")
3932
.FirstOrDefault();
4033

4134
if (!string.IsNullOrEmpty(registryGUID))
4235
{
43-
instance = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(
36+
newInstance = (T) UnityEditor.AssetDatabase.LoadAssetAtPath<ScriptableObject>(
4437
UnityEditor.AssetDatabase.GUIDToAssetPath(registryGUID));
4538
}
39+
40+
if (newInstance != null)
41+
return newInstance;
4642

47-
if(instance != null)
48-
return;
49-
50-
51-
instance = CreateInstance<T>();
43+
newInstance = CreateInstance<T>();
5244

5345
AssetDatabaseUtils.CreatePathIfDontExist("Assets/Resources");
54-
UnityEditor.AssetDatabase.CreateAsset(instance, $"Assets/Resources/{typeof(T).Name}.asset");
46+
UnityEditor.AssetDatabase.CreateAsset(newInstance, $"Assets/Resources/{typeof(T).Name}.asset");
5547
UnityEditor.AssetDatabase.SaveAssets();
5648
UnityEditor.AssetDatabase.Refresh();
49+
return newInstance;
5750
#endif
51+
return null;
5852
}
5953
}
6054
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.brunomikoski.scriptableobjectcollection",
33
"displayName": "Scriptable Object Collection",
4-
"version": "1.1.8",
4+
"version": "1.1.9",
55
"unity": "2018.4",
66
"description": "Scriptable Object Collection",
77
"keywords": [
@@ -15,5 +15,9 @@
1515
"type": "git",
1616
"url": "https://github.com/badawe/ScriptableObjectCollection.git"
1717
},
18-
"bugs": "https://github.com/badawe/ScriptableObjectCollection/issues"
18+
"bugs": "https://github.com/badawe/ScriptableObjectCollection/issues",
19+
"author": {
20+
"name": "Bruno Mikoski",
21+
"url": "https://www.brunomikoski.com"
22+
}
1923
}

0 commit comments

Comments
 (0)