-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace AIO | ||
{ | ||
[Serializable] | ||
public class ScriptableObject<T> : ScriptableObject where T : ScriptableObject<T> | ||
{ | ||
#if UNITY_EDITOR | ||
private static T instance; | ||
#endif | ||
|
||
private static T GetResource() { return Resources.LoadAll<T>(typeof(T).Name).FirstOrDefault(item => item); } | ||
|
||
public static T GetOrCreate() | ||
{ | ||
#if UNITY_EDITOR | ||
if (!instance) | ||
{ | ||
foreach (var item in AssetDatabase | ||
.FindAssets($"t:{typeof(T).Name}", new[] { "Assets", }) | ||
.Select(AssetDatabase.GUIDToAssetPath) | ||
.Select(AssetDatabase.LoadAssetAtPath<T>) | ||
.Where(item => item)) | ||
{ | ||
instance = item; | ||
break; | ||
} | ||
|
||
if (!instance) | ||
{ | ||
instance = CreateInstance<T>(); | ||
var resourcesDir = Path.Combine(Application.dataPath, "Resources"); | ||
if (!Directory.Exists(resourcesDir)) Directory.CreateDirectory(resourcesDir); | ||
AssetDatabase.CreateAsset(instance, $"Assets/Resources/{typeof(T).Name}.asset"); | ||
AssetDatabase.SaveAssets(); | ||
} | ||
} | ||
|
||
if (!instance) throw new Exception($"Not found {typeof(T).Name}.asset ! Please create it !"); | ||
return instance; | ||
#else | ||
return GetResource(); | ||
#endif | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Build Results of an ATL Project | ||
[Dd]ebugPS/ | ||
[Rr]eleasePS/ | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
# NUNIT | ||
*.VisualState.xml | ||
TestResult.xml | ||
|
||
# User-specific files (MonoDevelop/Xamarin Studio) | ||
*.userprefs | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
[Rr]eleases/ | ||
[Xx]64/ | ||
[Xx]86/ | ||
[Bb]uild/ | ||
[Bb]ld/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
||
*_i.c | ||
*_p.c | ||
*_i.h | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.tmp_proj | ||
*.log | ||
*.vspscc | ||
*.vssscc | ||
.builds | ||
*.pidb | ||
*.svclog | ||
*.scc | ||
|
||
|
||
# NuGet Packages | ||
*.nupkg | ||
# The packages folder can be ignored because of Package Restore | ||
**/packages/* | ||
# except build/, which is used as an MSBuild target. | ||
!**/packages/build/ | ||
# Uncomment if necessary however generally it will be regenerated when needed | ||
#!**/packages/repositories.config | ||
# NuGet v3's project.json files produces more ignoreable files | ||
*.nuget.props | ||
*.nuget.targets | ||
|
||
# Visual Studio cache files | ||
# files ending in .cache can be ignored | ||
*.[Cc]ache | ||
# but keep track of directories ending in .cache | ||
!*.[Cc]ache/ | ||
|
||
# FAKE - F# Make | ||
.fake/ |