¡»£±¡¥UI À©ºî ¡»£²¡¥¥¤¥Ù¥ó¥ÈÍѤΥ¯¥é¥¹À©ºî ¡»£³¡¥¥Ç¡¼¥¿¥Ù¡¼¥¹À©ºî ¡þ£´¡¥´ÉÍý¥¯¥é¥¹À©ºî
using System.Collections.Generic; using UnityEngine; using UniRx; using UnityEngine.UI; public class MainGameManager : MonoBehaviour { [SerializeField] private Transform routeBasePrefab; [SerializeField] private Transform routeBaseSetTran; [SerializeField] private GameObject routeImagePrefab; [SerializeField] private Transform playerIcon; [SerializeField] private RouteCollection routeCollection; [SerializeField] private Transform eventButtonTran; private List<Transform> routeList = new(); private List<EventBase> currentEventList = new(); private int currentRouteIndex = 0; void Start() { LoadRouteDatas(); GenerateEventButtons(); } /// <summary> /// ¥ë¡¼¥ÈºîÀ® /// </summary> private void LoadRouteDatas() { for (int i = 0; i < routeCollection.routeList.Count; i++) { // ¥ë¡¼¥ÈÇÛÃÖÍѤΥ١¼¥¹ºîÀ® Transform ruteBase = Instantiate(routeBasePrefab, routeBaseSetTran, false); routeList.Add(ruteBase); int index = 0; GameObject ruteBrunch = null; // ¥ë¡¼¥ÈÆâ¤Î¥¤¥Ù¥ó¥Èʬ¤À¤±¥Þ¥¹ÌÜÇÛÃÖ for (int eventCount = 0; eventCount < routeCollection.routeList[i].eventList.Count; eventCount++) { index = eventCount; ; ruteBrunch = Instantiate(routeImagePrefab, ruteBase, false); } // ¥¤¥Ù¥ó¥È¤¬£±¤Ä¤·¤«¤Ê¤¤¾ì¹ç¤Ë¤Ï¥Þ¥¹¤Î½ÄÊý¸þ¤ò¹¤²¤ë if (index == 0) { ruteBrunch.GetComponent<RectTransform>().sizeDelta = new(100, 240); } } } /// <summary> /// ¥×¥ì¥¤¥ä¡¼¥¢¥¤¥³¥ó¤ÎÇÛÃÖ°ÌÃ֤ι¹¿· /// </summary> /// <param name="nextParentObj"></param> private void SetPlayerLocation(Transform nextParentObj) { playerIcon.SetParent(nextParentObj); playerIcon.localPosition = new(0, 50, 0); // TODO ¥Þ¥¹¤Î¿§¤òÊѤ¨¤ë¡£UI ¤´¤Èº¹¤·Âؤ¨¤Ê¤É¤ÎÂбþ²Äǽ nextParentObj.GetComponent<Image>().color = Color.red; } /// <summary> /// ¥²¡¼¥à¿Ê¹ÔÍѤΥ롼¥Èʬ´ô¥Ü¥¿¥ó¤ÎºîÀ® /// </summary> private void GenerateEventButtons() { // ¼¡¤Î¥¤¥Ù¥ó¥ÈÍѤΥܥ¿¥óÀ¸À® for (int i = 0; i < routeCollection.routeList[currentRouteIndex].eventList.Count; i++) { int index = i; EventBase eventButton = Instantiate(routeCollection.routeList[currentRouteIndex].eventList[i], eventButtonTran, false); // ¥Ü¥¿¥ó¤Î¥¤¥Ù¥ó¥È¤ò¹ØÆÉ eventButton.OnClickEventButtonObserbable .ThrottleFirst(System.TimeSpan.FromSeconds(2.0f)) .Subscribe(async _ => { // ¥×¥ì¥¤¥ä¡¼¤Î¥¢¥¤¥³¥ó°ÌÃÖÀßÄê(»Ò¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤¹¤ë) SetPlayerLocation(routeList[currentRouteIndex].GetChild(index)); await eventButton.ExecuteEvent(); HandleEventCompletion(index); }) .AddTo(this); currentEventList.Add(eventButton); } } /// <summary> /// ¥¤¥Ù¥ó¥È½ªÎ»¸å¤Î½èÍý /// </summary> /// <param name="index"></param> private void HandleEventCompletion(int index) { DestroyEndEvents(); currentRouteIndex++; CheckRoute(); } /// <summary> /// ¥ë¡¼¥È¤¬»Ä¤Ã¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯ /// »Ä¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¥ë¡¼¥È¥¯¥ê¥¢ /// »Ä¤Ã¤Æ¤¤¤ì¤Ð¼¡¤Îʬ´ôÍѤΥܥ¿¥ó¤ÎºîÀ® /// </summary> private void CheckRoute() { // ¥ë¡¼¥È¤¬»Ä¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¥ë¡¼¥È¥¯¥ê¥¢ if (routeCollection.routeList.Count <= currentRouteIndex) { Debug.Log("¥ë¡¼¥È½ªÎ»"); return; } // ¥ë¡¼¥È¤¬»Ä¤Ã¤Æ¤¤¤ì¤Ð¼¡¤Îʬ´ôÍѤΥܥ¿¥ó¤ÎºîÀ® GenerateEventButtons(); } /// <summary> /// ʬ´ôÍѥܥ¿¥ó¤Îºï½ü /// </summary> private void DestroyEndEvents() { // ¥¤¥Ù¥ó¥ÈÍѤΥܥ¿¥óºï½ü for (int i = 0; i < currentEventList.Count; i++) { Destroy(currentEventList[i].gameObject); } // Á°¤Î¥¤¥Ù¥ó¥È¤òºï½ü currentEventList.Clear(); } }