I have the following class
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PixelSystem
{
public GameObject pixelPrefab;
public Texture2D[] style;
public List<Chunk> chunks;
public GameObject mGameObject;
public PixelSystem(GameObject _mGameObject)
{
mGameObject = _mGameObject;
chunks = new List<Chunk>();
}
}
Chunk and Pixel are structs but I don't think they are relevant.
I would like pixelPrefab and style to be serialized but cannot seem to be able to make that work. This script is not attatched to a GameObject.
I have looked into getting the assets at runtime with Resources or Addressables but I would like to be able to set these fields from the editor.
I have tried making the class inherit from MonoBehaviour and having [SerializeField] public GameObject pixelPrefab; and [SerializeField] public Texture2D[] style;, but the result of this is that pixelPrefab is settable from the editor but instead of showing style it shows mGameObject, for some reason... ¯\_(ツ)_/¯
Edit: Turns out that the [SerializeFields] do nothing here, the result is the same without them.
I've also tried puting [System.Serializable] before the class, but as far as I can tell this does nothing at all.
Someone plz help.
Edit:
Due to some misunerstandings I would like to clarify a few things:
- I have the prefab asset already, it is in my assets folder not in my scene, creating the assets is not the problem.
pixelPrefabwould work fine as astaticproperty, however,stylewould not.- Style only needs serializing for a default value and so is not a priority.
- This code is very incomplete, the constructor is incomplete, I want an answer to this qusetion before I spend time writing code that may be unusable.
- I want to select the assets in the editior
- I do not want to have a function that must be called before the classes are used, so that the assets are loaded
- I do not want to load the assets each time they are referenced, so no
get {load();}
This is what I want to see in the editor when I select my script:

And this is the closest thing to what I want so far:

Which I get by setting the class to inherit from MonoBehaviour, I'd rather not inherit from anything, and idk if you are meant to have MonoBehaviour classes that aren't attatched to gameObjects, but if this is necessary then so be it.