HandLowPower.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using SC.XR.Unity.Module_InputSystem;
  5. using UnityEngine.UI;
  6. using TMPro;
  7. using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
  8. public class HandLowPower : InputDeviceUIType, IHandUIType {
  9. public HandUIType UIType => HandUIType.LOWPOWER;
  10. public List<Image> ImageList;
  11. public List<TextMeshProUGUI> TextMeshProUGUIList;
  12. Coroutine effect;
  13. public float effectDurtion = 3;
  14. private float tempTime = 0;
  15. public void OnEnable() {
  16. ImageList = new List<Image>(GetComponentsInChildren<Image>());
  17. TextMeshProUGUIList = new List<TextMeshProUGUI>(GetComponentsInChildren<TextMeshProUGUI>());
  18. effect = StartCoroutine(EffectFunction(effectDurtion));
  19. }
  20. void OnDisable() {
  21. if (effect != null) {
  22. StopCoroutine(effect);
  23. }
  24. }
  25. IEnumerator EffectFunction(float time) {
  26. yield return new WaitForSeconds(0.2f);
  27. AudioSystem.getInstance.PlayAudioOneShot(gameObject, SCAudiosConfig.AudioType.Notification);
  28. tempTime = 0;
  29. while ((tempTime += Time.deltaTime*1.5f) < time) {
  30. float flag = Mathf.Clamp01((tempTime) / time);
  31. foreach (var item in ImageList) {
  32. item.color = new Color(item.color.r, item.color.g, item.color.b, flag);
  33. }
  34. foreach (var item in TextMeshProUGUIList) {
  35. item.color = new Color(item.color.r, item.color.g, item.color.b, flag);
  36. }
  37. yield return null;
  38. }
  39. yield return new WaitForSeconds(2);
  40. tempTime = 0;
  41. while ((tempTime += Time.deltaTime) < time) {
  42. float flag = Mathf.Clamp01( (time - tempTime) / time);
  43. foreach (var item in ImageList) {
  44. item.color = new Color(item.color.r, item.color.g, item.color.b, flag);
  45. }
  46. foreach (var item in TextMeshProUGUIList) {
  47. item.color = new Color(item.color.r, item.color.g, item.color.b, flag);
  48. }
  49. yield return null;
  50. }
  51. ModuleStop();
  52. }
  53. }