123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- public class PhotTransInput : MonoBehaviour
- {
- public void Awake()
- {
- if (this.Type == PhotTransInput.BehaviorType.Scale)
- {
- NDebug.Assert(this.SliderXYZ != null);
- }
- if (this.InputXYZ != null)
- {
- EventDelegate.Add(this.InputXYZ.onChange, new EventDelegate.Callback(this.OnTextChange));
- EventDelegate.Add(this.SliderXYZ.onChange, new EventDelegate.Callback(this.OnSliderChange));
- }
- else
- {
- EventDelegate.Add(this.InputX.onChange, new EventDelegate.Callback(this.OnTextChange));
- EventDelegate.Add(this.InputY.onChange, new EventDelegate.Callback(this.OnTextChange));
- EventDelegate.Add(this.InputZ.onChange, new EventDelegate.Callback(this.OnTextChange));
- }
- this.btn_list_.Clear();
- this.btn_list_.Add(UTY.GetChildObject(base.gameObject, "Btns/ResetBtn", false).GetComponent<UIButton>());
- EventDelegate.Add(this.btn_list_[this.btn_list_.Count - 1].onClick, new EventDelegate.Callback(this.OnReset));
- EventDelegate eventDelegate = new EventDelegate(this, "OnMouseHoverIn");
- eventDelegate.parameters[0].value = "リセット";
- this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
- this.btn_list_.Add(UTY.GetChildObject(base.gameObject, "Btns/CopyBtn", false).GetComponent<UIButton>());
- EventDelegate.Add(this.btn_list_[this.btn_list_.Count - 1].onClick, new EventDelegate.Callback(this.OnCopy));
- eventDelegate = new EventDelegate(this, "OnMouseHoverIn");
- eventDelegate.parameters[0].value = "コピー";
- this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
- this.btn_list_.Add(UTY.GetChildObject(base.gameObject, "Btns/PasteBtn", false).GetComponent<UIButton>());
- EventDelegate.Add(this.btn_list_[this.btn_list_.Count - 1].onClick, new EventDelegate.Callback(this.OnPaste));
- eventDelegate = new EventDelegate(this, "OnMouseHoverIn");
- eventDelegate.parameters[0].value = "ペースト";
- this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
- for (int i = 0; i < this.btn_list_.Count; i++)
- {
- EventDelegate.Add(this.btn_list_[i].gameObject.GetComponent<UIEventTrigger>().onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
- EventDelegate.Add(this.btn_list_[i].gameObject.GetComponent<UIEventTrigger>().onRelease, new EventDelegate.Callback(this.OnMouseHoverOut));
- }
- this.SetTarget(null, Vector3.zero);
- }
- public void SetTarget(Transform target_trans, Vector3 init_vector)
- {
- this.SetInitVector(init_vector);
- this.target_trans_ = target_trans;
- if (this.target_trans_ != null)
- {
- for (int i = 0; i < this.btn_list_.Count; i++)
- {
- this.btn_list_[i].isEnabled = true;
- }
- if (this.InputX != null)
- {
- this.InputX.enabled = true;
- }
- if (this.InputY != null)
- {
- this.InputY.enabled = true;
- }
- if (this.InputZ != null)
- {
- this.InputZ.enabled = true;
- }
- if (this.InputXYZ != null)
- {
- this.InputXYZ.enabled = true;
- }
- if (this.SliderXYZ != null)
- {
- this.SliderXYZ.enabled = true;
- this.SliderXYZ.thumb.GetComponent<UIButton>().isEnabled = true;
- this.SliderXYZ.GetComponent<BoxCollider>().enabled = true;
- }
- this.UpdateInputValue();
- }
- else
- {
- for (int j = 0; j < this.btn_list_.Count; j++)
- {
- this.btn_list_[j].isEnabled = false;
- }
- if (this.InputX != null)
- {
- this.InputX.enabled = false;
- }
- if (this.InputY != null)
- {
- this.InputY.enabled = false;
- }
- if (this.InputZ != null)
- {
- this.InputZ.enabled = false;
- }
- if (this.InputXYZ != null)
- {
- this.InputXYZ.enabled = false;
- }
- if (this.SliderXYZ != null)
- {
- this.SliderXYZ.enabled = true;
- this.SliderXYZ.thumb.GetComponent<UIButton>().isEnabled = false;
- this.SliderXYZ.GetComponent<BoxCollider>().enabled = false;
- }
- this.bacup_pos_ = Vector3.zero;
- if (this.InputXYZ != null)
- {
- this.InputXYZ.value = string.Empty;
- }
- else
- {
- UIInput inputX = this.InputX;
- string text = string.Empty;
- this.InputZ.value = text;
- text = text;
- this.InputY.value = text;
- inputX.value = text;
- }
- if (this.SliderXYZ != null)
- {
- this.SliderXYZ.value = 0f;
- }
- }
- }
- public void SetInitVector(Vector3 init_vector)
- {
- this.init_vector_ = init_vector;
- }
- private void OnTextChange()
- {
- if (this.target_trans_ == null || this.fix_update_)
- {
- return;
- }
- float num = 0f;
- try
- {
- num = float.Parse(UIInput.current.value);
- }
- catch
- {
- return;
- }
- Vector3 num_vec = this.num_vec;
- if (this.InputX == UIInput.current)
- {
- num_vec.x = num;
- }
- else if (this.InputY == UIInput.current)
- {
- num_vec.y = num;
- }
- else if (this.InputZ == UIInput.current)
- {
- num_vec.z = num;
- }
- else if (this.InputXYZ == UIInput.current)
- {
- if (num < this.SliderMin)
- {
- num = this.SliderMin;
- }
- else if (this.SliderMax < num)
- {
- num = this.SliderMax;
- }
- this.SliderXYZ.value = (num - this.SliderMin) / (this.SliderMax - this.SliderMin);
- num = this.SliderMin + (this.SliderMax - this.SliderMin) * this.SliderXYZ.value;
- return;
- }
- this.num_vec = num_vec;
- this.bacup_pos_ = this.num_vec;
- }
- private void OnSliderChange()
- {
- if (this.target_trans_ == null || this.fix_update_)
- {
- return;
- }
- float z = 1f;
- try
- {
- z = this.SliderMin + (this.SliderMax - this.SliderMin) * this.SliderXYZ.value;
- }
- catch
- {
- return;
- }
- Vector3 num_vec = this.num_vec;
- num_vec.x = (num_vec.y = (num_vec.z = z));
- this.fix_update_ = true;
- this.InputXYZ.value = z.ToString("G9");
- this.fix_update_ = false;
- this.num_vec = num_vec;
- this.bacup_pos_ = this.num_vec;
- }
- public void LateUpdate()
- {
- if (this.target_trans_ == null)
- {
- return;
- }
- Vector3 num_vec = this.num_vec;
- if (this.bacup_pos_ != num_vec)
- {
- this.UpdateInputValue();
- }
- }
- public void UpdateInputValue()
- {
- Vector3 num_vec = this.num_vec;
- this.fix_update_ = true;
- if (this.InputXYZ != null)
- {
- this.InputXYZ.value = num_vec.x.ToString("G9");
- }
- else
- {
- this.InputX.value = num_vec.x.ToString("G9");
- this.InputY.value = num_vec.y.ToString("G9");
- this.InputZ.value = num_vec.z.ToString("G9");
- }
- if (this.SliderXYZ != null)
- {
- this.SliderXYZ.value = (num_vec.x - this.SliderMin) / (this.SliderMax - this.SliderMin);
- }
- this.fix_update_ = false;
- this.bacup_pos_ = num_vec;
- }
- public void OnReset()
- {
- if (this.target_trans_ == null)
- {
- return;
- }
- this.num_vec = this.init_vector_;
- this.UpdateInputValue();
- }
- public void OnCopy()
- {
- if (this.target_trans_ == null)
- {
- return;
- }
- this.UpdateInputValue();
- Vector3 num_vec = this.num_vec;
- StringWriter stringWriter = new StringWriter();
- stringWriter.WriteLine(num_vec.x);
- stringWriter.WriteLine(num_vec.y);
- stringWriter.WriteLine(num_vec.z);
- BasePhotoWindowManager.SetCopyData(this.copy_data_title, stringWriter.ToString());
- }
- public void OnPaste()
- {
- if (this.target_trans_ == null)
- {
- return;
- }
- string copyData = BasePhotoWindowManager.GetCopyData(this.copy_data_title);
- if (string.IsNullOrEmpty(copyData))
- {
- return;
- }
- StringReader stringReader = new StringReader(copyData);
- try
- {
- this.num_vec = new Vector3
- {
- x = float.Parse(stringReader.ReadLine()),
- y = float.Parse(stringReader.ReadLine()),
- z = float.Parse(stringReader.ReadLine())
- };
- }
- catch
- {
- return;
- }
- this.UpdateInputValue();
- }
- public void OnMouseHoverIn(string text)
- {
- MouseExposition @object = MouseExposition.GetObject();
- @object.text = text;
- }
- public void OnMouseHoverOut()
- {
- MouseExposition @object = MouseExposition.GetObject();
- @object.text = string.Empty;
- }
- public Vector3 num_vec
- {
- get
- {
- Vector3 result;
- if (this.Type == PhotTransInput.BehaviorType.Pos)
- {
- result = this.target_trans_.localPosition;
- }
- else if (this.Type == PhotTransInput.BehaviorType.Rotate)
- {
- result = this.target_trans_.localRotation.eulerAngles;
- }
- else
- {
- result = this.target_trans_.localScale;
- }
- return result;
- }
- set
- {
- if (this.Type == PhotTransInput.BehaviorType.Pos)
- {
- this.target_trans_.localPosition = value;
- }
- else if (this.Type == PhotTransInput.BehaviorType.Rotate)
- {
- this.target_trans_.rotation = Quaternion.Euler(value);
- }
- else
- {
- this.target_trans_.localScale = value;
- }
- }
- }
- private string copy_data_title
- {
- get
- {
- return "PhotTransInput_" + this.Type.ToString();
- }
- }
- public PhotTransInput.BehaviorType Type;
- public UIInput InputX;
- public UIInput InputY;
- public UIInput InputZ;
- public UIInput InputXYZ;
- public UISlider SliderXYZ;
- public float SliderMin;
- public float SliderMax;
- private List<UIButton> btn_list_ = new List<UIButton>();
- private Transform target_trans_;
- private Vector3 bacup_pos_ = Vector3.zero;
- private bool fix_update_;
- private Vector3 init_vector_ = Vector3.zero;
- public enum BehaviorType
- {
- Pos,
- Rotate,
- Scale
- }
- }
|