SetAimIK.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using RootMotion.FinalIK;
  5. using RootMotion.Demos;
  6. using KairoEngine.Core;
  7. using KairoEngine.Inventory;
  8. namespace KairoEngine.CharacterSystem
  9. {
  10. public class SetAimIK : MonoBehaviour
  11. {
  12. public Transform weaponAimIK;
  13. public CharacterController character;
  14. public AimController aimController;
  15. public AimIK aimIK;
  16. public LimbIK limbIK;
  17. public SecondHandOnGun secondHandOnGun;
  18. private bool isRealoding = false;
  19. void OnEnable()
  20. {
  21. GenericEvents.StartListening(character.unique_name + "-Reloading", Reloading);
  22. GenericEvents.StartListening(character.unique_name + "-ReloadDone", ReloadDone);
  23. }
  24. void OnDisable()
  25. {
  26. GenericEvents.StopListening(character.unique_name + "-Reloading", Reloading);
  27. GenericEvents.StopListening(character.unique_name + "-ReloadDone", ReloadDone);
  28. }
  29. void Update()
  30. {
  31. if(weaponAimIK == null)
  32. {
  33. if(character.HasEquipedItem() && isRealoding == false)
  34. {
  35. if(character.GetEquipedItem().item.category == ItemType.firearm)
  36. {
  37. Firearm firearm = character.GetEquipedGameObject().GetComponent<Firearm>();
  38. weaponAimIK = firearm.aim;
  39. aimIK.solver.transform = weaponAimIK;
  40. limbIK.solver.target = firearm.grip;
  41. aimIK.enabled = true;
  42. limbIK.enabled = true;
  43. return;
  44. }
  45. }
  46. aimIK.enabled = false;
  47. limbIK.enabled = false;
  48. }
  49. }
  50. private void Reloading()
  51. {
  52. //Debug.Log("Reloading");
  53. isRealoding = true;
  54. weaponAimIK = null;
  55. secondHandOnGun.enabled = false;
  56. }
  57. private void ReloadDone()
  58. {
  59. //Debug.Log("Reloading Done");
  60. isRealoding = false;
  61. if(secondHandOnGun == null) return;
  62. secondHandOnGun.enabled = true;
  63. }
  64. }
  65. }