Efficient way to store Resource variables

Hello everyone,

I have a newbie question about what is the efficient way to store items from resources if I use them frequently in my project. For now, I store them inside a static class and call them whenever I need.

Or another way It comes to my mind is creating a mono-behaviour class as you can see below. But with this method, I have to reference the configuration class whenever I need to use any member of the config file.

First Image that I use static class:

Second Image with monobehaviour:

I’m a big fan of oldskool simple. The resource itself IS a file on disk, it IS a static resource, so I just don’t see the argument for why I would ever access it with anything except a static.

Almost all my games have a file called LAZY.cs which just contains sheets of little bits and bobs necessary all throughout the game.

If I went “The Unity Way™” strictly, I would need to make sure that if I changed these, they got changed in all places, and honestly I just can’t be arsed to bother. If a game reached a size / scale that it was required, then I would just refactor.

I didn’t get into game making because I enjoy manipulating and managing resources. Every millisecond I spend hassling with this background crud is a minute I am not enjoying making games. :slight_smile:

using UnityEngine;
using System.Collections;

// @kurtdekker - static resource linkages

public static partial class LAZY
{
    private static Texture2D _button_circular_1;
    public static Texture2D button_circular_1
    {
        get
        {
            if (!_button_circular_1)
            {
                _button_circular_1 = Resources.Load<Texture2D>(
                    "Textures/uibuttons/20130208_directional_blank");
            }
            return _button_circular_1;
        }
    }

...

Anyone who needs it can get at it with:

DrawTexture( rect, LAZY.button_circular_1);

I also usually make my LAZY class a partial, so I can have different “groupings” of stuff:

8938311--1225899--Screen Shot 2023-04-10 at 7.24.43 AM.png

1 Like