-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 8c0da5d
Showing
9 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
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,15 @@ | ||
{ | ||
"name": "Skibitsky.Unity.StaticAssetLoader.Editor", | ||
"references": [], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
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,31 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEditor; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace Skibitsky.Unity.Editor | ||
{ | ||
public static class StaticAssetLoader | ||
{ | ||
/// <summary> | ||
/// Load first asset of specified type | ||
/// </summary> | ||
public static T LoadAsset<T>() where T : Object | ||
{ | ||
var array = LoadAssetArray<T>().ToArray(); | ||
return array.Length > 0 ? LoadAssetArray<T>().First() : null; | ||
} | ||
|
||
/// <summary> | ||
/// Load all assets of specified type | ||
/// </summary> | ||
public static IEnumerable<T> LoadAssetArray<T>() where T : Object | ||
{ | ||
var assetCandidates = AssetDatabase.FindAssets($"t:{typeof(T)}"); | ||
return assetCandidates | ||
.Select(AssetDatabase.GUIDToAssetPath) | ||
.Select(AssetDatabase.LoadAssetAtPath<T>); | ||
} | ||
} | ||
} | ||
|
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,47 @@ | ||
# Static Asset Loader | ||
|
||
> Load asset from any project directory by type | ||
Very useful for loading configuration files of editor tools. | ||
|
||
## Usage | ||
|
||
```csharp | ||
public class MyEditorWindow : EditorWindow | ||
{ | ||
private MyScriptableObject LoadConfiguration() | ||
{ | ||
return StaticAssetLoader.LoadAsset<MyScriptableObject>(); | ||
} | ||
} | ||
``` | ||
|
||
## Installation | ||
|
||
### Install via OpenUPM | ||
|
||
The package is available on the [openupm registry](https://openupm.com). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli). | ||
|
||
``` | ||
openupm add com.skibitsky.static-asset-loader | ||
``` | ||
|
||
### Install via Git URL | ||
|
||
Open *Packages/manifest.json* with your favorite text editor. Add the following line to the dependencies block. | ||
|
||
{ | ||
"dependencies": { | ||
"com.skibitsky.static-asset-loader": "https://github.com/skibitsky/static-asset-loader.git" | ||
} | ||
} | ||
|
||
Notice: Unity Package Manager records the current commit to a lock entry of the *manifest.json*. To update to the latest version, change the hash value manually or remove the lock entry to resolve the package. | ||
|
||
"lock": { | ||
"com.skibitsky.static-asset-loader": { | ||
"revision": "master", | ||
"hash": "..." | ||
} | ||
} | ||
|
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,16 @@ | ||
{ | ||
"name": "com.skibitsky.static-asset-loader", | ||
"version": "1.0.0", | ||
"displayName": "Static Asset Loader", | ||
"description": "Load asset from any project directory by type", | ||
"repository": "skibitsky/static-asset-loader", | ||
"author": { | ||
"name": "Gleb Skibitsky", | ||
"email": "[email protected]", | ||
"url": "https://skibitsky.com" | ||
}, | ||
"unity": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.