94 lines
2.6 KiB
C#
94 lines
2.6 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AquariumUpdatePopupPanel : MonoBehaviour
|
|
{
|
|
Transform map;
|
|
RewardItemNew[] rewards;
|
|
Button btn_sure;
|
|
bool isShowBox;
|
|
|
|
private void Awake()
|
|
{
|
|
btn_sure = transform.Find("root/bg/btn_sure/btn_green").GetComponent<Button>();
|
|
map = transform.Find("root/bg/rewards");
|
|
rewards = map.GetComponentsInChildren<RewardItemNew>();
|
|
}
|
|
private void Start()
|
|
{
|
|
OpenBox();
|
|
btn_sure.onClick.AddListener(OnBtnSure);
|
|
}
|
|
void OnBtnSure()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.AquariumUpdatePopupPanel);
|
|
}
|
|
void OpenBox()
|
|
{
|
|
var _dataProvider = GContext.container.Resolve<FishingBoxDataProvier>();
|
|
Dictionary<int, int> FishingBoxs = _dataProvider.Data.FishingBoxs;
|
|
isShowBox = false;
|
|
int index = 0;
|
|
|
|
foreach (var box in FishingBoxs)
|
|
{
|
|
var boxCount = box.Value;
|
|
if (boxCount > 0)
|
|
{
|
|
int id = box.Key;
|
|
|
|
isShowBox = true;
|
|
rewards[index].SetData(new ItemData(id, boxCount));
|
|
}
|
|
rewards[index].gameObject.SetActive(boxCount > 0);
|
|
index++;
|
|
if (index >= 5)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
map.gameObject.SetActive(isShowBox);
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
if (isShowBox)
|
|
{
|
|
var _dataProvider = GContext.container.Resolve<FishingBoxDataProvier>();
|
|
Dictionary<int, int> FishingBoxs = _dataProvider.Data.FishingBoxs;
|
|
var FishingNewBoxs = _dataProvider.Data.FishingNewBoxs;
|
|
int index = 0;
|
|
|
|
foreach (var box in FishingBoxs)
|
|
{
|
|
var boxCount = box.Value;
|
|
if (boxCount > 0)
|
|
{
|
|
int id = box.Key;
|
|
if (FishingNewBoxs.ContainsKey(id))
|
|
{
|
|
FishingNewBoxs[id] += boxCount;
|
|
}
|
|
else
|
|
{
|
|
FishingNewBoxs.Add(id, boxCount);
|
|
}
|
|
}
|
|
index++;
|
|
if (index >= 5)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
_dataProvider.Data.FishingBoxs.Clear();
|
|
_dataProvider.Data.Save();
|
|
GContext.Publish(new ShowData(null, RewardType.FishBoxOpen, 1));
|
|
}
|
|
GContext.Publish(new FaceUICloseEvent());
|
|
}
|
|
}
|