So, here is my problem.
I have parent class called CameraBehaviour
derived from MonoBehaviour
public class CameraBehaviour : MonoBehaviour
{
public MinMax CameraViewRange;
private Single CalculateViewRange() { ... }
}
and have two class ActionCamera2D
and ActionCamera3D
derived from CameraBehaviour
public class ActionCamera2D : CameraBehaviour
{
[MinMaxRange (2f, 5f)]
public new MinMax CameraViewRange = new MinMax(2f, 5f);
}
public class ActionCamera3D : CameraBehaviour
{
[MinMaxRange(20f, 50f)]
public new MinMax CameraViewRange = new MinMax(20f, 50f);
}
as you can see, both the script has CameraViewRange
with new
keyword and has different MinMaxRange
attribute attached on each script, so the limit is will be vary between this script but still using the same CalculateViewRange
calculation as the parent script.
But it turns out to be not possible, in Unity at least, raising an error:
The same field name is serialized multiple times in the class or its parent class.
This is not supported: Base(MonoBehaviour) CameraViewRange
-
MinMaxRange
is a custom written attribute for property drawer. -
MinMax
is a custom struct that store min and max value.
- So, how can I overcome / deal with this problem ?
- Is my code pattern here is wrong ?
- Is there any workaround or better solutions for this ?
- Or is this the C# and Unity limitations ? ( but I’m not sure if it is )
thanks