123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using wf;
- public class PhotoSliderAndInput : MonoBehaviour
- {
- public void Awake()
- {
- if (!this.is_awake_)
- {
- this.is_awake_ = true;
- NDebug.AssertNull(this.SliderObject != null);
- if (this.InputObject != null)
- {
- EventDelegate.Add(this.InputObject.onChange, new EventDelegate.Callback(this.OnTextChange));
- }
- EventDelegate.Add(this.SliderObject.onChange, new EventDelegate.Callback(this.OnSliderChange));
- if (this.IsNumInt)
- {
- this.MinNum = (float)((int)this.MinNum);
- this.MaxNum = (float)((int)this.MaxNum);
- }
- }
- }
- public void ResetValue()
- {
- this.Awake();
- this.value = this.ResetNum;
- }
- private void OnTextChange()
- {
- if (this.fix_update_)
- {
- return;
- }
- float num = this.MinNum;
- try
- {
- num = float.Parse(UIInput.current.value);
- if (this.IsNumInt)
- {
- num = (float)((int)num);
- }
- num = wf.Math.RoundMinMax(num, this.MinNum, this.MaxNum);
- }
- catch
- {
- return;
- }
- this.SliderObject.value = (num - this.MinNum) / (this.MaxNum - this.MinNum);
- }
- private void OnSliderChange()
- {
- if (this.fix_update_)
- {
- return;
- }
- float num = this.MinNum;
- try
- {
- num = this.MinNum + (this.MaxNum - this.MinNum) * this.SliderObject.value;
- if (this.IsNumInt)
- {
- num = (float)((int)num);
- }
- num = wf.Math.RoundMinMax(num, this.MinNum, this.MaxNum);
- }
- catch
- {
- return;
- }
- if (this.InputObject != null)
- {
- this.fix_update_ = true;
- this.InputObject.value = num.ToString();
- this.fix_update_ = false;
- }
- for (int i = 0; i < this.onChangeValue.Count; i++)
- {
- this.onChangeValue[i](this.value);
- }
- }
- public string text
- {
- get
- {
- return (!(this.InputObject != null)) ? string.Empty : this.InputObject.value;
- }
- set
- {
- if (this.InputObject != null)
- {
- this.InputObject.value = value;
- }
- }
- }
- public float value
- {
- get
- {
- return this.MinNum + (this.MaxNum - this.MinNum) * this.SliderObject.value;
- }
- set
- {
- this.Awake();
- float num = value;
- if (this.IsNumInt)
- {
- num = (float)((int)num);
- }
- num = wf.Math.RoundMinMax(num, this.MinNum, this.MaxNum);
- this.SliderObject.value = (num - this.MinNum) / (this.MaxNum - this.MinNum);
- this.text = num.ToString();
- }
- }
- public bool visible
- {
- get
- {
- return base.gameObject.activeSelf;
- }
- set
- {
- base.gameObject.SetActive(value);
- }
- }
- public new bool enabled
- {
- get
- {
- return this.SliderObject.thumb.GetComponent<UIButton>().isEnabled;
- }
- set
- {
- this.SliderObject.thumb.GetComponent<UIButton>().isEnabled = value;
- this.SliderObject.GetComponent<BoxCollider>().enabled = value;
- if (this.InputObject != null)
- {
- this.InputObject.enabled = value;
- }
- }
- }
- public UIInput InputObject;
- public UISlider SliderObject;
- public float MinNum;
- public float MaxNum;
- public float ResetNum;
- public bool IsNumInt;
- public List<Action<float>> onChangeValue = new List<Action<float>>();
- private bool fix_update_;
- private bool is_awake_;
- }
|