Skip to content

Latest commit

 

History

History
59 lines (51 loc) · 2.01 KB

File metadata and controls

59 lines (51 loc) · 2.01 KB

Simple Resource Loader

ResourceLoader scans folders and all types of resources in Resources folder and then generates a C# script that contains structs and enums based on it.

With this, you can load resources simply by calling the ResourceLoader after a single drag'n drop into your Resources folder:

Instantiate(ResourceLoader.GetResource<GameObject>(Prefabs.UI.SpawnButton_1));
SetMaterial(ResourceLoader.GetResource<Material>(Materials.Tree_1));

This is designed specifically for my simple projects.

  • Compared to Asset Bundle or Addressable, this is more suitable for personal learning projects.
  • I made this in order to streamline the process of loading assets.
  • You can see the whole code from my RTS project.

How To Use

  1. Place any resources you want to access at runtime through ResourceLoader.cs into your Resources folder.
  2. Open the editor window(Window -> Custom Asset Window) and drag'n drop your script that you want to add enums to.

    Image

  1. Based on your folder structure, After clicking Save Button in the editor window, your script will automatically be edited with corresponding enums inside.
  2. Now you can load your resources by calling ResourceLoader.GetResource<T>(Enum enumMember);

Example

Image would look like this:
// This script's automatically generated by EnumGenerator.cs
namespace CustomResourceManagement
{
  public enum Materials{
    Tree_1,
    Tree_2,
  }
  public struct Prefabs{
    public struct Playable{
      public enum Unit{
        Wizard,
        Gladiator,
        Dragon,
      }
  }
    public enum UI{
      SpawnButton_1,
    }
  }
  public struct Textures{
    public enum UI{
      Health,
    }
  }
}