123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571 |
- using System;
- using System.Collections;
- using System.Collections.Specialized;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class CreativeRoomUIPlacementMaid : MonoBehaviour
- {
- private Maid targetMaid
- {
- get
- {
- if (this.m_TargetMaid == null)
- {
- this.m_TargetMaid = this.GetMaid(true);
- if (this.m_TargetMaid == null)
- {
- this.m_TargetMaid = this.GetMaid(false);
- }
- if (this.m_TargetMaid)
- {
- this.m_TargetMaid.body0.SetBoneHitHeightY(-1000f);
- }
- }
- return this.m_TargetMaid;
- }
- }
- private Maid GetMaid(bool searchLeader = true)
- {
- if (this.m_CharaMgr == null)
- {
- return null;
- }
- Maid maid = null;
- foreach (Maid maid2 in this.m_CharaMgr.GetStockMaidList())
- {
- if (maid2 != null)
- {
- if (!searchLeader || maid2.status.leader)
- {
- maid = maid2;
- break;
- }
- }
- }
- if (maid == null)
- {
- int maidCount = this.m_CharaMgr.GetMaidCount();
- for (int i = 0; i < maidCount; i++)
- {
- Maid maid3 = this.m_CharaMgr.GetMaid(i);
- if (maid3 != null)
- {
- if (!searchLeader || maid3.status.leader)
- {
- maid = maid3;
- break;
- }
- }
- }
- }
- return maid;
- }
- public float snapValuePosition
- {
- set
- {
- if (this.m_GizmoObject == null)
- {
- return;
- }
- this.m_GizmoObject.snapValuePosition = value;
- }
- }
- private void Awake()
- {
- this.m_CharaMgr = GameMain.Instance.CharacterMgr;
- GameObject gameObject;
- if (!(gameObject = GameObject.Find("[CreativeRoomUI Placement Maid] GizmoControlObject")))
- {
- gameObject = new GameObject("[CreativeRoomUI Placement Maid] GizmoControlObject");
- GizmoObject gizmoObject = gameObject.AddComponent<GizmoObject>();
- gizmoObject.activeAxis = true;
- gizmoObject.activeRot = false;
- gizmoObject.snapValuePosition = 0.5f;
- gizmoObject.snapValueAngles = 15f;
- gizmoObject.snapValueScale = 0.1f;
- gameObject.SetActive(false);
- }
- this.m_GizmoObject = gameObject.GetComponent<GizmoObject>();
- GizmoObject gizmoObject2 = this.m_GizmoObject;
- gizmoObject2.onChangePosition = (Action<Vector3>)Delegate.Combine(gizmoObject2.onChangePosition, new Action<Vector3>(this.OnUpdateGizmoPosition));
- GizmoObject gizmoObject3 = this.m_GizmoObject;
- gizmoObject3.onChangeRotation = (Action<Quaternion>)Delegate.Combine(gizmoObject3.onChangeRotation, new Action<Quaternion>(this.OnUpdateGizmoRotation));
- GizmoObject gizmoObject4 = this.m_GizmoObject;
- gizmoObject4.onChangeScale = (Action<Vector3>)Delegate.Combine(gizmoObject4.onChangeScale, new Action<Vector3>(this.OnUpdateGizmoScale));
- this.SetUpUI();
- }
- private void SetUpUI()
- {
- this.m_CachedTransformDataDic = new StringDictionary();
- this.m_InputFieldPosX.contentType = InputField.ContentType.DecimalNumber;
- this.m_InputFieldPosY.contentType = InputField.ContentType.DecimalNumber;
- this.m_InputFieldPosZ.contentType = InputField.ContentType.DecimalNumber;
- this.m_InputFieldRotX.contentType = InputField.ContentType.DecimalNumber;
- this.m_InputFieldRotY.contentType = InputField.ContentType.DecimalNumber;
- this.m_InputFieldRotZ.contentType = InputField.ContentType.DecimalNumber;
- this.m_InputFieldScale.contentType = InputField.ContentType.DecimalNumber;
- this.m_InputFieldPosX.text = this.m_GizmoObject.position.x.ToString("f3");
- this.m_InputFieldPosY.text = this.m_GizmoObject.position.y.ToString("f3");
- this.m_InputFieldPosZ.text = this.m_GizmoObject.position.z.ToString("f3");
- this.m_InputFieldRotX.text = this.m_GizmoObject.eulerAngles.x.ToString("f3");
- this.m_InputFieldRotY.text = this.m_GizmoObject.eulerAngles.y.ToString("f3");
- this.m_InputFieldRotZ.text = this.m_GizmoObject.eulerAngles.z.ToString("f3");
- this.m_InputFieldScale.text = this.m_GizmoObject.scale.x.ToString("f3");
- this.m_SliderScale.value = this.m_GizmoObject.scale.x;
- Action<InputField, Action<float>, Action> action = delegate(InputField input, Action<float> act_change, Action act_end)
- {
- input.onValueChanged.AddListener(delegate(string str)
- {
- float obj;
- if (float.TryParse(str, out obj))
- {
- act_change(obj);
- }
- });
- input.onEndEdit.AddListener(delegate(string str)
- {
- act_end();
- });
- };
- action(this.m_InputFieldPosX, delegate(float value)
- {
- Vector3 position = this.m_GizmoObject.position;
- position.x = value;
- this.m_GizmoObject.position = position;
- }, delegate
- {
- this.m_InputFieldPosX.text = this.m_GizmoObject.position.x.ToString("f3");
- });
- action(this.m_InputFieldPosY, delegate(float value)
- {
- Vector3 position = this.m_GizmoObject.position;
- position.y = value;
- this.m_GizmoObject.position = position;
- }, delegate
- {
- this.m_InputFieldPosY.text = this.m_GizmoObject.position.y.ToString("f3");
- });
- action(this.m_InputFieldPosZ, delegate(float value)
- {
- Vector3 position = this.m_GizmoObject.position;
- position.z = value;
- this.m_GizmoObject.position = position;
- }, delegate
- {
- this.m_InputFieldPosZ.text = this.m_GizmoObject.position.z.ToString("f3");
- });
- action(this.m_InputFieldRotX, delegate(float value)
- {
- Vector3 eulerAngles = this.m_GizmoObject.eulerAngles;
- eulerAngles.x = value;
- this.m_GizmoObject.eulerAngles = eulerAngles;
- }, delegate
- {
- this.m_InputFieldRotX.text = this.m_GizmoObject.eulerAngles.x.ToString("f3");
- });
- action(this.m_InputFieldRotY, delegate(float value)
- {
- Vector3 eulerAngles = this.m_GizmoObject.eulerAngles;
- eulerAngles.y = value;
- this.m_GizmoObject.eulerAngles = eulerAngles;
- }, delegate
- {
- this.m_InputFieldRotY.text = this.m_GizmoObject.eulerAngles.y.ToString("f3");
- });
- action(this.m_InputFieldRotZ, delegate(float value)
- {
- Vector3 eulerAngles = this.m_GizmoObject.eulerAngles;
- eulerAngles.z = value;
- this.m_GizmoObject.eulerAngles = eulerAngles;
- }, delegate
- {
- this.m_InputFieldRotZ.text = this.m_GizmoObject.eulerAngles.z.ToString("f3");
- });
- action(this.m_InputFieldScale, delegate(float value)
- {
- Vector3 scale = this.m_GizmoObject.scale;
- value = Mathf.Clamp(value, this.m_SliderScale.minValue, this.m_SliderScale.maxValue);
- if (Mathf.Approximately(scale.x, value))
- {
- return;
- }
- scale.x = (scale.y = (scale.z = value));
- this.m_GizmoObject.scale = scale;
- this.m_SliderScale.value = value;
- }, delegate
- {
- this.m_InputFieldScale.text = this.m_GizmoObject.scale.x.ToString("f3");
- });
- this.m_SliderScale.onValueChanged.AddListener(delegate(float value)
- {
- if (Mathf.Approximately(this.m_GizmoObject.cachedSnapScale.x, value))
- {
- return;
- }
- this.m_GizmoObject.nonCallbackScale = Vector3.one * value;
- float x = this.m_GizmoObject.cachedSnapScale.x;
- this.m_SliderScale.value = x;
- if (!this.m_InputFieldScale.isFocused)
- {
- this.m_InputFieldScale.text = x.ToString("f3");
- }
- });
- }
- private void Update()
- {
- if (this.targetMaid == null || !this.targetMaid.Visible)
- {
- this.m_GizmoObject.gameObject.SetActive(false);
- return;
- }
- if (EventSystem.current != null)
- {
- if (NInput.GetMouseButtonDown(0))
- {
- GameObject currentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
- if (EventSystem.current.IsPointerOverGameObject() && currentSelectedGameObject && currentSelectedGameObject.GetComponent<RectTransform>())
- {
- this.m_GizmoObject.gameObject.SetActive(false);
- }
- }
- else if (NInput.GetMouseButtonUp(0))
- {
- this.m_GizmoObject.gameObject.SetActive(true);
- }
- }
- }
- private void OnUpdateGizmoPosition(Vector3 position)
- {
- if (this.targetMaid != null)
- {
- this.targetMaid.transform.position = position;
- if (!this.m_InputFieldPosX.isFocused)
- {
- this.m_InputFieldPosX.text = position.x.ToString("f3");
- }
- if (!this.m_InputFieldPosY.isFocused)
- {
- this.m_InputFieldPosY.text = position.y.ToString("f3");
- }
- if (!this.m_InputFieldPosZ.isFocused)
- {
- this.m_InputFieldPosZ.text = position.z.ToString("f3");
- }
- }
- }
- private void OnUpdateGizmoRotation(Quaternion rotation)
- {
- if (this.targetMaid != null)
- {
- this.targetMaid.transform.rotation = rotation;
- Vector3 eulerAngles = rotation.eulerAngles;
- if (!this.m_InputFieldRotX.isFocused)
- {
- this.m_InputFieldRotX.text = eulerAngles.x.ToString("f3");
- }
- if (!this.m_InputFieldRotY.isFocused)
- {
- this.m_InputFieldRotY.text = eulerAngles.y.ToString("f3");
- }
- if (!this.m_InputFieldRotZ.isFocused)
- {
- this.m_InputFieldRotZ.text = eulerAngles.z.ToString("f3");
- }
- }
- }
- private void OnUpdateGizmoScale(Vector3 scale)
- {
- if (this.targetMaid != null)
- {
- this.targetMaid.transform.localScale = scale;
- if (!this.m_InputFieldScale.isFocused)
- {
- this.m_InputFieldScale.text = scale.x.ToString("f3");
- }
- this.m_SliderScale.value = scale.x;
- }
- }
- public void ButtonEvent_GizmoEnableMove()
- {
- GizmoObject gizmoObject = this.m_GizmoObject;
- gizmoObject.activeAxis = true;
- gizmoObject.activeRot = false;
- }
- public void ButtonEvent_GizmoEnableRot()
- {
- GizmoObject gizmoObject = this.m_GizmoObject;
- gizmoObject.activeAxis = false;
- gizmoObject.activeRot = true;
- }
- public void ButtonEvent_GizmoDisable()
- {
- GizmoObject gizmoObject = this.m_GizmoObject;
- gizmoObject.activeAxis = false;
- gizmoObject.activeRot = false;
- }
- public void ButtonEvent_CopyPosition()
- {
- Vector3 position = this.m_GizmoObject.position;
- string text = string.Format("{0},{1},{2}", position.x, position.y, position.z);
- this.m_CachedTransformDataDic["position"] = text.ToString();
- }
- public void ButtonEvent_PastePosition()
- {
- string text = this.m_CachedTransformDataDic["position"];
- if (string.IsNullOrEmpty(text))
- {
- Debug.Log("座標データはまだない");
- return;
- }
- string[] array = text.Split(new char[]
- {
- ','
- });
- if (array.Length != 3)
- {
- Debug.LogError("position の文字数が" + array.Length + "でした");
- return;
- }
- this.m_GizmoObject.position = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
- }
- public void ButtonEvent_ResetPosition()
- {
- this.m_GizmoObject.position = Vector3.zero;
- }
- public void ButtonEvent_CopyRotation()
- {
- Quaternion rotation = this.m_GizmoObject.rotation;
- string text = string.Format("{0},{1},{2},{3}", new object[]
- {
- rotation.x,
- rotation.y,
- rotation.z,
- rotation.w
- });
- this.m_CachedTransformDataDic["rotation"] = text.ToString();
- }
- public void ButtonEvent_PasteRotation()
- {
- string text = this.m_CachedTransformDataDic["rotation"];
- if (string.IsNullOrEmpty(text))
- {
- Debug.Log("回転データはまだない");
- return;
- }
- string[] array = text.Split(new char[]
- {
- ','
- });
- if (array.Length != 4)
- {
- Debug.LogError("rotation の文字数が" + array.Length + "でした");
- return;
- }
- this.m_GizmoObject.rotation = new Quaternion(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]), float.Parse(array[3]));
- }
- public void ButtonEvent_ResetRotation()
- {
- this.m_GizmoObject.rotation = Quaternion.identity;
- }
- public void ButtonEvent_CopyScale()
- {
- Vector3 scale = this.m_GizmoObject.scale;
- string text = string.Format("{0},{1},{2}", scale.x, scale.y, scale.z);
- this.m_CachedTransformDataDic["scale"] = text.ToString();
- }
- public void ButtonEvent_PasteScale()
- {
- string text = this.m_CachedTransformDataDic["scale"];
- if (string.IsNullOrEmpty(text))
- {
- Debug.Log("スケールデータはまだない");
- return;
- }
- string[] array = text.Split(new char[]
- {
- ','
- });
- if (array.Length != 3)
- {
- Debug.LogError("scale の文字数が" + array.Length + "でした");
- return;
- }
- this.m_GizmoObject.scale = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
- }
- public void ButtonEvent_ResetScale()
- {
- this.m_GizmoObject.scale = Vector3.one;
- }
- public void ButtonEvent_CameraFocus()
- {
- Maid targetMaid = this.targetMaid;
- if (!targetMaid)
- {
- return;
- }
- if (!targetMaid.Visible)
- {
- return;
- }
- Transform bone = targetMaid.body0.GetBone("Bip01 Head");
- WfCameraMoveSupport wfCameraMoveSupport = base.GetComponent<WfCameraMoveSupport>();
- if (wfCameraMoveSupport == null)
- {
- wfCameraMoveSupport = base.gameObject.AddComponent<WfCameraMoveSupport>();
- }
- Vector3 position = bone.position;
- float distance = Mathf.Sqrt(5f) * 2f;
- Vector2 aroundAngle = new Vector2(-135f, 45f);
- wfCameraMoveSupport.StartCameraPosition(position, distance, aroundAngle);
- }
- public void ButtonEvent_VisibleMaid(bool isVisible)
- {
- if (this.m_CharaMgr.IsBusy())
- {
- return;
- }
- if (this.targetMaid == null)
- {
- return;
- }
- if (this.targetMaid.ActiveSlotNo == -1)
- {
- this.m_CharaMgr.SetActiveMaid(this.targetMaid, 0);
- this.targetMaid.AllProcPropSeqStart();
- }
- this.targetMaid.Visible = isVisible;
- if (isVisible && this.targetMaid.IsBusy)
- {
- uGUIUtility.SetActiveEventSystem(false);
- GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
- base.StartCoroutine(this.CorMaidLoad(this.targetMaid, new Action(this.OnMaidLoadEnd)));
- }
- }
- public void ButtonEvent_ToggleSnap(bool isEnable)
- {
- if (this.m_GizmoObject)
- {
- if (isEnable)
- {
- this.m_GizmoObject.controlType = GizmoObject.ControlType.Snap;
- }
- else
- {
- this.m_GizmoObject.controlType = GizmoObject.ControlType.Default;
- }
- }
- }
- private IEnumerator CorMaidLoad(Maid targetMaid, Action actLoadEnd)
- {
- targetMaid.Visible = true;
- while (targetMaid.IsBusy)
- {
- yield return null;
- }
- actLoadEnd();
- yield break;
- }
- private void OnMaidLoadEnd()
- {
- GameMain.Instance.MainCamera.FadeIn(0.3f, false, null, true, true, default(Color));
- this.targetMaid.CrossFade("maid_stand01.anm", false, true, false, 0.5f, 1f);
- this.targetMaid.FaceAnime("通常", 0f, 0);
- this.targetMaid.EyeToCamera(Maid.EyeMoveType.目と顔を向ける, 0f);
- uGUIUtility.SetActiveEventSystem(true);
- }
- private void OnDisable()
- {
- if (this.m_GizmoObject)
- {
- this.m_GizmoObject.gameObject.SetActive(false);
- }
- }
- private void OnEnable()
- {
- if (this.m_GizmoObject && this.targetMaid != null && this.targetMaid.Visible)
- {
- this.m_GizmoObject.gameObject.SetActive(true);
- }
- }
- private void OnDestroy()
- {
- if (this.m_GizmoObject)
- {
- UnityEngine.Object.Destroy(this.m_GizmoObject);
- }
- if (this.targetMaid)
- {
- this.targetMaid.transform.position = Vector3.zero;
- this.targetMaid.transform.rotation = Quaternion.identity;
- this.targetMaid.transform.localScale = Vector3.one;
- this.targetMaid.ResetAll();
- this.targetMaid.Visible = false;
- }
- }
- [Header("座標入力欄")]
- [SerializeField]
- private InputField m_InputFieldPosX;
- [SerializeField]
- private InputField m_InputFieldPosY;
- [SerializeField]
- private InputField m_InputFieldPosZ;
- [Header("回転入力欄")]
- [SerializeField]
- private InputField m_InputFieldRotX;
- [SerializeField]
- private InputField m_InputFieldRotY;
- [SerializeField]
- private InputField m_InputFieldRotZ;
- [Header("スケール入力欄")]
- [SerializeField]
- private InputField m_InputFieldScale;
- [SerializeField]
- private Slider m_SliderScale;
- private CharacterMgr m_CharaMgr;
- private GizmoObject m_GizmoObject;
- private Maid m_TargetMaid;
- private StringDictionary m_CachedTransformDataDic;
- }
|