PhotoSliderAndInput.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class PhotoSliderAndInput : MonoBehaviour
  6. {
  7. public void Awake()
  8. {
  9. if (!this.is_awake_)
  10. {
  11. this.is_awake_ = true;
  12. NDebug.AssertNull(this.SliderObject != null);
  13. if (this.InputObject != null)
  14. {
  15. EventDelegate.Add(this.InputObject.onChange, new EventDelegate.Callback(this.OnTextChange));
  16. }
  17. EventDelegate.Add(this.SliderObject.onChange, new EventDelegate.Callback(this.OnSliderChange));
  18. if (this.IsNumInt)
  19. {
  20. this.MinNum = (float)((int)this.MinNum);
  21. this.MaxNum = (float)((int)this.MaxNum);
  22. }
  23. }
  24. }
  25. public void ResetValue()
  26. {
  27. this.Awake();
  28. this.value = this.ResetNum;
  29. }
  30. private void OnTextChange()
  31. {
  32. if (this.fix_update_)
  33. {
  34. return;
  35. }
  36. float num = this.MinNum;
  37. try
  38. {
  39. num = float.Parse(UIInput.current.value);
  40. if (this.IsNumInt)
  41. {
  42. num = (float)((int)num);
  43. }
  44. num = wf.Math.RoundMinMax(num, this.MinNum, this.MaxNum);
  45. }
  46. catch
  47. {
  48. return;
  49. }
  50. this.SliderObject.value = (num - this.MinNum) / (this.MaxNum - this.MinNum);
  51. }
  52. private void OnSliderChange()
  53. {
  54. if (this.fix_update_)
  55. {
  56. return;
  57. }
  58. float num = this.MinNum;
  59. try
  60. {
  61. num = this.MinNum + (this.MaxNum - this.MinNum) * this.SliderObject.value;
  62. if (this.IsNumInt)
  63. {
  64. num = (float)((int)num);
  65. }
  66. num = wf.Math.RoundMinMax(num, this.MinNum, this.MaxNum);
  67. }
  68. catch
  69. {
  70. return;
  71. }
  72. if (this.InputObject != null)
  73. {
  74. this.fix_update_ = true;
  75. this.InputObject.value = num.ToString();
  76. this.fix_update_ = false;
  77. }
  78. for (int i = 0; i < this.onChangeValue.Count; i++)
  79. {
  80. this.onChangeValue[i](this.value);
  81. }
  82. }
  83. public string text
  84. {
  85. get
  86. {
  87. return (!(this.InputObject != null)) ? string.Empty : this.InputObject.value;
  88. }
  89. set
  90. {
  91. if (this.InputObject != null)
  92. {
  93. this.InputObject.value = value;
  94. }
  95. }
  96. }
  97. public float value
  98. {
  99. get
  100. {
  101. return this.MinNum + (this.MaxNum - this.MinNum) * this.SliderObject.value;
  102. }
  103. set
  104. {
  105. this.Awake();
  106. float num = value;
  107. if (this.IsNumInt)
  108. {
  109. num = (float)((int)num);
  110. }
  111. num = wf.Math.RoundMinMax(num, this.MinNum, this.MaxNum);
  112. this.SliderObject.value = (num - this.MinNum) / (this.MaxNum - this.MinNum);
  113. this.text = num.ToString();
  114. }
  115. }
  116. public bool visible
  117. {
  118. get
  119. {
  120. return base.gameObject.activeSelf;
  121. }
  122. set
  123. {
  124. base.gameObject.SetActive(value);
  125. }
  126. }
  127. public new bool enabled
  128. {
  129. get
  130. {
  131. return this.SliderObject.thumb.GetComponent<UIButton>().isEnabled;
  132. }
  133. set
  134. {
  135. this.SliderObject.thumb.GetComponent<UIButton>().isEnabled = value;
  136. this.SliderObject.GetComponent<BoxCollider>().enabled = value;
  137. if (this.InputObject != null)
  138. {
  139. this.InputObject.enabled = value;
  140. }
  141. }
  142. }
  143. public UIInput InputObject;
  144. public UISlider SliderObject;
  145. public float MinNum;
  146. public float MaxNum;
  147. public float ResetNum;
  148. public bool IsNumInt;
  149. public List<Action<float>> onChangeValue = new List<Action<float>>();
  150. private bool fix_update_;
  151. private bool is_awake_;
  152. }