97 lines
2.6 KiB
C#
97 lines
2.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Invector;
|
|
using Invector.vCharacterController.AI;
|
|
using Invector.vCharacterController.AI.FSMBehaviour;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
[RequireComponent(typeof(vMessageReceiver))]
|
|
[DisallowMultipleComponent]
|
|
public class EnemyCombatNotifier : MonoBehaviour
|
|
{
|
|
private static EnemyCombatNotifier currentTarget;
|
|
|
|
private vMessageReceiver m_messageReceiver;
|
|
private vControlAICombat m_AICombat;
|
|
private vFSMBehaviourController m_fsm;
|
|
|
|
[SerializeField] private GameObject targetIcon; // << Dodajemy tylko to
|
|
|
|
private void Start()
|
|
{
|
|
m_messageReceiver = GetComponent<vMessageReceiver>();
|
|
m_AICombat = GetComponent<vControlAICombat>();
|
|
m_fsm = GetComponent<vFSMBehaviourController>();
|
|
|
|
if (targetIcon)
|
|
targetIcon.SetActive(false); // << Na start ukrywamy ikonkê
|
|
|
|
m_messageReceiver.onReceiveMessage += (s, message) =>
|
|
{
|
|
if (s.Equals("Alert"))
|
|
{
|
|
OnCombat(); // Tylko kiedy Alert
|
|
}
|
|
else if (s.Equals("Flee") || s.Equals("Patrol"))
|
|
{
|
|
OnCombatEnd(); // Kiedy Patrol albo Flee
|
|
}
|
|
};
|
|
|
|
if (m_AICombat)
|
|
{
|
|
m_AICombat.onDead.AddListener(arg0 => { OnCombatEnd(); });
|
|
}
|
|
}
|
|
|
|
private void OnCombat()
|
|
{
|
|
if (currentTarget != null && currentTarget != this)
|
|
{
|
|
currentTarget.DisableTargetIcon(); // Zgas stary target
|
|
}
|
|
|
|
currentTarget = this;
|
|
EnableTargetIcon(); // Zapal siebie
|
|
|
|
if (GameStateManager.Instance)
|
|
{
|
|
GameStateManager.Instance.OnCombat(m_fsm);
|
|
}
|
|
}
|
|
|
|
private void OnCombatEnd()
|
|
{
|
|
if (currentTarget == this)
|
|
{
|
|
DisableTargetIcon(); // Zgas siebie
|
|
currentTarget = null;
|
|
}
|
|
|
|
if (GameStateManager.Instance)
|
|
{
|
|
GameStateManager.Instance.OnCombatEnd(m_fsm);
|
|
}
|
|
}
|
|
|
|
private void EnableTargetIcon()
|
|
{
|
|
if (targetIcon)
|
|
targetIcon.SetActive(true);
|
|
}
|
|
|
|
private void DisableTargetIcon()
|
|
{
|
|
if (targetIcon)
|
|
targetIcon.SetActive(false);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
OnCombatEnd(); // Kiedy przeciwnik znika
|
|
}
|
|
}
|
|
}
|