123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631 |
- 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<uGUIKaraokeSelect.uGUIItemListViewer>();
- }
- return this.m_UIListViewer;
- }
- }
- private void Start()
- {
- this.m_UIListViewerObject.gameObject.AddComponent<uGUIKaraokeSelect.uGUIItemListViewer>();
- 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<Sprite>(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", arg));
- KaraokeDataManager.BackgroundData backgroundData = this.GetBackgroundData(this.GetNowBackgroundDataIndex());
- this.m_ButtonSelectBG.image.sprite = Resources.Load<Sprite>(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", backgroundData.strThumbnailName));
- if (SceneVRCommunication.Instance && !SceneVRCommunication.Instance.KaraokeMode)
- {
- this.m_ButtonSelectBG.interactable = false;
- }
- }
- public void OpenListSelectMusic(bool isOn)
- {
- 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();
- KaraokeDataManager.MusicData[] musicArray = this.GetMusicDataArray();
- this.m_BeforeSelectedGameObject = null;
- this.UIListViewer.Show(musicArray.Length, delegate(int index, GameObject item)
- {
- Toggle component = item.GetComponent<Toggle>();
- uGUIKaraokeSelect.uGUIItemListButton itemNumber = item.AddComponent<uGUIKaraokeSelect.uGUIItemListButton>();
- itemNumber.number = musicArray[index].ID;
- if (this.m_SelectingMusicDataID == itemNumber.number)
- {
- component.isOn = true;
- }
- component.image.sprite = this.GetResource<Sprite>(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", musicArray[index].strThumbnailName));
- component.onValueChanged.AddListener(delegate(bool value)
- {
- if (!value)
- {
- return;
- }
- int number = itemNumber.number;
- if (this.IsAlreadySelected(item))
- {
- this.ButtonEventSetMusic(number);
- }
- });
- });
- this.m_ButtonOK.onClick.RemoveAllListeners();
- this.m_ButtonOK.onClick.AddListener(delegate
- {
- int indexMusic = this.m_SelectingMusicDataID;
- if (this.m_BeforeSelectedGameObject)
- {
- indexMusic = this.m_BeforeSelectedGameObject.GetComponent<uGUIKaraokeSelect.uGUIItemListButton>().number;
- }
- this.ButtonEventSetMusic(indexMusic);
- });
- this.m_ButtonCANCEL.onClick.RemoveAllListeners();
- this.m_ButtonCANCEL.onClick.AddListener(delegate
- {
- 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();
- });
- }
- public void OpenListSelectBG(bool isOn)
- {
- 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();
- KaraokeDataManager.BackgroundData[] backgroundArray = this.GetBackgroundDataArray();
- this.m_BeforeSelectedGameObject = null;
- this.UIListViewer.Show(backgroundArray.Length, delegate(int index, GameObject item)
- {
- Toggle component = item.GetComponent<Toggle>();
- item.AddComponent<uGUIKaraokeSelect.uGUIItemListButton>().number = index;
- if (this.GetNowSelectingBackgroundDataIndex() == index)
- {
- component.isOn = true;
- }
- component.image.sprite = this.GetResource<Sprite>(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", backgroundArray[index].strThumbnailName));
- component.onValueChanged.AddListener(delegate(bool value)
- {
- if (!value)
- {
- return;
- }
- this.SetButtonInteractable(this.m_ButtonOK, true);
- if (this.IsAlreadySelected(item))
- {
- this.ButtonEventSetBG(index);
- }
- });
- });
- this.m_ButtonOK.onClick.RemoveAllListeners();
- this.m_ButtonOK.onClick.AddListener(delegate
- {
- int indexBG = this.GetNowSelectingBackgroundDataIndex();
- if (this.m_BeforeSelectedGameObject)
- {
- indexBG = this.m_BeforeSelectedGameObject.GetComponent<uGUIKaraokeSelect.uGUIItemListButton>().number;
- }
- this.ButtonEventSetBG(indexBG);
- });
- this.m_ButtonCANCEL.onClick.RemoveAllListeners();
- this.m_ButtonCANCEL.onClick.AddListener(delegate
- {
- 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();
- });
- }
- public void OpenListSelectFood(bool isOn)
- {
- 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();
- KaraokeDataManager.FoodData[] foodArray = this.GetFoodDataArray();
- this.m_BeforeSelectedGameObject = null;
- this.UIListViewer.Show(foodArray.Length, delegate(int index, GameObject item)
- {
- Toggle component = item.GetComponent<Toggle>();
- item.AddComponent<uGUIKaraokeSelect.uGUIItemListButton>().number = index;
- if (this.m_SelectingFoodDataIndex == index)
- {
- component.isOn = true;
- }
- component.image.sprite = this.GetResource<Sprite>(string.Format("{0}{1}", "SceneVRCommunication/Tablet/Karaoke/Sprite/", foodArray[index].strThumbnailName));
- component.onValueChanged.AddListener(delegate(bool value)
- {
- if (!value)
- {
- return;
- }
- this.SetButtonInteractable(this.m_ButtonOK, true);
- if (this.IsAlreadySelected(item))
- {
- this.ButtonEventSetFood(index);
- }
- });
- });
- this.m_ButtonOK.onClick.RemoveAllListeners();
- this.m_ButtonOK.onClick.AddListener(delegate
- {
- int indexFood = this.m_SelectingFoodDataIndex;
- if (this.m_BeforeSelectedGameObject)
- {
- indexFood = this.m_BeforeSelectedGameObject.GetComponent<uGUIKaraokeSelect.uGUIItemListButton>().number;
- }
- this.ButtonEventSetFood(indexFood);
- });
- this.m_ButtonCANCEL.onClick.RemoveAllListeners();
- this.m_ButtonCANCEL.onClick.AddListener(delegate
- {
- 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();
- });
- }
- 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<Sprite>(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<Sprite>(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<Sprite>(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<UICanvasFade>();
- component.FadeIn(component.fadeTime, component.isTimeScaling, null);
- }
- this.UpdateOrderButtonImage();
- }
- private void HideListViewer()
- {
- if (this.m_ParentUIListViewer.gameObject.activeSelf)
- {
- UICanvasFade component = this.m_ParentUIListViewer.GetComponent<UICanvasFade>();
- 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<Sprite>("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<T>(string path) where T : UnityEngine.Object
- {
- if (string.IsNullOrEmpty(path))
- {
- Debug.LogWarning("[Karaoke]リソースのパスが空です");
- return (T)((object)null);
- }
- T t = Resources.Load<T>(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()
- {
- return this.m_Manager.GetFoodDataArray(true);
- }
- 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<GameObject> itemList
- {
- get
- {
- return this.m_ItemList;
- }
- }
- public void Show(GameObject showArea, int itemCount, GameObject tempItem = null, Action<int, GameObject> 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<GameObject>(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<int, GameObject> 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<Transform>(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<GameObject> m_ItemList = new List<GameObject>();
- }
- private class uGUIItemListButton : MonoBehaviour
- {
- public int number = -1;
- }
- }
|