ResetLoading.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SC.XR.Unity.Module_InputSystem.InputDeviceGC {
  6. public class ResetLoading : SCModuleMono {
  7. InputDeviceGCPartUI _inputDeviceGCPartUI;
  8. public InputDeviceGCPartUI inputDeviceGCPartUI {
  9. get {
  10. if(_inputDeviceGCPartUI) {
  11. _inputDeviceGCPartUI = GetComponentInParent<InputDeviceGCPartUI>();
  12. }
  13. return _inputDeviceGCPartUI;
  14. }
  15. }
  16. Animator resetLoadingAnimator;
  17. float resetLoadingClipLength = 0;
  18. float timer = 0;
  19. Vector3 loadingPosition = new Vector3(0, 0, 1);
  20. MeshRenderer[] meshRenderer;
  21. public override void OnSCStart() {
  22. base.OnSCStart();
  23. timer = 0;
  24. DebugMy.Log("OnEnable:" + timer, this);
  25. if(meshRenderer == null) {
  26. meshRenderer = GetComponentsInChildren<MeshRenderer>(true);
  27. }
  28. foreach(var item in meshRenderer) {
  29. item.enabled = false;
  30. }
  31. resetLoadingAnimator = GetComponent<Animator>();
  32. //resetLoadingAnimator.enabled = true;
  33. AnimationClip[] clips = resetLoadingAnimator.runtimeAnimatorController.animationClips;
  34. if(clips.Length > 0) {
  35. resetLoadingClipLength = clips[0].length;
  36. }
  37. }
  38. public override void OnSCDisable() {
  39. base.OnSCDisable();
  40. DebugMy.Log("OnDisable", this);
  41. if(meshRenderer == null) {
  42. meshRenderer = GetComponentsInChildren<MeshRenderer>(true);
  43. }
  44. foreach(var item in meshRenderer) {
  45. item.enabled = false;
  46. }
  47. }
  48. public override void OnSCLateUpdate() {
  49. base.OnSCLateUpdate();
  50. // if(API_GSXR_Slam.SlamManager && API_GSXR_Slam.SlamManager.gameObject.activeSelf) {
  51. transform.position = Camera.main.transform.TransformPoint(loadingPosition);
  52. //transform.LookAt(Camera.main.transform);
  53. transform.eulerAngles = Camera.main.transform.eulerAngles + new Vector3(0, 0, -7);
  54. // }
  55. timer += Time.deltaTime;
  56. if(timer > resetLoadingClipLength) {
  57. timer = 0;
  58. gameObject.SetActive(false);
  59. }
  60. }
  61. }
  62. }