Skip to content

Commit

Permalink
fix: prioritize the use of PreloadedProjectSettings if present in the…
Browse files Browse the repository at this point in the history
… project.
  • Loading branch information
mob-sakai committed Dec 6, 2023
1 parent 6781c96 commit 7a2b449
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ private static Object[] GetPreloadedSettings(Type type)

protected static PreloadedProjectSettings GetDefaultSettings(Type type)
{
return GetPreloadedSettings(type).FirstOrDefault() as PreloadedProjectSettings;
return GetPreloadedSettings(type).FirstOrDefault() as PreloadedProjectSettings
?? AssetDatabase.FindAssets($"t:{nameof(PreloadedProjectSettings)}")
.Select(AssetDatabase.GUIDToAssetPath)
.Select(AssetDatabase.LoadAssetAtPath<PreloadedProjectSettings>)
.FirstOrDefault(x => x && x.GetType() == type);
}

protected static void SetDefaultSettings(PreloadedProjectSettings asset)
Expand Down Expand Up @@ -138,6 +142,9 @@ private void OnPlayModeStateChanged(PlayModeStateChange state)
public static T instance => s_Instance ? s_Instance : s_Instance = CreateInstance<T>();
#endif

/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected virtual void OnEnable()
{
#if UNITY_EDITOR
Expand All @@ -155,6 +162,9 @@ protected virtual void OnEnable()
s_Instance = this as T;
}

/// <summary>
/// This function is called when the behaviour becomes disabled.
/// </summary>
protected virtual void OnDisable()
{
#if UNITY_EDITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ private static Object[] GetPreloadedSettings(Type type)

protected static PreloadedProjectSettings GetDefaultSettings(Type type)
{
return GetPreloadedSettings(type).FirstOrDefault() as PreloadedProjectSettings;
return GetPreloadedSettings(type).FirstOrDefault() as PreloadedProjectSettings
?? AssetDatabase.FindAssets($"t:{nameof(PreloadedProjectSettings)}")
.Select(AssetDatabase.GUIDToAssetPath)
.Select(AssetDatabase.LoadAssetAtPath<PreloadedProjectSettings>)
.FirstOrDefault(x => x && x.GetType() == type);
}

protected static void SetDefaultSettings(PreloadedProjectSettings asset)
Expand Down Expand Up @@ -138,6 +142,9 @@ private void OnPlayModeStateChanged(PlayModeStateChange state)
public static T instance => s_Instance ? s_Instance : s_Instance = CreateInstance<T>();
#endif

/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected virtual void OnEnable()
{
#if UNITY_EDITOR
Expand All @@ -155,6 +162,9 @@ protected virtual void OnEnable()
s_Instance = this as T;
}

/// <summary>
/// This function is called when the behaviour becomes disabled.
/// </summary>
protected virtual void OnDisable()
{
#if UNITY_EDITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ private static Object[] GetPreloadedSettings(Type type)

protected static PreloadedProjectSettings GetDefaultSettings(Type type)
{
return GetPreloadedSettings(type).FirstOrDefault() as PreloadedProjectSettings;
return GetPreloadedSettings(type).FirstOrDefault() as PreloadedProjectSettings
?? AssetDatabase.FindAssets($"t:{nameof(PreloadedProjectSettings)}")
.Select(AssetDatabase.GUIDToAssetPath)
.Select(AssetDatabase.LoadAssetAtPath<PreloadedProjectSettings>)
.FirstOrDefault(x => x && x.GetType() == type);
}

protected static void SetDefaultSettings(PreloadedProjectSettings asset)
Expand Down

0 comments on commit 7a2b449

Please sign in to comment.