Skip to content

Commit

Permalink
✨ 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
xinansky committed Jun 20, 2024
1 parent 6f741c2 commit b831fe8
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitmodules

This file was deleted.

3 changes: 3 additions & 0 deletions Runtime/Tools/ScriptableObject.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions Runtime/Tools/ScriptableObject/ScriptableObjectExt.cs
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
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Tools/ScriptableObject/ScriptableObjectExt.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions Tools~/.gitignore
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/

0 comments on commit b831fe8

Please sign in to comment.