├── Editor.meta
├── Editor
├── Skibitsky.Unity.StaticAssetLoader.Editor.asmdef
├── Skibitsky.Unity.StaticAssetLoader.Editor.asmdef.meta
├── StaticAssetLoader.cs
└── StaticAssetLoader.cs.meta
├── README.md
├── README.md.meta
├── package.json
└── package.json.meta
/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5beddd043c2294c079ee91a530ecdf2e
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Skibitsky.Unity.StaticAssetLoader.Editor",
3 | "references": [],
4 | "includePlatforms": [
5 | "Editor"
6 | ],
7 | "excludePlatforms": [],
8 | "allowUnsafeCode": false,
9 | "overrideReferences": false,
10 | "precompiledReferences": [],
11 | "autoReferenced": true,
12 | "defineConstraints": [],
13 | "versionDefines": [],
14 | "noEngineReferences": false
15 | }
--------------------------------------------------------------------------------
/Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6de25f29c53094588aa0f31d848e9eba
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor/StaticAssetLoader.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using UnityEditor;
4 | using Object = UnityEngine.Object;
5 |
6 | namespace Skibitsky.Unity.Editor
7 | {
8 | public static class StaticAssetLoader
9 | {
10 | ///
11 | /// Load first asset of specified type
12 | ///
13 | public static T LoadAsset() where T : Object
14 | {
15 | var array = LoadAssetArray().ToArray();
16 | return array.Length > 0 ? LoadAssetArray().First() : null;
17 | }
18 |
19 | ///
20 | /// Load all assets of specified type
21 | ///
22 | public static IEnumerable LoadAssetArray() where T : Object
23 | {
24 | var assetCandidates = AssetDatabase.FindAssets($"t:{typeof(T)}");
25 | return assetCandidates
26 | .Select(AssetDatabase.GUIDToAssetPath)
27 | .Select(AssetDatabase.LoadAssetAtPath);
28 | }
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/Editor/StaticAssetLoader.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 84be8f1d030824add9beabe14bc647dc
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Static Asset Loader [](https://openupm.com/packages/com.skibitsky.static-asset-loader/)
2 |
3 | > Load asset from any project directory by type
4 |
5 | Very useful for loading configuration files of editor tools.
6 |
7 | ## Usage
8 |
9 | ```csharp
10 | public class MyEditorWindow : EditorWindow
11 | {
12 | private static MyScriptableObject LoadConfiguration()
13 | {
14 | return StaticAssetLoader.LoadAsset();
15 | }
16 | }
17 | ```
18 |
19 | ## Installation
20 |
21 | ### Install via OpenUPM
22 |
23 | 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).
24 |
25 | ```
26 | openupm add com.skibitsky.static-asset-loader
27 | ```
28 |
29 | ### Install via Git URL
30 |
31 | Open *Packages/manifest.json* with your favorite text editor. Add the following line to the dependencies block.
32 |
33 | {
34 | "dependencies": {
35 | "com.skibitsky.static-asset-loader": "https://github.com/skibitsky/static-asset-loader.git"
36 | }
37 | }
38 |
39 | 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.
40 |
41 | "lock": {
42 | "com.skibitsky.static-asset-loader": {
43 | "revision": "master",
44 | "hash": "..."
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d1f59d5ab14404caf8323193e4962652
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.skibitsky.static-asset-loader",
3 | "version": "1.0.0",
4 | "displayName": "Static Asset Loader",
5 | "description": "Load asset from any project directory by type",
6 | "repository": "skibitsky/static-asset-loader",
7 | "author": {
8 | "name": "Gleb Skibitsky",
9 | "email": "gleb@skibitsky.com",
10 | "url": "https://skibitsky.com"
11 | },
12 | "unity": "",
13 | "license": "MIT",
14 | "dependencies": {
15 | }
16 | }
--------------------------------------------------------------------------------
/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d78326ad65f1d44dba25357b3eec8ac3
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------