123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- public class VRManualMenu : MonoBehaviour
- {
- private void Start()
- {
- this.Init();
- }
- private void Init()
- {
- List<VRManualMenu.ManualData> list = new List<VRManualMenu.ManualData>();
- string text = "vrcom_config.nei";
- if (!GameUty.FileSystem.IsExistentFile(text))
- {
- NDebug.Assert("表がありません。" + text, false);
- }
- using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
- {
- using (CsvParser csvParser = new CsvParser())
- {
- bool condition = csvParser.Open(afileBase);
- NDebug.Assert(condition, text + "\nopen failed.");
- for (int i = 1; i < csvParser.max_cell_y; i++)
- {
- if (csvParser.IsCellToExistData(0, i))
- {
- int num = 0;
- int cellAsInteger = csvParser.GetCellAsInteger(num++, i);
- string cellAsString = csvParser.GetCellAsString(num++, i);
- string cellAsString2 = csvParser.GetCellAsString(num++, i);
- char[] array = csvParser.GetCellAsString(num++, i).ToCharArray();
- string cellAsString3 = csvParser.GetCellAsString(num++, i);
- bool flag = false;
- for (int j = 0; j < array.Length; j++)
- {
- if (array[j] == ((int)GameMain.Instance.VRDeviceTypeID).ToString().ToCharArray()[0])
- {
- flag = true;
- }
- }
- if (flag)
- {
- if (string.IsNullOrEmpty(cellAsString))
- {
- list.Add(new VRManualMenu.ManualData(cellAsInteger, -1, cellAsString2, cellAsString3, null));
- }
- else
- {
- list.Add(new VRManualMenu.ManualData(cellAsInteger, int.Parse(cellAsString), cellAsString2, cellAsString3, null));
- }
- }
- }
- }
- }
- }
- for (int k = 0; k < list.Count; k++)
- {
- VRManualMenu.ManualData data = list[k];
- if (data.BeforeID != -1)
- {
- this.m_ManualDataArray.Add(data);
- }
- else
- {
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_PrefabButton);
- gameObject.transform.SetParent(this.m_ScrollArea, false);
- gameObject.SetActive(true);
- data.ButtonPair = gameObject.GetComponent<Button>();
- this.m_ManualDataArray.Add(data);
- gameObject.GetComponentInChildren<Text>().text = data.ButtonName;
- gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
- gameObject.GetComponent<Button>().onClick.AddListener(delegate
- {
- this.ChangeManualImage(data.ImageName);
- this.ButtonClickEvent(data);
- });
- if (k == 0)
- {
- gameObject.GetComponent<Button>().onClick.Invoke();
- }
- }
- }
- }
- private void ButtonClickEvent(VRManualMenu.ManualData data)
- {
- Debug.Log(data.ButtonName);
- VRManualMenu.ManualData beforeButton = this.GetBeforePageID(data.BeforeID);
- this.m_LeftButton.onClick.RemoveAllListeners();
- this.m_LeftButton.interactable = false;
- if (beforeButton != null)
- {
- this.m_LeftButton.interactable = true;
- this.m_LeftButton.onClick.AddListener(delegate
- {
- this.ChangeManualImage(beforeButton.ImageName);
- this.ButtonClickEvent(beforeButton);
- });
- }
- VRManualMenu.ManualData nextButton = this.GetNextPageID(data.ID);
- this.m_RightButton.onClick.RemoveAllListeners();
- this.m_RightButton.interactable = false;
- if (nextButton != null)
- {
- this.m_RightButton.interactable = true;
- this.m_RightButton.onClick.AddListener(delegate
- {
- this.ChangeManualImage(nextButton.ImageName);
- this.ButtonClickEvent(nextButton);
- });
- }
- }
- private VRManualMenu.ManualData GetBeforePageID(int beforePageID)
- {
- if (beforePageID == -1)
- {
- return null;
- }
- for (int i = 0; i < this.m_ManualDataArray.Count; i++)
- {
- VRManualMenu.ManualData manualData = this.m_ManualDataArray[i];
- if (manualData.ID == beforePageID)
- {
- return manualData;
- }
- }
- return null;
- }
- private VRManualMenu.ManualData GetNextPageID(int pageID)
- {
- if (pageID == -1)
- {
- return null;
- }
- for (int i = 0; i < this.m_ManualDataArray.Count; i++)
- {
- VRManualMenu.ManualData manualData = this.m_ManualDataArray[i];
- if (manualData.BeforeID == pageID)
- {
- return manualData;
- }
- }
- return null;
- }
- private void ChangeManualImage(string ImageName)
- {
- string path = this.m_uGUIAtlasPath + ImageName;
- base.StartCoroutine(this.Coroutine_Load<Sprite>(path, delegate(ResourceRequest req)
- {
- this.m_ImageManual.sprite = (req.asset as Sprite);
- }));
- }
- private IEnumerator Coroutine_Load<T>(string path, UnityAction<ResourceRequest> callback) where T : UnityEngine.Object
- {
- ResourceRequest res = Resources.LoadAsync<T>(path);
- while (!res.isDone)
- {
- yield return null;
- }
- callback(res);
- yield break;
- }
- [SerializeField]
- private Image m_ImageManual;
- [SerializeField]
- private Text m_TextPageNumber;
- [SerializeField]
- private Button m_LeftButton;
- [SerializeField]
- private Button m_RightButton;
- private string m_uGUIAtlasPath = "SceneVRCommunication\\Tablet\\Sprite\\";
- [SerializeField]
- [Tooltip("ボタンを並べるエリア")]
- private RectTransform m_ScrollArea;
- [SerializeField]
- [Tooltip("左に並ぶボタンのプレハブ")]
- private GameObject m_PrefabButton;
- private List<VRManualMenu.ManualData> m_ManualDataArray = new List<VRManualMenu.ManualData>();
- private class ManualData
- {
- public ManualData(int id, int beforeID, string imageName, string buttonName, Button button)
- {
- this.ID = id;
- this.BeforeID = beforeID;
- this.ImageName = imageName;
- this.ButtonName = buttonName;
- this.ButtonPair = button;
- }
- public int ID;
- public int BeforeID;
- public string ImageName;
- public string ButtonName;
- public Button ButtonPair;
- }
- }
|