XRButtonToggle.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using XRTool.UI;
  8. using XRTool.Util;
  9. namespace XRTool.WorldUI
  10. {
  11. public class XRButtonToggle : XRToggle,ItemCell
  12. {
  13. public Color closeColor = Color.white;
  14. public Color openColor = Color.green;
  15. private Renderer imgRenderer;
  16. public Renderer ImgRenderer
  17. {
  18. get
  19. {
  20. if (!imgRenderer)
  21. {
  22. XRImage3D xrImg = null;
  23. if (CheckXRIcon3D && (xrImg = CheckXRIcon3D.GetComponent<XRImage3D>()))
  24. {
  25. imgRenderer = xrImg.BodyRender;
  26. }
  27. }
  28. return imgRenderer;
  29. }
  30. }
  31. public GameObject GetInstance()
  32. {
  33. return gameObject;
  34. }
  35. public virtual void Hide()
  36. {
  37. if (targetGraphic)
  38. {
  39. targetGraphic.gameObject.SetActive(false);
  40. }
  41. }
  42. public override void OnToggleChanged(bool isOn)
  43. {
  44. if (ImgRenderer)
  45. {
  46. UnityUtil.ChangeMateColor(ImgRenderer, isOn ? openColor : closeColor, "_Color");
  47. }
  48. }
  49. public virtual void SelectItem()
  50. {
  51. isOn = true;
  52. }
  53. public virtual void SetImage(Texture2D img)
  54. {
  55. if (ImgRenderer)
  56. {
  57. UnityUtil.ChangeMateTexture2D(ImgRenderer, img);
  58. }
  59. }
  60. public virtual void Show()
  61. {
  62. if (targetGraphic)
  63. {
  64. targetGraphic.gameObject.SetActive(true);
  65. }
  66. }
  67. public virtual void UnSelectItem()
  68. {
  69. isOn = false;
  70. }
  71. }
  72. }