From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/ReloadTigger.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 GameCode/ReloadTigger.cs (limited to 'GameCode/ReloadTigger.cs') diff --git a/GameCode/ReloadTigger.cs b/GameCode/ReloadTigger.cs new file mode 100644 index 0000000..3a4c093 --- /dev/null +++ b/GameCode/ReloadTigger.cs @@ -0,0 +1,40 @@ +using System; +using UnityEngine; +using UnityEngine.Events; + +public class ReloadTigger : MonoBehaviour +{ + public UnityEvent reloadDoneEvent; + + public UnityEvent outOfAmmoEvent; + + private void Start() + { + CharacterStatModifiers componentInParent = GetComponentInParent(); + componentInParent.OnReloadDoneAction = (Action)Delegate.Combine(componentInParent.OnReloadDoneAction, new Action(OnReloadDone)); + CharacterStatModifiers componentInParent2 = GetComponentInParent(); + componentInParent2.OutOfAmmpAction = (Action)Delegate.Combine(componentInParent2.OutOfAmmpAction, new Action(OnOutOfAmmo)); + } + + private void OnDestroy() + { + CharacterStatModifiers componentInParent = GetComponentInParent(); + componentInParent.OnReloadDoneAction = (Action)Delegate.Remove(componentInParent.OnReloadDoneAction, new Action(OnReloadDone)); + CharacterStatModifiers componentInParent2 = GetComponentInParent(); + componentInParent2.OutOfAmmpAction = (Action)Delegate.Remove(componentInParent2.OutOfAmmpAction, new Action(OnOutOfAmmo)); + } + + private void OnReloadDone(int bulletsReloaded) + { + reloadDoneEvent.Invoke(); + } + + private void OnOutOfAmmo(int bulletsReloaded) + { + outOfAmmoEvent.Invoke(); + } + + private void Update() + { + } +} -- cgit v1.1-26-g67d0