This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from techno-dwarf-works/dev
Version: 1.5.1
- Loading branch information
Showing
4 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
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
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,54 @@ | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Better.Extensions.Runtime | ||
{ | ||
public static class ScriptableObjectUtility | ||
{ | ||
#if UNITY_EDITOR | ||
public static T CreateScriptableObjectAsset<T>(string path) | ||
where T : ScriptableObject | ||
{ | ||
const string assetsPath = AssetDatabaseUtility.AssetsPath; | ||
const string assetExtension = AssetDatabaseUtility.AssetExtension; | ||
|
||
var lastFolder = Path.GetDirectoryName(path); | ||
lastFolder ??= string.Empty; | ||
if (lastFolder.StartsWith(assetsPath)) | ||
{ | ||
lastFolder = lastFolder.Remove(0, assetsPath.Length); | ||
} | ||
|
||
var absolutePath = Path.Combine(Application.dataPath, lastFolder); | ||
if (!Directory.Exists(absolutePath)) | ||
{ | ||
Directory.CreateDirectory(absolutePath); | ||
AssetDatabase.Refresh(ImportAssetOptions.Default); | ||
} | ||
|
||
if (!path.StartsWith(assetsPath)) | ||
{ | ||
path = Path.Combine(assetsPath, path); | ||
} | ||
|
||
if (!path.EndsWith(assetExtension)) | ||
{ | ||
var name = typeof(T).Name; | ||
path = Path.Combine(path, $"{name}{assetExtension}"); | ||
} | ||
|
||
var asset = ScriptableObject.CreateInstance<T>(); | ||
AssetDatabase.CreateAsset(asset, path); | ||
return asset; | ||
} | ||
|
||
public static T CreateScriptableObjectAsset<T>(params string[] pathParts) | ||
where T : ScriptableObject | ||
{ | ||
var path = Path.Combine(pathParts); | ||
return CreateScriptableObjectAsset<T>(path: path); | ||
} | ||
#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