GameAssistUI.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using DG.Tweening;
  6. public class GameAssistUI : MonoBehaviour
  7. {
  8. [SerializeField] Material outlight;
  9. [SerializeField] Text text1;
  10. [SerializeField] Text text2;
  11. public static GameAssistUI ins;
  12. void Start()
  13. {
  14. ins = this;
  15. this.transform.Find("Button1").GetComponent<Button>().onClick.AddListener(delegate(){
  16. GameRuleView.Create();
  17. });
  18. Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
  19. Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
  20. btnScaleAim.onClick.AddListener(delegate(){
  21. if (btnScaleAim.GetComponentInChildren<Image>().material == outlight) {
  22. btnScaleAim.GetComponentInChildren<Image>().material = null;
  23. closeScaleAim();
  24. } else {
  25. if (openScaleAim()) {
  26. btnScaleAim.GetComponentInChildren<Image>().material = outlight;
  27. }
  28. }
  29. });
  30. btnScaleShoot.onClick.AddListener(delegate(){
  31. if (btnScaleShoot.GetComponentInChildren<Image>().material == outlight) {
  32. btnScaleShoot.GetComponentInChildren<Image>().material = null;
  33. closeScaleShoot();
  34. } else {
  35. if (openScaleShoot()) {
  36. btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
  37. }
  38. }
  39. });
  40. }
  41. Transform scope = null;
  42. float[] scaleAimFieldOfViews = {30, 20, 12, 6, 3};
  43. float[] scaleAimArmBowZs = {-0.813f, -0.799f, -0.77f, -0.695f, -0.55f};
  44. float[] scaleAimScopeScales = {150, 98, 58, 29, 14.5f};
  45. Sequence seq1 = null;
  46. bool openScaleAim()
  47. {
  48. int scaleValue = GetPropScaleAimValue();
  49. if (scaleValue > 0)
  50. {
  51. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  52. bowCamera.banCameraFieldOfView = true;
  53. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 500);
  54. bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
  55. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  56. localPosition.z = -2;
  57. ArmBow.ins.transform.localPosition = localPosition;
  58. scope = bowCamera.transform.Find("Scope");
  59. float scopeScale = scaleAimScopeScales[scaleValue - 1];
  60. scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
  61. return true;
  62. }
  63. if (seq1 != null && !seq1.IsComplete()) {
  64. seq1.Complete();
  65. }
  66. seq1 = DOTween.Sequence();
  67. seq1.Append(text1.DOFade(1, 0.5f));
  68. seq1.AppendInterval(2);
  69. seq1.Append(text1.DOFade(0, 0.5f));
  70. return false;
  71. }
  72. void closeScaleAim()
  73. {
  74. BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
  75. bowCamera.banCameraFieldOfView = false;
  76. CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(260, 260);
  77. Vector3 localPosition = ArmBow.ins.transform.localPosition;
  78. localPosition.z = -0.1f;
  79. ArmBow.ins.transform.localPosition = localPosition;
  80. scope.localScale = new Vector3(0, 0, 0);
  81. scope = null;
  82. }
  83. int GetPropScaleAimValue()
  84. {
  85. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  86. foreach (var prop in props)
  87. {
  88. if (prop.config.type == 1) {
  89. PropScaleAim config = prop.config as PropScaleAim;
  90. return config.scaleValue;
  91. }
  92. }
  93. return 0;
  94. }
  95. public int shootScaleValue = 0;
  96. Sequence seq2 = null;
  97. bool openScaleShoot()
  98. {
  99. List<PropInfo> props = PropMgr.ins.ListForEquipped();
  100. foreach (var prop in props)
  101. {
  102. if (prop.config.type == 2) {
  103. PropScaleShoot config = prop.config as PropScaleShoot;
  104. shootScaleValue = config.scaleValue;
  105. return true;
  106. }
  107. }
  108. if (seq2 != null && !seq2.IsComplete()) {
  109. seq2.Complete();
  110. }
  111. seq2 = DOTween.Sequence();
  112. seq2.Append(text2.DOFade(1, 0.5f));
  113. seq2.AppendInterval(2);
  114. seq2.Append(text2.DOFade(0, 0.5f));
  115. return false;
  116. }
  117. void closeScaleShoot()
  118. {
  119. shootScaleValue = 0;
  120. }
  121. }