using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; public class EndPanel : MonoBehaviour { [SerializeField] private Button closeButton; [SerializeField] private Button videoButton; [SerializeField] private GameObject win; [SerializeField] private GameObject lose; [SerializeField] private Transform itemParent; [SerializeField] private GameObject item; [SerializeField] private List _listItem = new List(); private List _fallings = new List(); public void SetData(bool bo) { win.SetActive(bo); lose.SetActive(!bo); if (bo) { SoundSystem.ins.WinEventAudio(); } else { SoundSystem.ins.LoseEventAudio(); } _fallings = new List(); if (_listItem.Count!=0) { foreach (var o in _listItem) { Destroy(o); } } _listItem = new List(); foreach (var fall in BattleManager.ins.Fallings) { bo = false; foreach (var f in _fallings.Where(f => f.id==fall.id)) { f.num += fall.num; bo = true; } if (!bo) { _fallings.Add(fall); } } foreach (var f in _fallings) { var obj=Instantiate(item,itemParent); obj.SetActive(true); obj.GetComponent().SetData(f); _listItem.Add(obj); } } private void OnEnable() { closeButton.onClick.AddListener(ClosePanel); videoButton.onClick.AddListener(ClosePanel); } private void OnDisable() { closeButton.onClick.RemoveListener(ClosePanel); videoButton.onClick.RemoveListener(ClosePanel); } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } void VideoClosePanel() { ADSystem.getInstance().PlayAd(() => { UIMgr.ins.OpenForgePanel(); foreach (var falling in _fallings) { DataManager.AddItem(falling.id,falling.num*2); } }); } void ClosePanel() { UIMgr.ins.OpenForgePanel(); foreach (var falling in _fallings) { DataManager.AddItem(falling.id,falling.num); } } }