124 lines
3.0 KiB
C#
124 lines
3.0 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Module.Log;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
// 特殊礼包2的控制脚本
|
|||
|
// 控制转动数字并停到服务器发来的结果上。
|
|||
|
public class GiftBagRandomPanelCtr : MonoBehaviour {
|
|||
|
|
|||
|
private static GiftBagRandomPanelCtr _instance;
|
|||
|
public static GiftBagRandomPanelCtr Instance
|
|||
|
{
|
|||
|
get { return _instance; }
|
|||
|
}
|
|||
|
|
|||
|
public UIImgText multiple; // 倍数
|
|||
|
public GameObject randomShowPanel; // 展示随机 的面板
|
|||
|
public GameObject resultPanel; // 显示奖品面板
|
|||
|
public RollNum numHeight; // 随机高位数
|
|||
|
public RollNum numLow; // 随机低位数
|
|||
|
public UIContainerBase container; // 奖品容器
|
|||
|
public Button backMask; // 背面遮罩
|
|||
|
private bool isFinish = false; // 是否结束展示,仅当结束展示后才能关闭界面
|
|||
|
private int rollFinish;
|
|||
|
|
|||
|
public delegate void VoidNoneDel();
|
|||
|
public event VoidNoneDel OnDisableEvent;
|
|||
|
|
|||
|
public void Awake()
|
|||
|
{
|
|||
|
if (_instance == null)
|
|||
|
{
|
|||
|
_instance = this;
|
|||
|
|
|||
|
backMask.onClick.AddListener(Close);
|
|||
|
numHeight.FinishEvent += OnFinish;
|
|||
|
numLow.FinishEvent += OnFinish;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void OnFinish()
|
|||
|
{
|
|||
|
++rollFinish;
|
|||
|
if(rollFinish >= 2)
|
|||
|
{
|
|||
|
isFinish = true;
|
|||
|
StartCoroutine("Switch");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
isFinish = false;
|
|||
|
rollFinish = 0;
|
|||
|
randomShowPanel.SetActive(false);
|
|||
|
resultPanel.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
public void Show(object packet)
|
|||
|
{
|
|||
|
SynSpecialGift2Reward info = packet as SynSpecialGift2Reward;
|
|||
|
if (info == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if(isFinish == false)
|
|||
|
{
|
|||
|
randomShowPanel.SetActive(true);
|
|||
|
resultPanel.SetActive(false);
|
|||
|
StopAllCoroutines();
|
|||
|
multiple.text = info.multiple.ToString();
|
|||
|
StartCoroutine("StarRoll", info.multiple);
|
|||
|
container.InitContentItem(info.info);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator StarRoll(object n)
|
|||
|
{
|
|||
|
int num = (int)n;
|
|||
|
if(num > 99)
|
|||
|
{
|
|||
|
LogModule.ErrorLog("Can't be lager than 99.");
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
int h = num / 10;
|
|||
|
int l = num % 10;
|
|||
|
|
|||
|
numHeight.SetAndBegin(h);
|
|||
|
yield return new WaitForSeconds(1.0f);
|
|||
|
numLow.SetAndBegin(l);
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator Switch()
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(1.5f);
|
|||
|
randomShowPanel.SetActive(false);
|
|||
|
resultPanel.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
_instance = null;
|
|||
|
}
|
|||
|
|
|||
|
private void Close()
|
|||
|
{
|
|||
|
if(isFinish == true)
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.GiftBagRandomPanel);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
if(OnDisableEvent != null)
|
|||
|
{
|
|||
|
OnDisableEvent.Invoke();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|