GameVersionField.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="GameVersionField.cs" company="Exit Games GmbH">
  3. // Part of: Pun Cockpit
  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. /// Game version field.
  13. /// </summary>
  14. public class GameVersionField : MonoBehaviour
  15. {
  16. public InputField PropertyValueInput;
  17. private string _cache;
  18. private bool registered;
  19. private void OnEnable()
  20. {
  21. if (!this.registered)
  22. {
  23. this.registered = true;
  24. this.PropertyValueInput.onEndEdit.AddListener(this.OnEndEdit);
  25. }
  26. }
  27. private void OnDisable()
  28. {
  29. this.registered = false;
  30. this.PropertyValueInput.onEndEdit.RemoveListener(this.OnEndEdit);
  31. }
  32. private void Update()
  33. {
  34. if (PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion != this._cache)
  35. {
  36. this._cache = PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion;
  37. this.PropertyValueInput.text = this._cache;
  38. }
  39. }
  40. // new UI will fire "EndEdit" event also when loosing focus. So check "enter" key and only then submit form.
  41. public void OnEndEdit(string value)
  42. {
  43. if (Input.GetKey(KeyCode.Return) || Input.GetKey(KeyCode.KeypadEnter) || Input.GetKey(KeyCode.Tab))
  44. {
  45. this.SubmitForm(value.Trim());
  46. }
  47. else
  48. {
  49. this.SubmitForm(value);
  50. }
  51. }
  52. public void SubmitForm(string value)
  53. {
  54. this._cache = value;
  55. PunCockpit.Instance.GameVersionOverride = this._cache;
  56. //Debug.Log("PunCockpit.GameVersionOverride = " + PunCockpit.Instance.GameVersionOverride, this);
  57. }
  58. }
  59. }