Skip to content

Commit

Permalink
Merge pull request #33 from brunomikoski/feature/fix-aot-issue-again
Browse files Browse the repository at this point in the history
Feature/fix aot issue again
  • Loading branch information
brunomikoski committed Sep 4, 2020
2 parents 7f24966 + 054975e commit 8958abb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.6]
## Changed
- Fixed AOT issue.

## [1.2.5]
## Changed
- Fixed issue with the read only lists not refreshing properly on Inspector calls on PlayMode.
Expand Down Expand Up @@ -129,6 +133,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- Proper setup for automatic creation of necessary collections

[1.2.6]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.2.6
[1.2.5]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.2.5
[1.2.4]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.2.4
[1.2.3]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.2.3
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Editor/Utils/CollectionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static void CreateNewItem()
[MenuItem("Assets/Create/ScriptableObject Collection/Create Settings", false, 200)]
private static void CreateSettings()
{
ScriptableObjectCollectionSettings.LoadOrCreateInstance();
ScriptableObjectCollectionSettings.LoadOrCreateInstance<ScriptableObjectCollection>();
}

public static Editor GetEditorForItem(CollectableScriptableObject collectionItem)
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Runtime/CollectionsRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CollectionsRegistry : ResourceScriptableObjectSingleton<Collections

public void UsedOnlyForAOTCodeGeneration()
{
LoadOrCreateInstance();
LoadOrCreateInstance<CollectionsRegistry>();
// Include an exception so we can be sure to know if this method is ever called.
throw new InvalidOperationException("This method is used for AOT code generation only. Do not call it at runtime.");
}
Expand Down
16 changes: 8 additions & 8 deletions Scripts/Runtime/ResourceScriptableObjectSingleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public static T Instance
get
{
if (instance == null)
instance = LoadOrCreateInstance();
instance = LoadOrCreateInstance<T>();
return instance;
}
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static T LoadOrCreateInstance()
public static T2 LoadOrCreateInstance<T2>() where T2 : ScriptableObject
{
T newInstance = Resources.Load<T>(typeof(T).Name);
T2 newInstance = Resources.Load<T2>(typeof(T2).Name);

if (newInstance != null)
return newInstance;
Expand All @@ -28,22 +28,22 @@ public static T LoadOrCreateInstance()
if (Application.isPlaying)
return null;

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

if (!string.IsNullOrEmpty(registryGUID))
{
newInstance = (T) UnityEditor.AssetDatabase.LoadAssetAtPath<ScriptableObject>(
newInstance = (T2) UnityEditor.AssetDatabase.LoadAssetAtPath<ScriptableObject>(
UnityEditor.AssetDatabase.GUIDToAssetPath(registryGUID));
}

if (newInstance != null)
return newInstance;
return newInstance ;

newInstance = CreateInstance<T>();
newInstance = CreateInstance<T2>();

AssetDatabaseUtils.CreatePathIfDontExist("Assets/Resources");
UnityEditor.AssetDatabase.CreateAsset(newInstance, $"Assets/Resources/{typeof(T).Name}.asset");
UnityEditor.AssetDatabase.CreateAsset(newInstance, $"Assets/Resources/{typeof(T2).Name}.asset");
UnityEditor.AssetDatabase.SaveAssets();
UnityEditor.AssetDatabase.Refresh();
return newInstance;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.brunomikoski.scriptableobjectcollection",
"displayName": "Scriptable Object Collection",
"version": "1.2.5",
"version": "1.2.6",
"unity": "2018.4",
"description": "Scriptable Object Collection",
"keywords": [
Expand Down

0 comments on commit 8958abb

Please sign in to comment.