WfCameraMoveSupport.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using UnityEngine;
  3. internal class WfCameraMoveSupport : MonoBehaviour
  4. {
  5. public CameraMain camera
  6. {
  7. get
  8. {
  9. return GameMain.Instance.MainCamera;
  10. }
  11. }
  12. public Vector3 targetPosition
  13. {
  14. get
  15. {
  16. return this.camera.GetTargetPos();
  17. }
  18. set
  19. {
  20. this.camera.SetTargetPos(value, true);
  21. }
  22. }
  23. public float distance
  24. {
  25. get
  26. {
  27. return this.camera.GetDistance();
  28. }
  29. set
  30. {
  31. this.camera.SetDistance(value, true);
  32. }
  33. }
  34. public Vector2 aroundAngle
  35. {
  36. get
  37. {
  38. return this.camera.GetAroundAngle();
  39. }
  40. set
  41. {
  42. this.camera.SetAroundAngle(value, true);
  43. }
  44. }
  45. public Vector3 savePosition { get; private set; }
  46. public float saveDistance { get; private set; }
  47. public Vector2 saveAngle { get; private set; }
  48. public void SaveCameraPosition()
  49. {
  50. this.savePosition = GameMain.Instance.MainCamera.GetTargetPos();
  51. this.saveDistance = GameMain.Instance.MainCamera.GetDistance();
  52. this.saveAngle = GameMain.Instance.MainCamera.GetAroundAngle();
  53. }
  54. public void SaveCameraPosition(Vector3 targetPosition, float distance, Vector2 aroundAngle)
  55. {
  56. this.savePosition = targetPosition;
  57. this.saveDistance = distance;
  58. this.saveAngle = aroundAngle;
  59. }
  60. public void StartCameraPosition(Vector3 position, float distance, Vector2 aroundAngle)
  61. {
  62. Vector2 aroundAngle2 = GameMain.Instance.MainCamera.GetAroundAngle();
  63. Vector2 vector = new Vector2(this.RoundDegree(aroundAngle2.x), this.RoundDegree(aroundAngle2.y));
  64. aroundAngle = new Vector2(this.RoundDegree(aroundAngle.x), this.RoundDegree(aroundAngle.y));
  65. if (Mathf.Abs(aroundAngle.y - 360f - vector.y) < Mathf.Abs(aroundAngle.y - vector.y))
  66. {
  67. aroundAngle.y -= 360f;
  68. }
  69. else if (Mathf.Abs(aroundAngle.y + 360f - vector.y) < Mathf.Abs(aroundAngle.y - vector.y))
  70. {
  71. aroundAngle.y += 360f;
  72. }
  73. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  74. {
  75. "easetype",
  76. iTween.EaseType.easeOutCubic,
  77. "from",
  78. this.targetPosition,
  79. "to",
  80. position,
  81. "time",
  82. this.moveTime,
  83. "onupdate",
  84. "UpdateCameraTargetPosition"
  85. }));
  86. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  87. {
  88. "easetype",
  89. iTween.EaseType.easeOutCubic,
  90. "from",
  91. this.distance,
  92. "to",
  93. distance,
  94. "time",
  95. this.moveTime,
  96. "onUpdate",
  97. "UpdateCameraDistance"
  98. }));
  99. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  100. {
  101. "easetype",
  102. iTween.EaseType.easeOutCubic,
  103. "from",
  104. vector,
  105. "to",
  106. aroundAngle,
  107. "time",
  108. this.moveTime,
  109. "onUpdate",
  110. "UpdateCameraAngle"
  111. }));
  112. }
  113. public void ResetCamera()
  114. {
  115. this.StartCameraPosition(this.savePosition, this.saveDistance, this.saveAngle);
  116. }
  117. private void UpdateCameraTargetPosition(Vector3 targetPos)
  118. {
  119. this.targetPosition = targetPos;
  120. }
  121. private void UpdateCameraDistance(float distance)
  122. {
  123. this.distance = distance;
  124. }
  125. private void UpdateCameraAngle(Vector2 angle)
  126. {
  127. this.aroundAngle = angle;
  128. }
  129. private float RoundDegree(float degres)
  130. {
  131. if (0f > degres || degres > 360f)
  132. {
  133. degres -= Mathf.Floor(degres / 360f) * 360f;
  134. return (!Mathf.Approximately(360f, degres)) ? degres : 0f;
  135. }
  136. return Mathf.Abs(degres);
  137. }
  138. public float moveTime = 0.5f;
  139. }