chicken_dy/Assets/Scripts/UI/CustomControl/LevelList/LevelCell.cs

75 lines
2.1 KiB
C#
Raw Normal View History

2022-02-10 09:21:59 +00:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2022-02-13 09:36:12 +00:00
public class LevelCell : MonoBehaviour
2022-02-10 09:21:59 +00:00
{
public Action<int> DelClick;
[SerializeField] Button mBtnBg;
[SerializeField] ImageNum mInmLevel;
[SerializeField] Image mImgIconBg;
[SerializeField] Image mImgIcon;
[SerializeField] GameObject mGobDone;
[SerializeField] GameObject mGobComplete;
[SerializeField] Image mImgProgress;
2022-02-13 09:36:12 +00:00
[SerializeField] GameObject mGobEmpty;
[SerializeField] GameObject mGobComingSoon;
2022-02-10 09:21:59 +00:00
2022-02-13 09:36:12 +00:00
private int mIndex;
private int mLevelID;
2022-02-10 09:21:59 +00:00
private void Awake()
{
UIUtils.BindBtn(mBtnBg, OnClick);
}
2022-02-13 09:36:12 +00:00
public void Init(int pIndex)
2022-02-10 09:21:59 +00:00
{
2022-02-13 09:36:12 +00:00
mIndex = pIndex;
2022-02-10 09:21:59 +00:00
mLevelID = GameConfig.Instance.LevelSort[mIndex];
LevelData tLvData = GameConfig.Instance.GetLevelData(mLevelID);
mInmLevel.SetNum(mIndex + 1);
if (ColorUtility.TryParseHtmlString(tLvData.LevelColorCode, out Color tBgColor))
{
mImgIconBg.color = tBgColor;
}
mImgIcon.sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetLevelIconSmall(mLevelID));
int tUnlockedEndingCount = PlayerData.Instance.EndingCountOfLevel(mLevelID);
bool tIsAllEndingsDone = tUnlockedEndingCount == tLvData.Endings.Count;
mGobDone.SetActive(tIsAllEndingsDone);
mGobComplete.SetActive(tIsAllEndingsDone);
mImgProgress.fillAmount = (float)tUnlockedEndingCount / tLvData.Endings.Count;
2022-02-13 09:36:12 +00:00
mBtnBg.gameObject.SetActive(true);
mGobEmpty.gameObject.SetActive(false);
mGobComingSoon.gameObject.SetActive(false);
}
public void SetEmpty()
{
mBtnBg.gameObject.SetActive(false);
mGobEmpty.gameObject.SetActive(true);
mGobComingSoon.gameObject.SetActive(false);
}
public void SetComingSoon()
{
mBtnBg.gameObject.SetActive(false);
mGobEmpty.gameObject.SetActive(false);
mGobComingSoon.gameObject.SetActive(true);
2022-02-10 09:21:59 +00:00
}
private void OnClick()
{
DelClick?.Invoke(mIndex);
}
}