Hello.
I am trying to make a ValueInput use a struct and show a custom inspector – pretty much just like how a Vector3 is displayed:
In ValueInput, there is a SupportsDefaultValue method that seems to control if an inspector will show. It matches against a set of types:
private static readonly HashSet<Type> typesWithDefaultValues = new HashSet<Type>()
{
typeof(Vector2),
typeof(Vector3),
typeof(Vector4),
typeof(Color),
typeof(AnimationCurve),
typeof(Rect),
typeof(Ray),
typeof(Ray2D),
typeof(Type),
#if PACKAGE_INPUT_SYSTEM_EXISTS
typeof(UnityEngine.InputSystem.InputAction),
#endif
};
public static bool SupportsDefaultValue(Type type)
{
return
typesWithDefaultValues.Contains(type) ||
typesWithDefaultValues.Contains(Nullable.GetUnderlyingType(type)) ||
type.IsBasic() ||
typeof(UnityObject).IsAssignableFrom(type);
}
If I use a struct, then the inspector will not show:
public struct LampIdValue
{
public string id;
public int value;
public static readonly LampIdValue Empty = new LampIdValue { id = string.Empty, value = 0 };
}
.
.
.
var lampIdValue = ValueInput<LampIdValue>("Lamp ID " + (i + 1), LampIdValue.Empty);
So, the only way I can get the inspector to show is to make the ValueInput use a UnityObject:
[Serializable]
public class LampIdValue : UnityObject
{
public string id;
public int value;
public static readonly LampIdValue Empty = new LampIdValue { id = string.Empty, value = 0 };
}
.
.
.
var lampIdValue = ValueInput<LampIdValue>("Lamp ID " + (i + 1), LampIdValue.Empty);
Now the problem is, whenever I restart Unity, (or make a code change), the data is lost:
Does anyone know why the data is not being preserved?