โ‰๏ธListen when an Mode starts or ends

You can use the Unity Events for the mode to let you know when a mode start or ends

Subscribe to Modes via Inspector

How to Listen to any Mode.

Use the global Unity Events On Mode Start and On Mode End

How to Listen to a specific Mode (e.g. Attack1)

On the Global Properties Section of every Mode you can Subscribe to the Unity Events On Enter | On Exit to listen when the Main Attack (Attack1) Starts or Ends.

How to listen to an Ability inside a Mode (E.g. Subscribe to Eat Action)

if you want to listen to an specific Ability (E.g. Eat) then you can use the Override Properties:

Set the Override Affect States Option Select NONE (that way the Ability will use the Global Affect parameters)

Subscribe to Modes via Script

How to Listen to any Mode.

void Awake()
{ 
   animal = GetComponent<MAnimal>(); 
}

void OnEnable()
{ 
    animal.OnModeStart.AddListener(StartMode); 
    animal.OnModeStart.AddListener(StartMode); 
}

void OnDisable()
{
    animal.OnModeStart.RemoveListener(StartMode);
    animal.OnModeStart.RemoveListener(StartMode);
}


void StartMode(int ModeID)
{
    //Your code Here
}

void EndMode(int ModeID)
{
    //Your code Here
}

How to Listen to a specific Mode (e.g. Action)

private MAnimal animal;
private Mode ActionMode;

void Awake()
{ 
    animal = GetComponent<MAnimal>(); 
    
    ActionMode = animal.Mode_Get(4);  //4 is the ID for Action
}

void OnEnable()
{   
    if (ActionMode != null)
    {
        ActionMode.GlobalProperties.OnEnter.AddListener(StartAction);
        ActionMode.GlobalProperties.OnExit.AddListener(EndAction);
    }
}

void OnDisable()
{
    if (ActionMode != null)
    {
        ActionMode.GlobalProperties.OnEnter.RemoveListener(StartAction);
        ActionMode.GlobalProperties.OnExit.RemoveListener(EndAction);
    }
}

void StartAction()
{
    //Your code Here
}

void EndAction()
{
    //Your code Here
}

How to listen to an Ability inside a Mode (E.g. Subscribe to Eat Action)

 private MAnimal animal;
 private Ability EatAbility;


void Start()
{
    animal = GetComponent<MAnimal>();          
    Mode ActionMode = animal.Mode_Get(4);         //4 is the ID for Action

    if (ActionMode != null)
    {
        EatAbility = ActionMode.Abilities.Find(ability => ability.Name == "Eat");
    }
}

void OnEnable()
{
    if (EatAbility != null)
    {
        EatAbility.OverrideProperties.OnEnter.AddListener(StartEat);
        EatAbility.OverrideProperties.OnExit.AddListener(EndEat);
    }
}

void OnDisable()
{
    if (EatAbility != null)
    {
        EatAbility.OverrideProperties.OnEnter.RemoveListener(StartEat);
        EatAbility.OverrideProperties.OnExit.RemoveListener(EndEat);
    }
}

void StartEat()
{
    //Your code Here
}

void EndEat()
{
    //Your code Here
}

Last updated