123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- using System;
- using System.Collections.Generic;
- using Kasizuki;
- using UnityEngine;
- public class VRFaceShortcutConfig : MonoBehaviour
- {
- public void CacheItemTemplate<T>(string path) where T : VRFaceShortcutConfig.Item
- {
- Transform childObject = VRFaceShortcutConfig.GetChildObject<Transform>(this.m_Grid.gameObject, path);
- T t = childObject.gameObject.AddComponent<T>();
- Type typeFromHandle = typeof(T);
- this.m_ItemTemplateList.Add(typeFromHandle, t);
- childObject.gameObject.SetActive(false);
- }
- public T CreateItem<T>(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<GameObject>(item.gameObject);
- gameObject.transform.SetParent(this.m_Grid.transform, false);
- T component = gameObject.GetComponent<T>();
- component.gameObject.SetActive(true);
- component.label.text = itemLabel;
- this.m_ItemDic.Add(itemLabel, component);
- return component;
- }
- private void Awake()
- {
- this.CacheItemTemplate<VRFaceShortcutConfig.ItemSlider>("temp slider");
- this.CacheItemTemplate<VRFaceShortcutConfig.ItemSelectButton>("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<VRFaceShortcutConfig.ItemSlider>("リップシンク:マイク感度");
- itemSlider.min = 0f;
- itemSlider.max = 10f;
- itemSlider.Set(variable.MicSensitivity);
- itemSlider.onValueChanged = delegate(float value)
- {
- GameMain.Instance.LipSyncMgr.Variable.MicSensitivity = value;
- };
- itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("リップシンク:自分の声の大きさ");
- 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<VRFaceShortcutConfig.ItemSelectButton>("リップシンク:ミュートにする");
- itemSelectButton.textLeft.text = "ON";
- itemSelectButton.textRight.text = "OFF";
- itemSelectButton.Set(variable.Mute);
- itemSelectButton.onClickIsLeft = delegate(bool isLeft)
- {
- variable.Mute = isLeft;
- };
- itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("手元ショートカット:表情の変化");
- itemSelectButton.textLeft.text = "即座に変更する";
- itemSelectButton.textRight.text = "選択して決定する";
- itemSelectButton.Set(ControllerShortcutSettingData.config.isDirectMode);
- itemSelectButton.onClickIsLeft = delegate(bool isLeft)
- {
- ControllerShortcutSettingData.config.isDirectMode = isLeft;
- };
- itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("手元ショートカット:手元のUI");
- itemSelectButton.textLeft.text = "常に表示する";
- itemSelectButton.textRight.text = "決定時に隠す";
- itemSelectButton.Set(ControllerShortcutSettingData.config.isEveryShowMode);
- itemSelectButton.onClickIsLeft = delegate(bool isLeft)
- {
- ControllerShortcutSettingData.config.isEveryShowMode = isLeft;
- };
- itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体向きの頭への追従");
- itemSlider.min = 0f;
- itemSlider.max = 1f;
- itemSlider.Set(ControllerShortcutSettingData.config.maintainPelvisPosition);
- itemSlider.onValueChanged = delegate(float value)
- {
- ControllerShortcutSettingData.config.maintainPelvisPosition = value;
- };
- itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体位置の頭への追従");
- itemSlider.min = 0f;
- itemSlider.max = 1f;
- itemSlider.Set(ControllerShortcutSettingData.config.bodyPosStiffness);
- itemSlider.onValueChanged = delegate(float value)
- {
- ControllerShortcutSettingData.config.bodyPosStiffness = value;
- };
- itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体回転の頭への追従");
- itemSlider.min = 0f;
- itemSlider.max = 1f;
- itemSlider.Set(ControllerShortcutSettingData.config.bodyRotStiffness);
- itemSlider.onValueChanged = delegate(float value)
- {
- ControllerShortcutSettingData.config.bodyRotStiffness = value;
- };
- itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("胸部回転の頭への追従");
- itemSlider.min = 0f;
- itemSlider.max = 1f;
- itemSlider.Set(ControllerShortcutSettingData.config.chestRotationWeight);
- itemSlider.onValueChanged = delegate(float value)
- {
- ControllerShortcutSettingData.config.chestRotationWeight = value;
- };
- itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("カメラの画角");
- 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<VRFaceShortcutConfig.ItemSelectButton>("一番上にあるトラッカーを\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<T>(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<T>();
- 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<Type, VRFaceShortcutConfig.Item> m_ItemTemplateList = new Dictionary<Type, VRFaceShortcutConfig.Item>();
- private Dictionary<string, VRFaceShortcutConfig.Item> m_ItemDic = new Dictionary<string, VRFaceShortcutConfig.Item>();
- 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<UILabel>(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<float> onValueChanged { get; set; }
- public Action onDragFinished { get; set; }
- protected override void Awake()
- {
- base.Awake();
- this.slider = VRFaceShortcutConfig.GetChildObject<UISlider>(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<bool> onClickIsLeft { get; set; }
- protected override void Awake()
- {
- base.Awake();
- this.buttonRight = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button right");
- this.buttonLeft = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button left");
- this.textRight = this.buttonRight.GetComponentInChildren<UILabel>();
- this.textLeft = this.buttonLeft.GetComponentInChildren<UILabel>();
- 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;
- }
- }
|