using System; using UnityEngine; internal class WfCameraMoveSupport : MonoBehaviour { public CameraMain camera { get { return GameMain.Instance.MainCamera; } } public Vector3 targetPosition { get { return this.camera.GetTargetPos(); } set { this.camera.SetTargetPos(value, true); } } public float distance { get { return this.camera.GetDistance(); } set { this.camera.SetDistance(value, true); } } public Vector2 aroundAngle { get { return this.camera.GetAroundAngle(); } set { this.camera.SetAroundAngle(value, true); } } public Vector3 savePosition { get; private set; } public float saveDistance { get; private set; } public Vector2 saveAngle { get; private set; } public void SaveCameraPosition() { this.savePosition = GameMain.Instance.MainCamera.GetTargetPos(); this.saveDistance = GameMain.Instance.MainCamera.GetDistance(); this.saveAngle = GameMain.Instance.MainCamera.GetAroundAngle(); } public void SaveCameraPosition(Vector3 targetPosition, float distance, Vector2 aroundAngle) { this.savePosition = targetPosition; this.saveDistance = distance; this.saveAngle = aroundAngle; } public void StartCameraPosition(Vector3 position, float distance, Vector2 aroundAngle) { Vector2 aroundAngle2 = GameMain.Instance.MainCamera.GetAroundAngle(); Vector2 vector = new Vector2(this.RoundDegree(aroundAngle2.x), this.RoundDegree(aroundAngle2.y)); aroundAngle = new Vector2(this.RoundDegree(aroundAngle.x), this.RoundDegree(aroundAngle.y)); if (Mathf.Abs(aroundAngle.y - 360f - vector.y) < Mathf.Abs(aroundAngle.y - vector.y)) { aroundAngle.y -= 360f; } else if (Mathf.Abs(aroundAngle.y + 360f - vector.y) < Mathf.Abs(aroundAngle.y - vector.y)) { aroundAngle.y += 360f; } iTween.ValueTo(base.gameObject, iTween.Hash(new object[] { "easetype", iTween.EaseType.easeOutCubic, "from", this.targetPosition, "to", position, "time", this.moveTime, "onupdate", "UpdateCameraTargetPosition" })); iTween.ValueTo(base.gameObject, iTween.Hash(new object[] { "easetype", iTween.EaseType.easeOutCubic, "from", this.distance, "to", distance, "time", this.moveTime, "onUpdate", "UpdateCameraDistance" })); iTween.ValueTo(base.gameObject, iTween.Hash(new object[] { "easetype", iTween.EaseType.easeOutCubic, "from", vector, "to", aroundAngle, "time", this.moveTime, "onUpdate", "UpdateCameraAngle" })); } public void ResetCamera() { this.StartCameraPosition(this.savePosition, this.saveDistance, this.saveAngle); } private void UpdateCameraTargetPosition(Vector3 targetPos) { this.targetPosition = targetPos; } private void UpdateCameraDistance(float distance) { this.distance = distance; } private void UpdateCameraAngle(Vector2 angle) { this.aroundAngle = angle; } private float RoundDegree(float degres) { if (0f > degres || degres > 360f) { degres -= Mathf.Floor(degres / 360f) * 360f; return (!Mathf.Approximately(360f, degres)) ? degres : 0f; } return Mathf.Abs(degres); } public float moveTime = 0.5f; }