// Alot of the time it will be sensible to have the same object/component implementing both the characters perception management (awareness state) // and the perception event invoker, because the thing managing what the character is aware of is the best position to know when to invoke certain // events relating to those very perceptions. However, those things are still logically distinct in regard to the USERS of those operations, namely, // some clients will care about controlling the parameters of the awareness logic, while others will only care about recieving updates on what the // character is currently awareof/percieving. Consequently, these are two distinct interfaces! // Use unity engine to aquire all the dependencies needed for a character to operate. They are mandated by this script to be attached to the gameobject. void Awake() { object[] temp = GetComponents <ICombatAi>(); if (temp.Length > 1) { throw new System.Exception("Character gameobject had more than one ICombatAi component attached! This is not allowed"); } combatAi = (ICombatAi)temp[0]; temp = GetComponents <IHealthSystem>(); if (temp.Length > 1) { throw new System.Exception("Character gameobject had more than one IHealthSystem component attached! This is not allowed"); } healthSystem = (IHealthSystem)temp[0]; temp = GetComponents <IPerceptionEventInvoker>(); if (temp.Length > 1) { throw new System.Exception("Character gameobject had more than one IPerceptionEventInvoker component attached! This is not allowed"); } perceptionEventInvoker = (IPerceptionEventInvoker)temp[0]; temp = GetComponents <ICharacterAwarenessState>(); if (temp.Length > 1) { throw new System.Exception("Character gameobject had more than one ICharacterAwarenessState component attached! This is not allowed"); } characterAwarenessState = (ICharacterAwarenessState)temp[0]; }
private void RegisterListenersToMainCharacter(ICharacter ch) { IPerceptionEventInvoker p = ch.RequestPerceptionEventListeningRights(); // Register our handler delegates. p.EnemyEngagedEvent += MainCharacterEngagedEnemy; p.EnemyDisengagedEvent += MainCharacterDisengagedEnemy; p.EnemySpottedEvent += MainCharacterSpottedEnemy; p.EnemyLostEvent += MainCharacterLostEnemy; }