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()); 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 = "ScenePhotoMode/リセット"; this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent().onHoverOver.Add(eventDelegate); this.btn_list_.Add(UTY.GetChildObject(base.gameObject, "Btns/CopyBtn", false).GetComponent()); 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 = "ScenePhotoMode/コピー"; this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent().onHoverOver.Add(eventDelegate); this.btn_list_.Add(UTY.GetChildObject(base.gameObject, "Btns/PasteBtn", false).GetComponent()); 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 = "ScenePhotoMode/ペースト"; this.btn_list_[this.btn_list_.Count - 1].gameObject.GetComponent().onHoverOver.Add(eventDelegate); for (int i = 0; i < this.btn_list_.Count; i++) { EventDelegate.Add(this.btn_list_[i].gameObject.GetComponent().onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut)); EventDelegate.Add(this.btn_list_[i].gameObject.GetComponent().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().isEnabled = true; this.SliderXYZ.GetComponent().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().isEnabled = false; this.SliderXYZ.GetComponent().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.textFromLanguageTerm = 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 btn_list_ = new List(); 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 } }