Question by
Colin_Brilliant_Labs · 5 days ago ·
c#unity 2dunityeditorconstructor
Override constructor of list of classes when creating a new element from the inspector
I have a class that contains a list of another class and an enum.
public class CutsceneDialog
{
public List<MoveCharacterInCutscene> characterMovements = new List<MoveCharacterInCutscene>();
[Header("Relative - Move relative to current position")]
public PositionType positionType = PositionType.Relative;
}
The issue is that the MoveCharacterInCutscene class needs to know what the value for positionType is.
public class MoveCharacterPositions
{
//We need our constructor to get the positionType
MoveCharacterPositions(PositionType positionType)
{
this.positionType = positionType;
Debug.Log("got position type: " + positionType);
}
[Header("Insantly warp the player to their positions, rather than move them over time.")]
public bool instantWarp = false;
public Vector2 absolutePosition = Vector2.zero;
//Only display our relative position Vector2 if position is relative
[ConditionalField(true, "IsPositionRelative")]
public Vector2 relativePosition = Vector2.zero;
//Checks if our position is relative
public bool IsPositionRelative()
{
return positionType == PositionType.Relative ? true : false;
}
public PositionType positionType;
}
Is there a way that I can override the contructor method when created a new element in the list from the inspector? Or if there are any other ways to do this, please let me know :) Keep in mind that I can't create a custom inspector because the class doesn't inherit monobehaviour.
Comment
Your answer
Follow this Question
Related Questions
How to override constructor when creating a new element in a list from the inspector. 0 Answers
Value doesn't change in game when updated. 2 Answers
Help me with joystick setting 1 Answer
Unity Input Touch 0 Answers
Highscore not working 0 Answers