using System; using System.Collections.Generic; using Kasizuki; using UnityEngine; public class VRFaceShortcutConfig : MonoBehaviour { public void CacheItemTemplate(string path) where T : VRFaceShortcutConfig.Item { Transform childObject = VRFaceShortcutConfig.GetChildObject(this.m_Grid.gameObject, path); T t = childObject.gameObject.AddComponent(); Type typeFromHandle = typeof(T); this.m_ItemTemplateList.Add(typeFromHandle, t); childObject.gameObject.SetActive(false); } public T CreateItem(string itemLabel) where T : VRFaceShortcutConfig.Item { if (this.m_ItemDic.ContainsKey(itemLabel)) { string message = "[VRFaceShortcutConfig] 既に「" + itemLabel + "」という項目が存在しています"; Debug.LogError(message); NDebug.Assert(message, false); } VRFaceShortcutConfig.Item item; if (!this.m_ItemTemplateList.TryGetValue(typeof(T), out item)) { string message2 = "[VRFaceShortcutConfig] " + typeof(T).ToString() + "型のUI項目はキャッシュされていません"; Debug.LogError(message2); NDebug.Assert(message2, false); } GameObject gameObject = UnityEngine.Object.Instantiate(item.gameObject); gameObject.transform.SetParent(this.m_Grid.transform, false); T component = gameObject.GetComponent(); component.gameObject.SetActive(true); component.label.text = itemLabel; this.m_ItemDic.Add(itemLabel, component); return component; } private void Awake() { this.CacheItemTemplate("temp slider"); this.CacheItemTemplate("temp select"); this.CreateDefaultItems(); this.CreateViveItems(); NGUIWindow fadeWindowThis = this.m_FadeWindowThis; fadeWindowThis.OnClose = (Action)Delegate.Combine(fadeWindowThis.OnClose, new Action(delegate() { ControllerShortcutSettingData.config.Write(); })); } private void CreateDefaultItems() { OVRLipSync.VariableData variable = GameMain.Instance.LipSyncMgr.Variable; VRFaceShortcutConfig.ItemSlider itemSlider = this.CreateItem("リップシンク:マイク感度"); itemSlider.min = 0f; itemSlider.max = 10f; itemSlider.Set(variable.MicSensitivity); itemSlider.onValueChanged = delegate(float value) { GameMain.Instance.LipSyncMgr.Variable.MicSensitivity = value; }; itemSlider = this.CreateItem("リップシンク:自分の声の大きさ"); itemSlider.min = 0f; itemSlider.max = 10f; itemSlider.Set(variable.MicVolume); itemSlider.onValueChanged = delegate(float value) { GameMain.Instance.LipSyncMgr.Variable.MicVolume = value; }; VRFaceShortcutConfig.ItemSelectButton itemSelectButton = this.CreateItem("リップシンク:ミュートにする"); itemSelectButton.textLeft.text = "ON"; itemSelectButton.textRight.text = "OFF"; itemSelectButton.Set(variable.Mute); itemSelectButton.onClickIsLeft = delegate(bool isLeft) { variable.Mute = isLeft; }; itemSelectButton = this.CreateItem("手元ショートカット:表情の変化"); itemSelectButton.textLeft.text = "即座に変更する"; itemSelectButton.textRight.text = "選択して決定する"; itemSelectButton.Set(ControllerShortcutSettingData.config.isDirectMode); itemSelectButton.onClickIsLeft = delegate(bool isLeft) { ControllerShortcutSettingData.config.isDirectMode = isLeft; }; itemSelectButton = this.CreateItem("手元ショートカット:手元のUI"); itemSelectButton.textLeft.text = "常に表示する"; itemSelectButton.textRight.text = "決定時に隠す"; itemSelectButton.Set(ControllerShortcutSettingData.config.isEveryShowMode); itemSelectButton.onClickIsLeft = delegate(bool isLeft) { ControllerShortcutSettingData.config.isEveryShowMode = isLeft; }; itemSlider = this.CreateItem("体向きの頭への追従"); itemSlider.min = 0f; itemSlider.max = 1f; itemSlider.Set(ControllerShortcutSettingData.config.maintainPelvisPosition); itemSlider.onValueChanged = delegate(float value) { ControllerShortcutSettingData.config.maintainPelvisPosition = value; }; itemSlider = this.CreateItem("体位置の頭への追従"); itemSlider.min = 0f; itemSlider.max = 1f; itemSlider.Set(ControllerShortcutSettingData.config.bodyPosStiffness); itemSlider.onValueChanged = delegate(float value) { ControllerShortcutSettingData.config.bodyPosStiffness = value; }; itemSlider = this.CreateItem("体回転の頭への追従"); itemSlider.min = 0f; itemSlider.max = 1f; itemSlider.Set(ControllerShortcutSettingData.config.bodyRotStiffness); itemSlider.onValueChanged = delegate(float value) { ControllerShortcutSettingData.config.bodyRotStiffness = value; }; itemSlider = this.CreateItem("胸部回転の頭への追従"); itemSlider.min = 0f; itemSlider.max = 1f; itemSlider.Set(ControllerShortcutSettingData.config.chestRotationWeight); itemSlider.onValueChanged = delegate(float value) { ControllerShortcutSettingData.config.chestRotationWeight = value; }; itemSlider = this.CreateItem("カメラの画角"); itemSlider.min = 0f; itemSlider.max = 1f; itemSlider.Set(ControllerShortcutSettingData.config.selfCameraFOV); itemSlider.onValueChanged = delegate(float value) { ControllerShortcutSettingData.config.selfCameraFOV = value; }; } private void CreateViveItems() { if (GameMain.Instance.VRDeviceTypeID != GameMain.VRDeviceType.VIVE) { return; } VRFaceShortcutConfig.ItemSelectButton itemSelectButton = this.CreateItem("一番上にあるトラッカーを\n頭トラッキングに利用"); itemSelectButton.textLeft.text = "ON"; itemSelectButton.textRight.text = "OFF"; itemSelectButton.Set(ControllerShortcutSettingData.config.use1TrackerForHead); itemSelectButton.onClickIsLeft = delegate(bool isLeft) { ControllerShortcutSettingData.config.use1TrackerForHead = isLeft; this.SetActiveItem("2つめと3つめのトラッカーを\n足トラッキングに利用", isLeft, false); this.SetActiveItem("1つめと2つめのトラッカーを\n足トラッキングに利用", !isLeft, false); }; } private void SetActiveItem(string itemKey, bool isActive, bool isEnableError = true) { VRFaceShortcutConfig.Item item; if (!this.m_ItemDic.TryGetValue(itemKey, out item)) { if (isEnableError) { string message = "[VRFaceShortcutConfig] コンフィグ項目に「" + itemKey + "」は存在しません"; Debug.LogError(message); NDebug.Assert(message, false); } return; } if (item.gameObject.activeSelf != isActive) { item.gameObject.SetActive(isActive); this.m_IsUpdateReposition = true; } } private void LateUpdate() { if (this.m_IsUpdateReposition) { this.m_IsUpdateReposition = false; this.m_Grid.Reposition(); this.m_ScrollView.UpdatePosition(); } } private static T GetChildObject(GameObject gameObject, string path) { GameObject childObject = UTY.GetChildObject(gameObject, path, false); if (childObject == null) { string message = string.Concat(new string[] { "[VRFaceShortcutConfig] ", gameObject.name, "/", path, "が見つかりませんでした" }); NDebug.Assert(message, false); Debug.LogError(message); } T component = childObject.GetComponent(); if (component == null) { string message2 = string.Concat(new object[] { "[VRFaceShortcutConfig] ", gameObject.name, "/", path, "に、\n", typeof(T), "のコンポーネントがありませんでした" }); NDebug.Assert(message2, false); Debug.LogError(message2); } return component; } [SerializeField] [Range(0.001f, 1f)] private float m_FadeSpeed = 0.25f; [SerializeField] private NGUIWindow m_FadeWindowThis; [SerializeField] private UIScrollView m_ScrollView; [SerializeField] private UIGrid m_Grid; private Dictionary m_ItemTemplateList = new Dictionary(); private Dictionary m_ItemDic = new Dictionary(); private bool m_IsUpdateReposition; public abstract class Item : MonoBehaviour { public UILabel label { get { return this.m_Label; } set { this.m_Label = value; } } protected virtual void Awake() { this.m_Label = VRFaceShortcutConfig.GetChildObject(base.gameObject, "name"); } public abstract void Set(object value); private UILabel m_Label; } public class ItemSlider : VRFaceShortcutConfig.Item { public UISlider slider { get { return this.m_Slider; } private set { this.m_Slider = value; } } public float normalizedValue { get { return this.slider.value; } set { this.slider.value = value; } } public float min { get { return this.m_Min; } set { this.m_Min = value; } } public float max { get { return this.m_Max; } set { this.m_Max = value; } } public float value { get { return Mathf.Lerp(this.min, this.max, this.normalizedValue); } set { this.normalizedValue = Mathf.InverseLerp(this.min, this.max, value); } } public Action onValueChanged { get; set; } public Action onDragFinished { get; set; } protected override void Awake() { base.Awake(); this.slider = VRFaceShortcutConfig.GetChildObject(base.gameObject, "slider"); EventDelegate.Add(this.slider.onChange, delegate() { if (this.onValueChanged != null) { this.onValueChanged(this.value); } }); UISlider slider = this.slider; slider.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(slider.onDragFinished, new UIProgressBar.OnDragFinished(delegate() { if (this.onDragFinished != null) { this.onDragFinished(); } })); } public override void Set(object value) { this.value = (float)value; } private UISlider m_Slider; private float m_Min; private float m_Max = 1f; } public class ItemSelectButton : VRFaceShortcutConfig.Item { public UIButton buttonRight { get { return this.m_ButtonRight; } private set { this.m_ButtonRight = value; } } public UIButton buttonLeft { get { return this.m_ButtonLeft; } private set { this.m_ButtonLeft = value; } } public UILabel textRight { get { return this.m_TextRight; } private set { this.m_TextRight = value; } } public UILabel textLeft { get { return this.m_TextLeft; } private set { this.m_TextLeft = value; } } public Action onClickIsLeft { get; set; } protected override void Awake() { base.Awake(); this.buttonRight = VRFaceShortcutConfig.GetChildObject(base.gameObject, "button right"); this.buttonLeft = VRFaceShortcutConfig.GetChildObject(base.gameObject, "button left"); this.textRight = this.buttonRight.GetComponentInChildren(); this.textLeft = this.buttonLeft.GetComponentInChildren(); EventDelegate.Add(this.buttonRight.onClick, delegate() { if (this.onClickIsLeft != null) { this.onClickIsLeft(false); } this.OnClickButton(false); }); EventDelegate.Add(this.buttonLeft.onClick, delegate() { if (this.onClickIsLeft != null) { this.onClickIsLeft(true); } this.OnClickButton(true); }); } private void OnClickButton(bool isLeft) { this.buttonLeft.defaultColor = ((!isLeft) ? VRFaceShortcutConfig.ItemSelectButton.ButtonDefaultColor : VRFaceShortcutConfig.ItemSelectButton.ButtonClickedColor); this.buttonRight.defaultColor = (isLeft ? VRFaceShortcutConfig.ItemSelectButton.ButtonDefaultColor : VRFaceShortcutConfig.ItemSelectButton.ButtonClickedColor); } public void Emulate(bool isLeft) { UIButton uibutton = (!isLeft) ? this.buttonRight : this.buttonLeft; EventDelegate.Execute(uibutton.onClick); } public override void Set(object value) { this.Emulate((bool)value); } private static Color ButtonDefaultColor = new Color(1f, 1f, 1f, 0.5f); private static Color ButtonClickedColor = Color.white; private UIButton m_ButtonRight; private UIButton m_ButtonLeft; private UILabel m_TextRight; private UILabel m_TextLeft; } }