Greets community,
I wanted to pass a class/struct (i.e. agentLocomotion) of Mob to a class/struct that is composed by Mob (chaseLocomotion) by OnValidate of Editor, so that agentLocomotion of Mob is directly accessible in ChaseLocomotion. Same goes for NavMeshAgent,Transform (even MonoBehaviours) of Mob…
The classes:
public class Mob : MonoBehaviour
{
[SerializeField] protected AgentLocomotion _agentLocomotion;
public AgentLocomotion agentLocomotion => _agentLocomotion;
[SerializeField] protected ChaseLocomotion _chaseLocomotion;
public ChaseLocomotion chaseLocomotion => _chaseLocomotion;
...
#if UNITY_EDITOR
public override void Validate()
{
_chaseLocomotion.Validate(this);
}
#endif
...
}
public class ChaseLocomotion
{
[SerializeField, HideInInspector] Transform transform;
[SerializeField, HideInInspector] Mob entity;
[SerializeField, HideInInspector] NavMeshAgent agent;
[SerializeField, HideInInspector] AgentLocomotion agentLocomotion;
public ChaseLocomotion(Mob newEntity = null, NavMeshAgent newAgent = null, AgentLocomotion newAgentLocomotion = null, Transform newTransform = null)
{ // ONLY if struct
entity = newEntity;
agent = newAgent;
agentLocomotion = newAgentLocomotion;
transform = newTransform;
}
#if UNITY_EDITOR
public void Validate(Mob newEntity)
{
entity = newEntity;
transform = entity.transform;
agent = entity.Agent;
agentLocomotion = entity.agentLocomotion;
}
#endif
}
public class AgentLocomotion { ... }
I am not sure if this can be passed by constructor or like I did by an additional function.