Skip to content

Commit

Permalink
Package created
Browse files Browse the repository at this point in the history
  • Loading branch information
skibitsky committed Jun 21, 2020
0 parents commit 8c0da5d
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Editor.meta

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

15 changes: 15 additions & 0 deletions Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef
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
}
7 changes: 7 additions & 0 deletions Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef.meta

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

31 changes: 31 additions & 0 deletions Editor/StaticAssetLoader.cs
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>);
}
}
}

11 changes: 11 additions & 0 deletions Editor/StaticAssetLoader.cs.meta

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

47 changes: 47 additions & 0 deletions README.md
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": "..."
}
}

7 changes: 7 additions & 0 deletions README.md.meta

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

16 changes: 16 additions & 0 deletions package.json
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": "gleb@skibitsky.com",
"url": "https://skibitsky.com"
},
"unity": "",
"license": "MIT",
"dependencies": {
}
}
7 changes: 7 additions & 0 deletions package.json.meta

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

0 comments on commit 8c0da5d

Please sign in to comment.