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.CacheItemTemplate("temp multi 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; }; VRFaceShortcutConfig.ParentMultiButton parentMultiButton = this.CreateItem("手のスカートへの当たり判定\n※VR CONFIGより優先されます。"); parentMultiButton.textRight.text = "OFF"; parentMultiButton.textLeft.text = "常時ON"; parentMultiButton.textCenter.text = "握時ON"; if (GameMain.Instance.CMSystem.SConfig.OvrHandHitToSkirtVAS == CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.OFF) { parentMultiButton.Set(0); } else if (GameMain.Instance.CMSystem.SConfig.OvrHandHitToSkirtVAS == CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.ON) { parentMultiButton.Set(1); } else { parentMultiButton.Set(2); } parentMultiButton.onClick = delegate(int index) { CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT ovrHandHitToSkirtVAS; if (index == 0) { ovrHandHitToSkirtVAS = CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.OFF; } else if (index == 1) { ovrHandHitToSkirtVAS = CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.ON; } else { ovrHandHitToSkirtVAS = CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.GRAB; } GameMain.Instance.CMSystem.SConfig.OvrHandHitToSkirtVAS = ovrHandHitToSkirtVAS; }; } 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; } private class ParentMultiButton : 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 UIButton buttonCenter { get { return this.m_ButtonCenter; } private set { this.m_ButtonCenter = 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 UILabel textCenter { get { return this.m_TextCenter; } private set { this.m_TextCenter = value; } } public Action onClick { 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.buttonCenter = VRFaceShortcutConfig.GetChildObject(base.gameObject, "button center"); this.textRight = this.buttonRight.GetComponentInChildren(); this.textLeft = this.buttonLeft.GetComponentInChildren(); this.textCenter = this.buttonCenter.GetComponentInChildren(); EventDelegate.Add(this.buttonRight.onClick, delegate() { if (this.onClick != null) { this.onClick(0); } this.OnClickButton(0); }); EventDelegate.Add(this.buttonLeft.onClick, delegate() { if (this.onClick != null) { this.onClick(1); } this.OnClickButton(1); }); EventDelegate.Add(this.buttonCenter.onClick, delegate() { if (this.onClick != null) { this.onClick(2); } this.OnClickButton(2); }); } private void OnClickButton(int index) { this.buttonRight.defaultColor = ((index != 0) ? VRFaceShortcutConfig.ParentMultiButton.ButtonDefaultColor : VRFaceShortcutConfig.ParentMultiButton.ButtonClickedColor); this.buttonLeft.defaultColor = ((index != 1) ? VRFaceShortcutConfig.ParentMultiButton.ButtonDefaultColor : VRFaceShortcutConfig.ParentMultiButton.ButtonClickedColor); this.buttonCenter.defaultColor = ((index != 2) ? VRFaceShortcutConfig.ParentMultiButton.ButtonDefaultColor : VRFaceShortcutConfig.ParentMultiButton.ButtonClickedColor); } public void Emulate(int index) { UIButton uibutton; if (index == 0) { uibutton = this.buttonRight; } else if (index == 1) { uibutton = this.buttonLeft; } else { uibutton = this.buttonCenter; } EventDelegate.Execute(uibutton.onClick); } public override void Set(object value) { this.Emulate((int)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 UIButton m_ButtonCenter; private UILabel m_TextRight; private UILabel m_TextLeft; private UILabel m_TextCenter; } }