using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class uGUIKaraokeSelect : MonoBehaviour { private uGUIKaraokeSelect.uGUIItemListViewer UIListViewer { get { if (!this.m_UIListViewer) { this.m_UIListViewer = this.m_UIListViewerObject.GetOrAddComponent(); } return this.m_UIListViewer; } } private void Start() { this.m_UIListViewerObject.gameObject.AddComponent(); this.HideListViewer(); this.SetButtonActive(this.m_ButtonOK, false); this.SetButtonActive(this.m_ButtonCANCEL, false); this.SetButtonActive(this.m_ButtonStart, true); this.SetButtonActive(this.m_ButtonEnd, true); this.SetButtonInteractable(this.m_ButtonOK, false); this.SetButtonInteractable(this.m_ButtonCANCEL, false); this.SetButtonInteractable(this.m_ButtonStart, true); this.SetButtonInteractable(this.m_ButtonEnd, true); KaraokeDataManager.MusicData[] musicDataArray = this.GetMusicDataArray(); string arg = string.Empty; if (musicDataArray.Length > 0) { arg = musicDataArray[0].strThumbnailName; this.m_SelectingMusicDataID = musicDataArray[0].ID; } this.m_ButtonSelectMusic.image.sprite = Resources.Load(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", arg)); KaraokeDataManager.BackgroundData backgroundData = this.GetBackgroundData(this.GetNowBackgroundDataIndex()); this.m_ButtonSelectBG.image.sprite = Resources.Load(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", backgroundData.strThumbnailName)); if (SceneVRCommunication.Instance && !SceneVRCommunication.Instance.KaraokeMode) { this.m_ButtonSelectBG.interactable = false; } if (this.GetFoodDataArray().Length <= 0) { this.m_ButtonSelectFood.interactable = false; } } public void OpenListSelectMusic(bool isOn) { uGUIKaraokeSelect.c__AnonStorey0 c__AnonStorey = new uGUIKaraokeSelect.c__AnonStorey0(); c__AnonStorey.$this = this; this.SetButtonActive(this.m_ButtonOK, true); this.SetButtonActive(this.m_ButtonCANCEL, true); this.SetButtonActive(this.m_ButtonStart, false); this.SetButtonActive(this.m_ButtonEnd, false); this.SetButtonInteractable(this.m_ButtonOK, true); this.SetButtonInteractable(this.m_ButtonCANCEL, true); this.ShowListViewer(); c__AnonStorey.musicArray = this.GetMusicDataArray(); this.m_BeforeSelectedGameObject = null; this.UIListViewer.Show(c__AnonStorey.musicArray.Length, delegate(int index, GameObject item) { Toggle component = item.GetComponent(); uGUIKaraokeSelect.uGUIItemListButton itemNumber = item.AddComponent(); itemNumber.number = c__AnonStorey.musicArray[index].ID; if (c__AnonStorey.$this.m_SelectingMusicDataID == itemNumber.number) { component.isOn = true; } component.image.sprite = c__AnonStorey.$this.GetResource(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", c__AnonStorey.musicArray[index].strThumbnailName)); component.onValueChanged.AddListener(delegate(bool value) { if (!value) { return; } int number = itemNumber.number; if (c__AnonStorey.IsAlreadySelected(item)) { c__AnonStorey.ButtonEventSetMusic(number); } }); }); this.m_ButtonOK.onClick.RemoveAllListeners(); this.m_ButtonOK.onClick.AddListener(delegate() { int indexMusic = c__AnonStorey.$this.m_SelectingMusicDataID; if (c__AnonStorey.$this.m_BeforeSelectedGameObject) { indexMusic = c__AnonStorey.$this.m_BeforeSelectedGameObject.GetComponent().number; } c__AnonStorey.$this.ButtonEventSetMusic(indexMusic); }); this.m_ButtonCANCEL.onClick.RemoveAllListeners(); this.m_ButtonCANCEL.onClick.AddListener(delegate() { c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonOK, false); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonCANCEL, false); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonStart, true); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonEnd, true); c__AnonStorey.$this.SetButtonInteractable(c__AnonStorey.$this.m_ButtonStart, c__AnonStorey.$this.IsSelectingMusicDataExist()); c__AnonStorey.$this.SetButtonInteractable(c__AnonStorey.$this.m_ButtonEnd, true); c__AnonStorey.$this.HideListViewer(); }); } public void OpenListSelectBG(bool isOn) { uGUIKaraokeSelect.c__AnonStorey2 c__AnonStorey = new uGUIKaraokeSelect.c__AnonStorey2(); c__AnonStorey.$this = this; this.SetButtonActive(this.m_ButtonOK, true); this.SetButtonActive(this.m_ButtonCANCEL, true); this.SetButtonActive(this.m_ButtonStart, false); this.SetButtonActive(this.m_ButtonEnd, false); this.SetButtonInteractable(this.m_ButtonOK, true); this.SetButtonInteractable(this.m_ButtonCANCEL, true); this.ShowListViewer(); c__AnonStorey.backgroundArray = this.GetBackgroundDataArray(); this.m_BeforeSelectedGameObject = null; this.UIListViewer.Show(c__AnonStorey.backgroundArray.Length, delegate(int index, GameObject item) { Toggle component = item.GetComponent(); item.AddComponent().number = index; if (c__AnonStorey.$this.GetNowSelectingBackgroundDataIndex() == index) { component.isOn = true; } component.image.sprite = c__AnonStorey.$this.GetResource(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", c__AnonStorey.backgroundArray[index].strThumbnailName)); component.onValueChanged.AddListener(delegate(bool value) { if (!value) { return; } c__AnonStorey.SetButtonInteractable(c__AnonStorey.m_ButtonOK, true); if (c__AnonStorey.IsAlreadySelected(item)) { c__AnonStorey.ButtonEventSetBG(index); } }); }); this.m_ButtonOK.onClick.RemoveAllListeners(); this.m_ButtonOK.onClick.AddListener(delegate() { int indexBG = c__AnonStorey.$this.GetNowSelectingBackgroundDataIndex(); if (c__AnonStorey.$this.m_BeforeSelectedGameObject) { indexBG = c__AnonStorey.$this.m_BeforeSelectedGameObject.GetComponent().number; } c__AnonStorey.$this.ButtonEventSetBG(indexBG); }); this.m_ButtonCANCEL.onClick.RemoveAllListeners(); this.m_ButtonCANCEL.onClick.AddListener(delegate() { c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonOK, false); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonCANCEL, false); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonStart, true); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonEnd, true); c__AnonStorey.$this.SetButtonInteractable(c__AnonStorey.$this.m_ButtonStart, c__AnonStorey.$this.IsSelectingMusicDataExist()); c__AnonStorey.$this.SetButtonInteractable(c__AnonStorey.$this.m_ButtonEnd, true); c__AnonStorey.$this.HideListViewer(); }); } public void OpenListSelectFood(bool isOn) { uGUIKaraokeSelect.c__AnonStorey4 c__AnonStorey = new uGUIKaraokeSelect.c__AnonStorey4(); c__AnonStorey.$this = this; if (!isOn) { return; } if (this.IsMaidAddCallFlag()) { this.OnEventMaidAddCalled(); return; } this.SetButtonActive(this.m_ButtonOK, true); this.SetButtonActive(this.m_ButtonCANCEL, true); this.SetButtonActive(this.m_ButtonStart, false); this.SetButtonActive(this.m_ButtonEnd, false); this.SetButtonInteractable(this.m_ButtonOK, true); this.SetButtonInteractable(this.m_ButtonCANCEL, true); this.ShowListViewer(); c__AnonStorey.foodArray = this.GetFoodDataArray(); this.m_BeforeSelectedGameObject = null; this.UIListViewer.Show(c__AnonStorey.foodArray.Length, delegate(int index, GameObject item) { Toggle component = item.GetComponent(); item.AddComponent().number = index; if (c__AnonStorey.$this.m_SelectingFoodDataIndex == index) { component.isOn = true; } component.image.sprite = c__AnonStorey.$this.GetResource(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", c__AnonStorey.foodArray[index].strThumbnailName)); component.onValueChanged.AddListener(delegate(bool value) { if (!value) { return; } c__AnonStorey.SetButtonInteractable(c__AnonStorey.m_ButtonOK, true); if (c__AnonStorey.IsAlreadySelected(item)) { c__AnonStorey.ButtonEventSetFood(index); } }); }); this.m_ButtonOK.onClick.RemoveAllListeners(); this.m_ButtonOK.onClick.AddListener(delegate() { int indexFood = c__AnonStorey.$this.m_SelectingFoodDataIndex; if (c__AnonStorey.$this.m_BeforeSelectedGameObject) { indexFood = c__AnonStorey.$this.m_BeforeSelectedGameObject.GetComponent().number; } c__AnonStorey.$this.ButtonEventSetFood(indexFood); }); this.m_ButtonCANCEL.onClick.RemoveAllListeners(); this.m_ButtonCANCEL.onClick.AddListener(delegate() { c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonOK, false); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonCANCEL, false); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonStart, true); c__AnonStorey.$this.SetButtonActive(c__AnonStorey.$this.m_ButtonEnd, true); c__AnonStorey.$this.SetButtonInteractable(c__AnonStorey.$this.m_ButtonStart, c__AnonStorey.$this.IsSelectingMusicDataExist()); c__AnonStorey.$this.SetButtonInteractable(c__AnonStorey.$this.m_ButtonEnd, true); c__AnonStorey.$this.HideListViewer(); }); } private void ButtonEventSetMusic(int indexMusic) { this.m_SelectingMusicDataID = indexMusic; this.SetButtonActive(this.m_ButtonOK, false); this.SetButtonActive(this.m_ButtonCANCEL, false); this.SetButtonActive(this.m_ButtonStart, true); this.SetButtonActive(this.m_ButtonEnd, true); this.SetButtonInteractable(this.m_ButtonStart, this.IsSelectingMusicDataExist()); this.SetButtonInteractable(this.m_ButtonEnd, true); this.HideListViewer(); this.m_ButtonSelectMusic.image.sprite = Resources.Load(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", this.GetMusicData(indexMusic).strThumbnailName)); } private void ButtonEventSetBG(int indexBG) { this.SetBG(indexBG); Debug.Log(string.Format("[Karaoke]背景が選択された\n選択した背景インデックス:{0}", indexBG)); this.SetButtonActive(this.m_ButtonOK, false); this.SetButtonActive(this.m_ButtonCANCEL, false); this.SetButtonActive(this.m_ButtonStart, true); this.SetButtonActive(this.m_ButtonEnd, true); this.SetButtonInteractable(this.m_ButtonStart, this.IsSelectingMusicDataExist()); this.SetButtonInteractable(this.m_ButtonEnd, true); this.HideListViewer(); this.m_ButtonSelectBG.image.sprite = Resources.Load(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", this.GetBackgroundData(indexBG).strThumbnailName)); } private void ButtonEventSetFood(int indexFood) { this.m_SelectingFoodDataIndex = indexFood; Debug.Log(string.Format("[Karaoke]飲食物が選択された\n選択した飲食物インデックス:{0}", indexFood)); this.SetButtonActive(this.m_ButtonOK, false); this.SetButtonActive(this.m_ButtonCANCEL, false); this.SetButtonActive(this.m_ButtonStart, true); this.SetButtonActive(this.m_ButtonEnd, true); this.SetButtonInteractable(this.m_ButtonStart, this.IsSelectingMusicDataExist()); this.SetButtonInteractable(this.m_ButtonEnd, true); this.HideListViewer(); this.StartFood(indexFood); this.m_ButtonSelectFood.image.sprite = Resources.Load(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", this.GetFoodData(indexFood).strThumbnailName)); this.UpdateOrderButtonImage(); } private void ShowListViewer() { if (!this.m_ParentUIListViewer.gameObject.activeSelf) { UICanvasFade component = this.m_ParentUIListViewer.GetComponent(); component.FadeIn(component.fadeTime, component.isTimeScaling, null); } this.UpdateOrderButtonImage(); } private void HideListViewer() { if (this.m_ParentUIListViewer.gameObject.activeSelf) { UICanvasFade component = this.m_ParentUIListViewer.GetComponent(); component.FadeOut(component.fadeTime, component.isTimeScaling, delegate() { this.m_ParentUIListViewer.gameObject.SetActive(false); }); } this.UpdateOrderButtonImage(); } private void UpdateOrderButtonImage() { if (this.IsMaidAddCallFlag()) { this.m_ButtonSelectFood.image.sprite = this.GetResource("SceneVRCommunication/Tablet/Karaoke/Sprite/kp_event"); Debug.Log("[カラオケ]\u3000メイド二人目呼び出しのフラグがtrue"); } else { Debug.Log("[カラオケ]\u3000メイド二人目はまだ呼ばれていない。"); } } private bool IsAlreadySelected(GameObject selectableObject) { GameObject currentSelectedGameObject = EventSystem.current.currentSelectedGameObject; bool result = this.m_BeforeSelectedGameObject == selectableObject; this.m_BeforeSelectedGameObject = currentSelectedGameObject; return result; } private void SetButtonActive(Button button, bool active) { if (button.gameObject.activeSelf != active) { button.gameObject.SetActive(active); } } private void SetButtonInteractable(Button button, bool interactable) { if (button.interactable != interactable) { button.interactable = interactable; } } private bool IsSelectingMusicDataExist() { Debug.Log(string.Format("[Karaoke]選択している楽曲インデックス:{0}", this.m_SelectingMusicDataID)); return this.m_Manager.IsExistMusicData(this.m_SelectingMusicDataID); } private T GetResource(string path) where T : UnityEngine.Object { if (string.IsNullOrEmpty(path)) { Debug.LogWarning("[Karaoke]リソースのパスが空です"); return (T)((object)null); } T t = Resources.Load(path); if (!t) { Debug.LogWarning(string.Format("[Karaoke]リソースの取得に失敗しました\nパス:「{0}」", path)); } return t; } private bool IsMaidAddCallFlag() { int tmpGenericFlag = GameMain.Instance.CMSystem.GetTmpGenericFlag("カラオケメイド追加"); return tmpGenericFlag == 1; } private void OnEventMaidAddCalled() { string file_name = "karaoke_comevent_main.ks"; GameMain.Instance.ScriptMgr.adv_kag.LoadScriptFile(file_name, string.Empty); GameMain.Instance.ScriptMgr.adv_kag.Exec(); } private KaraokeDataManager.MusicData[] GetMusicDataArray() { return this.m_Manager.GetMusicDataArray(true); } private KaraokeDataManager.FoodData[] GetFoodDataArray() { KaraokeDataManager.FoodData[] foodDataArray = this.m_Manager.GetFoodDataArray(true); List list = new List(); foreach (KaraokeDataManager.FoodData foodData in foodDataArray) { if (!foodData.isNewBodyBlock || !GameMain.Instance.CharacterMgr.GetMaid(0).IsCrcBody) { if (foodData.ID != KaraokeDataManager.FoodData.ID_BUTTON_MAID_ADDITIONAL || KaraokeDataManager.IsEnablePersonalKaraoke003(GameMain.Instance.CharacterMgr.GetMaid(0))) { if (foodData.ID != KaraokeDataManager.FoodData.ID_BUTTON_MAID_ || KaraokeDataManager.IsEnablePersonalKaraoke004(GameMain.Instance.CharacterMgr.GetMaid(0))) { list.Add(foodData); } } } } return list.ToArray(); } private KaraokeDataManager.BackgroundData[] GetBackgroundDataArray() { return this.m_Manager.GetBackgroundDataArray(true); } private KaraokeDataManager.MusicData GetMusicData(int musicID) { return this.m_Manager.GetMusicData(musicID); } private KaraokeDataManager.FoodData GetFoodData(int foodID) { return this.GetFoodDataArray()[foodID]; } private KaraokeDataManager.BackgroundData GetBackgroundData(int backgroundID) { return this.GetBackgroundDataArray()[backgroundID]; } private int GetNowBackgroundDataIndex() { return this.m_Manager.GetNowBGIndex(); } private int GetNowSelectingBackgroundDataIndex() { return this.m_Manager.GetNowSelectingBGIndex(); } public void StartKaraoke() { this.m_Manager.StartKaraoke(this.m_SelectingMusicDataID); } public void EndKaraoke() { this.m_Manager.ButtonExit(); } private void StartFood(int index) { this.m_Manager.SetFoodData(this.GetFoodDataArray()[index].ID); } private void SetBG(int index) { this.m_Manager.SetBGIndex(index); } [SerializeField] private KaraokeDataManager m_Manager; [SerializeField] private Button m_ButtonOK; [SerializeField] private Button m_ButtonCANCEL; [SerializeField] private Button m_ButtonStart; [SerializeField] private Button m_ButtonEnd; [SerializeField] private Toggle m_ButtonSelectMusic; [SerializeField] private Toggle m_ButtonSelectBG; [SerializeField] private Toggle m_ButtonSelectFood; [SerializeField] private RectTransform m_ParentUIListViewer; [SerializeField] private RectTransform m_UIListViewerObject; private uGUIKaraokeSelect.uGUIItemListViewer m_UIListViewer; [Space(16f)] [SerializeField] private RectTransform m_ImageLines; private GameObject m_BeforeSelectedGameObject; private int m_SelectingMusicDataID; private int m_SelectingFoodDataIndex; private const string ThumbnailPath = "SceneVRCommunication/Tablet/Karaoke/Sprite/"; private class uGUIItemListViewer : MonoBehaviour { public GameObject showArea { get { return this.m_ShowArea; } set { this.m_ShowArea = value; } } public GameObject tempItem { get { return this.m_TempItem; } set { this.m_TempItem = value; } } public List itemList { get { return this.m_ItemList; } } public void Show(GameObject showArea, int itemCount, GameObject tempItem = null, Action eventItemSetting = null) { if (showArea) { this.m_ShowArea = showArea; } else if (!this.m_ShowArea) { this.FindShowArea(); } if (!this.m_ShowArea) { return; } if (tempItem) { this.m_TempItem = tempItem; } else if (!this.m_TempItem) { this.FindItemTemplate(); } if (!this.m_ShowArea || !this.m_TempItem) { return; } if (!this.m_ShowArea.activeSelf) { this.m_ShowArea.SetActive(true); } if (this.m_TempItem.activeSelf) { this.m_TempItem.SetActive(false); } this.Clear(); Transform transform = this.m_ShowArea.transform; for (int i = 0; i < itemCount; i++) { GameObject gameObject = UnityEngine.Object.Instantiate(this.m_TempItem); gameObject.SetActive(true); gameObject.transform.SetParent(transform, false); if (eventItemSetting != null) { eventItemSetting(i, gameObject); } this.m_ItemList.Add(gameObject); } } public void Show(int itemCount, Action eventItemSetting = null) { this.Show(this.m_ShowArea, itemCount, this.m_TempItem, eventItemSetting); } public void Clear() { if (!this.m_ShowArea) { return; } if (this.m_ItemList == null) { return; } for (int i = 0; i < this.m_ItemList.Count; i++) { UnityEngine.Object.Destroy(this.m_ItemList[i]); } } private void FindItemTemplate() { if (!this.m_ShowArea) { return; } if (this.m_ShowArea.transform.childCount <= 0) { return; } Transform transform = this.FindChildDeep(this.m_ShowArea.transform, "Temp Item", true); if (!transform) { transform = this.m_ShowArea.transform.GetChild(0); } this.m_TempItem = transform.gameObject; } private void FindShowArea() { Transform transform = base.transform.parent; if (!transform) { transform = base.transform; } string text = "Content"; Transform transform2 = this.FindChildDeep(transform, text, true); if (!transform2) { Debug.LogError(string.Format("[Karaoke.uGUIItemListViewer]項目を並べるエリアが見つかりませんでした\n検索名:{0}", text)); return; } this.m_ShowArea = transform2.gameObject; } private Transform FindChildDeep(Component self, string name, bool includeInactive = false) { Transform[] componentsInChildren = self.GetComponentsInChildren(includeInactive); for (int i = 0; i < componentsInChildren.Length; i++) { if (componentsInChildren[i].name == name) { return componentsInChildren[i]; } } return null; } private GameObject m_ShowArea; private GameObject m_TempItem; private List m_ItemList = new List(); } private class uGUIItemListButton : MonoBehaviour { public int number = -1; } }