SHICameraController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using CIS;
  3. using DG.Tweening;
  4. using UnityEngine;
  5. public class SHICameraController : SingletonMonoBehaviourClass<SHICameraController>, ICameraController
  6. {
  7. private Transform HeroTrans
  8. {
  9. get
  10. {
  11. return SingletonMonoBehaviourClass<GameLogicMgr>.instance.playerController.Transform;
  12. }
  13. }
  14. private IPlayerController playerController
  15. {
  16. get
  17. {
  18. return SingletonMonoBehaviourClass<GameLogicMgr>.instance.playerController;
  19. }
  20. }
  21. private void Awake()
  22. {
  23. this.ScreenWidth = (float)Screen.width;
  24. this.ScreenHeight = (float)Screen.height;
  25. this.currentX = base.transform.localPosition.x;
  26. }
  27. public GameObject GetGO()
  28. {
  29. return base.gameObject;
  30. }
  31. public void FadeInMask(float time, float endValue, Action doneCallback)
  32. {
  33. this.mask.enabled = true;
  34. this.mask.color = new Color(this.mask.color.r, this.mask.color.g, this.mask.color.b, 0f);
  35. this.mask.DOFade(endValue, time).OnComplete(delegate
  36. {
  37. if (doneCallback != null)
  38. {
  39. doneCallback();
  40. }
  41. });
  42. }
  43. public void FadeOutMask(float time, float endValue, Action doneCallback)
  44. {
  45. this.mask.DOFade(endValue, time).OnComplete(delegate
  46. {
  47. if (doneCallback != null)
  48. {
  49. doneCallback();
  50. }
  51. this.mask.enabled = false;
  52. });
  53. }
  54. public void ZoomTo(Vector2 destPos, float size, float duration)
  55. {
  56. float orthographicSize = this.mainCam.orthographicSize;
  57. float z = base.transform.position.z;
  58. DOTween.To(delegate(float x)
  59. {
  60. this.mainCam.orthographicSize = x;
  61. }, orthographicSize, size, duration);
  62. base.transform.DOMove(new Vector3(destPos.x, destPos.y, z), duration, false);
  63. }
  64. public void SetSize(float size)
  65. {
  66. this.mainCam.orthographicSize = size;
  67. }
  68. public void EnableFollowPlayer(bool enable)
  69. {
  70. this.follow = enable;
  71. }
  72. public void SetTargetTrans(Transform trans)
  73. {
  74. this.targetTrans = trans;
  75. }
  76. public void ShakeCamera(float duration, float strenth, float vibration)
  77. {
  78. this.shakeCamera = true;
  79. Transform parent = base.transform.parent;
  80. parent.DOShakePosition(duration, strenth, (int)vibration, 90f, false, true).OnComplete(delegate
  81. {
  82. this.shakeCamera = false;
  83. });
  84. }
  85. public void ReloadLimitBorder(Transform up, Transform down, Transform left, Transform right)
  86. {
  87. this.leftLimitTrans = left;
  88. this.rightLimitTrans = right;
  89. this.DownLimitTrans = down;
  90. this.UpLimitTrans = up;
  91. this.leftLimit = this.leftLimitTrans.position.x;
  92. this.rightLimit = this.rightLimitTrans.position.x;
  93. this.downLimit = this.DownLimitTrans.position.y + this.ScreenHeight / 2f;
  94. this.upLimit = this.UpLimitTrans.position.y - this.ScreenHeight / 2f;
  95. }
  96. public void SetCurrentPos(float x, float y)
  97. {
  98. this.currentX = x;
  99. this.currentY = y;
  100. }
  101. private void Update()
  102. {
  103. if (this.targetTrans != null)
  104. {
  105. base.transform.position = new Vector3(this.targetTrans.position.x, this.targetTrans.position.y, base.transform.position.z);
  106. return;
  107. }
  108. if (!this.follow)
  109. {
  110. return;
  111. }
  112. Vector3 position = this.HeroTrans.position;
  113. float x = position.x;
  114. float y = position.y;
  115. float num = (this.playerController == null) ? 0f : this.playerController.Velocity.x;
  116. float num2 = num * this.xOffsetSeconds + this.offset.x;
  117. float y2 = this.offset.y;
  118. if (Mathf.Abs(this.lastVelocityX - num) > 1f)
  119. {
  120. this.cameraMultiplier = 1.5f;
  121. }
  122. this.lastVelocityX = num;
  123. this.currentX += (x + num2 - this.currentX) * SingletonMonoBehaviourClass<TimeMgr>.instance.deltaTime * this.cameraMultiplier;
  124. this.currentY = y + y2;
  125. this.currentX = Mathf.Clamp(this.currentX, this.leftLimit + this.ScreenWidth / 2f, this.rightLimit - this.ScreenWidth / 2f);
  126. this.currentY = Mathf.Clamp(this.currentY, this.downLimit, this.upLimit);
  127. base.transform.localPosition = new Vector3(this.currentX, this.currentY, base.transform.localPosition.z);
  128. if (Mathf.Abs(x + num2 - this.currentX) > 1f)
  129. {
  130. this.cameraMultiplier += SingletonMonoBehaviourClass<TimeMgr>.instance.deltaTime;
  131. }
  132. }
  133. public Transform leftLimitTrans;
  134. public Transform rightLimitTrans;
  135. public Transform DownLimitTrans;
  136. public Transform UpLimitTrans;
  137. public Camera mainCam;
  138. public Vector2 offset;
  139. public SpriteRenderer mask;
  140. public SpriteRenderer overlayMask;
  141. public float leftLimit;
  142. public float rightLimit;
  143. public float xOffsetSeconds;
  144. private float cameraMultiplier;
  145. private float ScreenWidth;
  146. private float ScreenHeight;
  147. public float downLimit;
  148. public float upLimit;
  149. private Transform targetTrans;
  150. private bool follow = true;
  151. private bool shakeCamera;
  152. private float currentX;
  153. private float currentY;
  154. private float lastVelocityX;
  155. private float lastX;
  156. private float lastY;
  157. }