Hello. I have a Palette class that is generic and inherits from ScriptableObject. This class has a field “elements” and it doesn’t want to be displayed in the inspector in any way. I tried different methods but it didn’t work. Do you have any idea why this is happening?
[System.Serializable]
public abstract class Palette<T> : ScriptableObject where T : System.Enum
{
[SerializeField]
private Data[] elements;
private void OnEnable()
{
Fill();
}
private void OnValidate()
{
Fill();
}
private void Fill()
{
string[] enumsList = System.Enum.GetNames(typeof(T));
List<Data> tempElements = new List<Data>();
bool isFound;
for (int i = 0; i < enumsList.Length; i++)
{
isFound = false;
if (elements != null)
{
for (int j = 0; j < elements.Length; j++)
{
if (enumsList[i] == System.Enum.GetName(typeof(T), elements[j].type))
{
isFound = true;
tempElements.Add(elements[j]);
break;
}
}
}
if (!isFound)
{
tempElements.Add(new Data((T)System.Enum.Parse(typeof(T), enumsList[i])));
}
}
elements = tempElements.ToArray();
}
public Color GetMainColor(T targetType)
{
for (int i = 0; i < elements.Length; i++)
{
if (elements[i].type.Equals(targetType))
return elements[i].mainColor;
}
return default;
}
public Color GetExtraColor(T targetType)
{
for (int i = 0; i < elements.Length; i++)
{
if (elements[i].type.Equals(targetType))
return elements[i].extraColor;
}
return default;
}
// Data
[System.Serializable]
public struct Data
{
[ReadOnly]
public T type;
public Color mainColor;
public Color extraColor;
public Data(T type)
{
this.type = type;
mainColor = Color.black;
extraColor = Color.black;
}
}
}
[CreateAssetMenu(fileName = "PortalColorPalette", menuName = "ScriptableObjects/PortalColorPalette", order = 1)]
[System.Serializable]
public class PortalColorPalette : Palette<PortalType>
{
}
