2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.1 KiB

5 years ago
  1. using Unity.FPS.Game;
  2. using UnityEngine;
  3. namespace Unity.FPS.Gameplay
  4. {
  5. [RequireComponent(typeof(WeaponController))]
  6. public class WeaponFuelCellHandler : MonoBehaviour
  7. {
  8. [Tooltip("Retract All Fuel Cells Simultaneously")]
  9. public bool SimultaneousFuelCellsUsage = false;
  10. [Tooltip("List of GameObjects representing the fuel cells on the weapon")]
  11. public GameObject[] FuelCells;
  12. [Tooltip("Cell local position when used")]
  13. public Vector3 FuelCellUsedPosition;
  14. [Tooltip("Cell local position before use")]
  15. public Vector3 FuelCellUnusedPosition = new Vector3(0f, -0.1f, 0f);
  16. WeaponController m_Weapon;
  17. bool[] m_FuelCellsCooled;
  18. void Start()
  19. {
  20. m_Weapon = GetComponent<WeaponController>();
  21. DebugUtility.HandleErrorIfNullGetComponent<WeaponController, WeaponFuelCellHandler>(m_Weapon, this,
  22. gameObject);
  23. m_FuelCellsCooled = new bool[FuelCells.Length];
  24. for (int i = 0; i < m_FuelCellsCooled.Length; i++)
  25. {
  26. m_FuelCellsCooled[i] = true;
  27. }
  28. }
  29. void Update()
  30. {
  31. if (SimultaneousFuelCellsUsage)
  32. {
  33. for (int i = 0; i < FuelCells.Length; i++)
  34. {
  35. FuelCells[i].transform.localPosition = Vector3.Lerp(FuelCellUsedPosition, FuelCellUnusedPosition,
  36. m_Weapon.CurrentAmmoRatio);
  37. }
  38. }
  39. else
  40. {
  41. // TODO: needs simplification
  42. for (int i = 0; i < FuelCells.Length; i++)
  43. {
  44. float length = FuelCells.Length;
  45. float lim1 = i / length;
  46. float lim2 = (i + 1) / length;
  47. float value = Mathf.InverseLerp(lim1, lim2, m_Weapon.CurrentAmmoRatio);
  48. value = Mathf.Clamp01(value);
  49. FuelCells[i].transform.localPosition =
  50. Vector3.Lerp(FuelCellUsedPosition, FuelCellUnusedPosition, value);
  51. }
  52. }
  53. }
  54. }
  55. }