RenderModuleCamera.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. public class RenderModuleCamera : MonoBehaviour
  6. {
  7. Transform sphere;
  8. int _mode = 1; //0:静置在桌面;1:旋转校准;
  9. public static RenderModuleCamera ins;
  10. private static int _loadCount = 0;
  11. public static void Load()
  12. {
  13. _loadCount++;
  14. if (_loadCount == 1) Instantiate(Resources.Load("RenderModuleCamera"));
  15. }
  16. public static void Unload()
  17. {
  18. _loadCount--;
  19. if (_loadCount < 0) _loadCount = 0;
  20. if (_loadCount == 0)
  21. {
  22. try { Destroy(ins.gameObject); } catch(System.Exception e) { Debug.LogError(e); }
  23. }
  24. }
  25. void Awake()
  26. {
  27. ins = this;
  28. DontDestroyOnLoad(gameObject);
  29. sphere = transform.Find("Sphere");
  30. }
  31. void OnDestroy()
  32. {
  33. if (ins == this) ins = null;
  34. CloseSequence();
  35. }
  36. Sequence _sequence = null;
  37. void CloseSequence()
  38. {
  39. if (_sequence != null)
  40. {
  41. _sequence.Kill();
  42. _sequence = null;
  43. }
  44. }
  45. public void SetMode(int mode)
  46. {
  47. _mode = mode;
  48. CloseSequence();
  49. if (mode == 0)
  50. {
  51. sphere.localEulerAngles = new Vector3(0, 0, 180);
  52. sphere.gameObject.SetActive(true);
  53. }
  54. else if (mode == 1)
  55. {
  56. sphere.localEulerAngles = new Vector3(0, 0, 0);
  57. sphere.gameObject.SetActive(true);
  58. _sequence = DOTween.Sequence();
  59. _sequence.Append(sphere.DOLocalRotate(new Vector3(360f, 0, 0), 1.5f, RotateMode.FastBeyond360));
  60. _sequence.Append(sphere.DOLocalRotate(new Vector3(0, 360f, 0), 1.5f, RotateMode.FastBeyond360));
  61. _sequence.Append(sphere.DOLocalRotate(new Vector3(0, 0, 360f), 1.5f, RotateMode.FastBeyond360));
  62. _sequence.SetLoops(-1);
  63. }
  64. }
  65. }