|
1 | | -# UnityResourceGenerator |
| 1 | +# Unity Resource Generator [](https://openupm.com/packages/com.autsoft.unityresourcegenerator/) [](https://github.com/AutSoft/UnityResourceGenerator/releases/latest) [](https://github.com/AutSoft/UnityResourceGenerator/actions/workflows/publish.yml) [](https://github.com/AutSoft/UnityResourceGenerator/actions/workflows/publish-to-gh-pages.yml) |
| 2 | + |
| 3 | +Automatically generate a helper class for `Resources.Load` in Unity with the press of a button. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +With this folder structure: |
| 8 | + |
| 9 | +``` |
| 10 | +Assets/ |
| 11 | +├─ Resources/ |
| 12 | +│ ├─ Coin.prefab |
| 13 | +│ ├─ Coin.mp3 |
| 14 | +├─ Scenes/ |
| 15 | +│ ├─ CoinRain.unity |
| 16 | +``` |
| 17 | + |
| 18 | +The following helper class is generated: |
| 19 | + |
| 20 | +```csharp |
| 21 | +using UnityEngine; |
| 22 | +using UnityEngine.SceneManagement; |
| 23 | + |
| 24 | +namespace Sample |
| 25 | +{ |
| 26 | + // ReSharper disable PartialTypeWithSinglePart |
| 27 | + public static partial class ResourcePaths |
| 28 | + { |
| 29 | + |
| 30 | + public static partial class Scenes |
| 31 | + { |
| 32 | + public const string CoinRain = "Scenes/CoinRain"; |
| 33 | + |
| 34 | + public static void LoadCoinRain(LoadSceneMode mode = LoadSceneMode.Single) => |
| 35 | + SceneManager.LoadScene(CoinRain, mode); |
| 36 | + |
| 37 | + public static AsyncOperation LoadAsyncCoinRain(LoadSceneMode mode = LoadSceneMode.Single) => |
| 38 | + SceneManager.LoadSceneAsync(CoinRain, mode); |
| 39 | + } |
| 40 | + |
| 41 | + public static partial class Prefabs |
| 42 | + { |
| 43 | + public const string Coin = "Coin"; |
| 44 | + public static GameObject LoadCube() => Resources.Load<GameObject>(Coin); |
| 45 | + } |
| 46 | + |
| 47 | + public static partial class AudioClips |
| 48 | + { |
| 49 | + public const string Coin = "Coin"; |
| 50 | + public static AudioClip LoadCoin() => Resources.Load<AudioClip>(Coin); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +## Installation |
| 57 | + |
| 58 | +Either use the `.unitypackage` provided in the releases or use OpenUPM |
| 59 | + |
| 60 | +``` |
| 61 | +openupm add com.autsoft.unityresourcegenerator |
| 62 | +``` |
| 63 | + |
| 64 | +## Documentation |
| 65 | + |
| 66 | +For the complete documentation, visit the [website](https://autsoft.github.io/UnityResourceGenerator/). |
0 commit comments