I’ve created a bunch of palettes in the editor, but I have a some objects that change color based on certain conditions. Can I reference my editor palettes in a script? I’m trying to just have one source of all my colors.
I don’t think you can reference the editor swatches (at least not easily).
Youd be better off creating your own colour pallette in a script using a list of colours that you assign in your inspector.
This post on stackexchange has a pretty decent solution:
Extremely newb question - how do I make an Entry using that solution? I’m used to the serialized field coming up in the object or using scriptable objects to create an asset from the menu. I tried searching for examples what system.serializable does but can’t figure it out.
the [System.Serializable] tag will expose all of the public properties of the Entry class in the inspector, so when you add an entry you should be able to choose the colour and give it a name.
You have to change the size of the colors array in the inspector from 0 to however many colour swatches you have before it will let you pick the colours and name them.
I haven’t actually used a scriptable object before… but I assume you can just attach it to a gameObject in your scene and then you can reference that from your other scripts? Sorry I didn’t realise that post was using scriptable objects. You could change it to a normal MonoBehaviour or whatever you’re used to working with.
Another use of [System.Serializable] is that it allows you to use the FileStream class to save and load objects into/from text files at runtime.