diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..5674283 --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5beddd043c2294c079ee91a530ecdf2e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef b/Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef new file mode 100644 index 0000000..49aa63e --- /dev/null +++ b/Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef @@ -0,0 +1,15 @@ +{ + "name": "Skibitsky.Unity.StaticAssetLoader.Editor", + "references": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef.meta b/Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef.meta new file mode 100644 index 0000000..aafa1bb --- /dev/null +++ b/Editor/Skibitsky.Unity.StaticAssetLoader.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 6de25f29c53094588aa0f31d848e9eba +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/StaticAssetLoader.cs b/Editor/StaticAssetLoader.cs new file mode 100644 index 0000000..05c816f --- /dev/null +++ b/Editor/StaticAssetLoader.cs @@ -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 + { + /// + /// Load first asset of specified type + /// + public static T LoadAsset() where T : Object + { + var array = LoadAssetArray().ToArray(); + return array.Length > 0 ? LoadAssetArray().First() : null; + } + + /// + /// Load all assets of specified type + /// + public static IEnumerable LoadAssetArray() where T : Object + { + var assetCandidates = AssetDatabase.FindAssets($"t:{typeof(T)}"); + return assetCandidates + .Select(AssetDatabase.GUIDToAssetPath) + .Select(AssetDatabase.LoadAssetAtPath); + } + } +} + diff --git a/Editor/StaticAssetLoader.cs.meta b/Editor/StaticAssetLoader.cs.meta new file mode 100644 index 0000000..b3da089 --- /dev/null +++ b/Editor/StaticAssetLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 84be8f1d030824add9beabe14bc647dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md new file mode 100644 index 0000000..84ae5c4 --- /dev/null +++ b/README.md @@ -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(); + } +} +``` + +## 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": "..." + } + } + diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..d6f1385 --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d1f59d5ab14404caf8323193e4962652 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..f2e2716 --- /dev/null +++ b/package.json @@ -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": { + } +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..968ea82 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d78326ad65f1d44dba25357b3eec8ac3 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: