99 lines
3.1 KiB
C#
99 lines
3.1 KiB
C#
using Assets.Framework.Tool;
|
|
using Assets.MyGame.Scripts.Net;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public enum LevelGiftType
|
|
{
|
|
MianFei=1,
|
|
JingYing=2,
|
|
ZhiZun=4
|
|
}
|
|
public class LevelGiftitem : MonoBehaviour
|
|
{
|
|
public Image img_MianFei;
|
|
public Image img_MianFeiDuiGou;
|
|
public Image img_MianFeiBackForword;
|
|
|
|
public TextMeshProUGUI tmp_MianFeiPropCount;
|
|
|
|
public Image img_JingYing;
|
|
public Image img_JingYingDuiGou;
|
|
public Image img_JingYingBackForword;
|
|
public Image img_JingYingLocal;
|
|
public TextMeshProUGUI tmp_JingYingPropCount;
|
|
|
|
|
|
public Image img_ZhiZun;
|
|
public Image img_ZhiZunDuiGou;
|
|
public Image img_ZhiZunBackForword;
|
|
public Image img_ZhiZunLocal;
|
|
public TextMeshProUGUI tmp_ZhiZunPropCount;
|
|
|
|
public TextMeshProUGUI tmp_currLevel;
|
|
public Sprite sprite_Gold;
|
|
public Sprite sprite_Diamond;
|
|
|
|
public void Init(string urlMianFei, int mianFeiPropCount, string urlJingYing, int jingYingPropCount,
|
|
string urlZhiZun, int zhiZunPropCount, int currLevel, LevelGiftType giftType, bool showDuiGou,
|
|
int normalGiftType = 0, int luxuryGiftType = 0, int supremeGiftType = 0)
|
|
{
|
|
SetGiftImage(img_MianFei, urlMianFei, normalGiftType);
|
|
SetGiftImage(img_JingYing, urlJingYing, luxuryGiftType);
|
|
SetGiftImage(img_ZhiZun, urlZhiZun, supremeGiftType);
|
|
|
|
tmp_MianFeiPropCount.text = mianFeiPropCount.ToString();
|
|
tmp_JingYingPropCount.text = jingYingPropCount.ToString();
|
|
tmp_ZhiZunPropCount.text = zhiZunPropCount.ToString();
|
|
if ((giftType & LevelGiftType.MianFei) != 0)
|
|
{
|
|
img_MianFeiBackForword.gameObject.SetActive(!showDuiGou);
|
|
if (showDuiGou)
|
|
img_MianFeiDuiGou.gameObject.SetActive(true);
|
|
}
|
|
if ((giftType & LevelGiftType.JingYing) != 0)
|
|
{
|
|
img_JingYingLocal.gameObject.SetActive(false);
|
|
img_JingYingBackForword.gameObject.SetActive(!showDuiGou);
|
|
if (showDuiGou)
|
|
img_JingYingDuiGou.gameObject.SetActive(true);
|
|
}
|
|
if ((giftType & LevelGiftType.ZhiZun) != 0)
|
|
{
|
|
img_ZhiZunLocal.gameObject.SetActive(false);
|
|
img_ZhiZunBackForword.gameObject.SetActive(!showDuiGou);
|
|
if (showDuiGou)
|
|
img_ZhiZunDuiGou.gameObject.SetActive(true);
|
|
}
|
|
tmp_currLevel.text = currLevel.ToString();
|
|
}
|
|
|
|
private void SetGiftImage(Image target, string url, int giftType)
|
|
{
|
|
if (target == null) return;
|
|
|
|
if (giftType == 1 && sprite_Gold != null)
|
|
{
|
|
target.sprite = sprite_Gold;
|
|
target.SetNativeSize();
|
|
|
|
}
|
|
else if (giftType == 2 && sprite_Diamond != null)
|
|
{
|
|
target.sprite = sprite_Diamond;
|
|
target.SetNativeSize();
|
|
|
|
}
|
|
else if (!string.IsNullOrEmpty(url))
|
|
{
|
|
WebTool.DownImage(APIManager.baseURL + url, texture =>
|
|
{
|
|
target.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
|
|
});
|
|
}
|
|
}
|
|
}
|