CrcCheckToggle.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="CrcCheckToggle.cs" company="Exit Games GmbH">
  3. // Part of: Pun Cockpit Demo
  4. // </copyright>
  5. // <author>developer@exitgames.com</author>
  6. // --------------------------------------------------------------------------------------------------------------------
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. namespace Photon.Pun.Demo.Cockpit
  10. {
  11. /// <summary>
  12. /// PhotonNetwork.CrcCheckEnabled UI Toggle
  13. /// </summary>
  14. [RequireComponent(typeof(Toggle))]
  15. public class CrcCheckToggle : MonoBehaviour
  16. {
  17. Toggle _toggle;
  18. bool registered;
  19. // Use this for initialization
  20. void OnEnable()
  21. {
  22. _toggle = GetComponent<Toggle>();
  23. if (!registered)
  24. {
  25. registered = true;
  26. _toggle.onValueChanged.AddListener(ToggleValue);
  27. }
  28. }
  29. void OnDisable()
  30. {
  31. if (_toggle != null)
  32. {
  33. registered = false;
  34. _toggle.onValueChanged.RemoveListener(ToggleValue);
  35. }
  36. }
  37. void Update()
  38. {
  39. if (PhotonNetwork.CrcCheckEnabled != _toggle.isOn)
  40. {
  41. _toggle.isOn = PhotonNetwork.CrcCheckEnabled;
  42. }
  43. }
  44. public void ToggleValue(bool value)
  45. {
  46. PhotonNetwork.CrcCheckEnabled = value;
  47. //Debug.Log("PhotonNetwork.CrcCheckEnabled = " + PhotonNetwork.CrcCheckEnabled, this);
  48. }
  49. }
  50. }