SCToggleSwitch3D.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using SC.XR.Unity;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace SC.XR.Unity
  7. {
  8. public class SCToggleSwitch3D : SCToggleBase
  9. {
  10. public GameObject dot;
  11. public Renderer toggleBG;
  12. private MaterialPropertyBlock materialPropertyBlock;
  13. public Color switchOffColor;
  14. public Color switchOnColor;
  15. public Vector3 dotSwitchOffLocalPosition;
  16. public Vector3 dotSwitchOnLocalPosition;
  17. protected override void PlayEffect()
  18. {
  19. if (materialPropertyBlock == null)
  20. {
  21. materialPropertyBlock = new MaterialPropertyBlock();
  22. }
  23. if (m_IsOn)
  24. {
  25. materialPropertyBlock.SetColor("_Color", switchOnColor);
  26. dot.transform.localPosition = dotSwitchOnLocalPosition;
  27. }
  28. else
  29. {
  30. materialPropertyBlock.SetColor("_Color", switchOffColor);
  31. dot.transform.localPosition = dotSwitchOffLocalPosition;
  32. }
  33. toggleBG.SetPropertyBlock(materialPropertyBlock);
  34. }
  35. }
  36. }