CameraControl.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. namespace SoftKitty.MasterCharacterCreator
  6. {
  7. public class CameraControl : MonoBehaviour
  8. {
  9. #region variables
  10. public static CameraControl instance;
  11. [HideInInspector]
  12. public bool Initialized = false;
  13. public Transform RotY;
  14. public Transform PosY;
  15. public Camera Cam;
  16. private float targetAngleY = 0F;
  17. private float angleY = 0F;
  18. private float posY = 1F;
  19. private float fov = 43F;
  20. private float targetFov = 43F;
  21. private float yAdd = 5F;
  22. private bool disabled = false;
  23. #endregion
  24. #region internal methods
  25. void Awake()
  26. {
  27. instance = this;
  28. }
  29. void Update()
  30. {
  31. if (!CharacterCusUI.instance.Initialized || disabled) return;
  32. yAdd = Mathf.Lerp(yAdd, Initialized?0F: 5F,Time.deltaTime*5F);
  33. if (Input.GetMouseButton(1)) targetAngleY = (targetAngleY + Input.GetAxis("Mouse X") * 5F) % 360F;
  34. angleY = Mathf.Lerp(angleY, targetAngleY, Time.deltaTime * 5F);
  35. fov = Mathf.Lerp(fov, targetFov, Time.deltaTime * 5F);
  36. if (CharacterCusUI.instance != null && CharacterCusUI.instance.MyCharacter != null && CharacterCusUI.instance.MyCharacter.isInited)
  37. {
  38. float _lerp = (fov - 13F) / 30F;
  39. posY = Mathf.Lerp(CharacterCusUI.instance.MyCharacter.BoneDictionary["Bip001 Head"].position.y, CharacterCusUI.instance.MyCharacter.BoneDictionary["Bip001 Pelvis"].position.y, _lerp);
  40. }
  41. if (EventSystem.current.IsPointerOverGameObject() && CharacterManager.PhotoMode==0) return;
  42. targetFov = Mathf.Clamp(targetFov- Input.GetAxis("Mouse ScrollWheel") * 25F,13F,43F);
  43. }
  44. public void DisableForTime(float _time)
  45. {
  46. StartCoroutine(DisableForTimeCo(_time));
  47. }
  48. IEnumerator DisableForTimeCo(float _time)
  49. {
  50. disabled = true;
  51. yield return new WaitForSeconds(_time);
  52. disabled = false;
  53. }
  54. private void LateUpdate()
  55. {
  56. RotY.transform.localEulerAngles = new Vector3(0F, angleY, 0F);
  57. PosY.transform.localPosition = new Vector3(0F, posY+ yAdd, 0F);
  58. Cam.fieldOfView = fov;
  59. }
  60. #endregion
  61. }
  62. }