| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using DG.Tweening;
- public class MemoryObject : MonoBehaviour
- {
- [SerializeField] GameObject CurrentMemoryObject;
- public List<MemoryTab> memoryTabs = new List<MemoryTab>();
- [SerializeField] MemoryPredictionLine memoryPredictionLine;
- int oldMemory = 0;
- public void Init()
- {
- AssignMemoryTab();
- memoryPredictionLine.Init();
- foreach (MemoryTab memoryTab in memoryTabs)
- {
- memoryTab.Init();
- }
- }
- public void AssignMemoryTab()
- {
- bool isMasterClient = GManager.instance.You.PlayerID == 0;
- for (int i = 0; i < memoryTabs.Count; i++)
- {
- if (isMasterClient)
- {
- memoryTabs[i].Memory = i - 10;
- }
- else
- {
- memoryTabs[i].Memory = 10 - i;
- }
- }
- }
- public IEnumerator SetMemory()
- {
- if (oldMemory != GManager.instance.turnStateMachine.gameContext.Memory)
- {
- bool isMasterClient = GManager.instance.You.PlayerID == 0;
- MemoryTab targetMemoryTab = null;
- MemoryTab currentMemoryTab = null;
- foreach (MemoryTab memoryTab in memoryTabs)
- {
- if (memoryTab.Memory == GManager.instance.turnStateMachine.gameContext.Memory)
- {
- targetMemoryTab = memoryTab;
- }
- if (memoryTab.Memory == oldMemory)
- {
- currentMemoryTab = memoryTab;
- }
- }
- if (targetMemoryTab != null)
- {
- List<MemoryTab> lightMemoryTabs = new List<MemoryTab>();
- int startIndex = memoryTabs.IndexOf(currentMemoryTab);
- int endIndex = memoryTabs.IndexOf(targetMemoryTab);
- if (startIndex < endIndex)
- {
- for (int i = 0; i < memoryTabs.Count; i++)
- {
- if (startIndex <= i && i <= endIndex)
- {
- lightMemoryTabs.Add(memoryTabs[i]);
- }
- }
- }
- else
- {
- for (int i = 0; i < memoryTabs.Count; i++)
- {
- if (endIndex <= i && i <= startIndex)
- {
- lightMemoryTabs.Add(memoryTabs[i]);
- }
- }
- }
- foreach (MemoryTab memoryTab in lightMemoryTabs)
- {
- if (memoryTab.Light != null)
- {
- memoryTab.Light.SetActive(true);
- }
- }
- #region �A�j���[�V����
- bool end = false;
- var sequence = DOTween.Sequence();
- Vector3 TargetPosition = targetMemoryTab.tabObject.transform.localPosition;
- float GoTime = 0.2f;
- sequence
- .Append(CurrentMemoryObject.transform.DOLocalMove(TargetPosition, GoTime).SetEase(Ease.OutCubic))
- .AppendCallback(() =>
- {
- end = true;
- });
- sequence.Play();
- yield return new WaitWhile(() => !end);
- end = false;
- #endregion
- }
- }
- foreach (MemoryTab memoryTab in memoryTabs)
- {
- if (memoryTab.Light != null)
- {
- memoryTab.Light.SetActive(false);
- }
- }
- oldMemory = GManager.instance.turnStateMachine.gameContext.Memory;
- }
- public void ShowMemoryPredictionLine(int nextMemory)
- {
- if (nextMemory >= 10)
- {
- nextMemory = 10;
- }
- else if (nextMemory <= -10)
- {
- nextMemory = -10;
- }
- MemoryTab currentMemoryTab = null;
- MemoryTab nextMemoryTab = null;
- foreach (MemoryTab memoryTab in memoryTabs)
- {
- if (memoryTab.Memory == GManager.instance.turnStateMachine.gameContext.Memory)
- {
- currentMemoryTab = memoryTab;
- }
- if (memoryTab.Memory == nextMemory)
- {
- nextMemoryTab = memoryTab;
- }
- }
- if (currentMemoryTab != null && nextMemoryTab != null)
- {
- memoryPredictionLine.SetMemoryPredictionLine(currentMemoryTab, nextMemoryTab);
- }
- else
- {
- OffMemoryPredictionLine();
- }
- }
- public void OffMemoryPredictionLine()
- {
- memoryPredictionLine.gameObject.SetActive(false);
- }
- }
- [Serializable]
- public class MemoryTab
- {
- public int Memory { get; set; }
- public GameObject tabObject;
- public GameObject Light
- {
- get
- {
- if (tabObject != null)
- {
- if (tabObject.transform.childCount >= 2)
- {
- return tabObject.transform.GetChild(tabObject.transform.childCount - 2).gameObject;
- }
- }
- return null;
- }
- }
- public void Init()
- {
- if (Light != null)
- {
- Light.SetActive(false);
- }
- }
- }
|