|
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using UI.ActivityHuaRongDao;
|
|
|
using FairyGUI;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Threading;
|
|
|
|
|
|
namespace GFGGame
|
|
|
{
|
|
@@ -20,6 +22,8 @@ namespace GFGGame
|
|
|
private List<GObject> _items;
|
|
|
private bool _gameStart;
|
|
|
private HuarongRoadGame cfg;
|
|
|
+ private CancellationTokenSource cancellationTokenSource;
|
|
|
+ private GObject blankItem;
|
|
|
|
|
|
public override void Dispose()
|
|
|
{
|
|
@@ -38,16 +42,23 @@ namespace GFGGame
|
|
|
packageName = UI_ActivityHuaRongDaoUI.PACKAGE_NAME;
|
|
|
_ui = UI_ActivityHuaRongDaoUI.Create();
|
|
|
viewCom = _ui.target;
|
|
|
- viewCom.Center();
|
|
|
+ _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("quanping_moren_bg");
|
|
|
isReturnView = true;
|
|
|
- modal = true;
|
|
|
|
|
|
_ui.m_item.target.visible = false;
|
|
|
_ui.m_btnBack.onClick.Add(OnBtnBackClick);
|
|
|
+ _ui.m_btnLookPic.onClick.Add(OnClickBtnShowOriginPic);
|
|
|
+ _ui.m_btnHidePic.onClick.Add(OnClickBtnHideOriginPic);
|
|
|
+ _ui.m_btnRefresh.onClick.Add(OnClickBtnRefresh);
|
|
|
|
|
|
InitGridInfo();
|
|
|
CreateItems();
|
|
|
-
|
|
|
+ // 初始化空白处图片
|
|
|
+ if (blankItem == null)
|
|
|
+ {
|
|
|
+ blankItem = UIPackage.CreateObject("ActivityHuaRongDao", "item");
|
|
|
+ _ui.target.AddChild(blankItem);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
protected override void OnShown()
|
|
@@ -55,17 +66,22 @@ namespace GFGGame
|
|
|
base.OnShown();
|
|
|
|
|
|
cfg = (HuarongRoadGame)viewData;
|
|
|
- SetGridInfo();
|
|
|
- InitItems();
|
|
|
+
|
|
|
+ blankItem.visible = false;
|
|
|
_gameStart = false;
|
|
|
- ResetCountdown();
|
|
|
- Countdown(null);
|
|
|
- Timers.inst.Add(1, 0, Countdown);
|
|
|
+ cancellationTokenSource = new CancellationTokenSource();
|
|
|
+ Task task = StartAnimation(cancellationTokenSource.Token);
|
|
|
+
|
|
|
+ // 倒计时相关
|
|
|
+ //ResetCountdown();
|
|
|
+ //Countdown(null);
|
|
|
+ //Timers.inst.Add(1, 0, Countdown);
|
|
|
}
|
|
|
|
|
|
protected override void OnHide()
|
|
|
{
|
|
|
base.OnHide();
|
|
|
+ StopMyAsyncFunction();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -86,14 +102,11 @@ namespace GFGGame
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void SetGridInfo()
|
|
|
+ private void SetGridInfo(List<int> numList)
|
|
|
{
|
|
|
//List<int> numList = GetRandomArr(1, 8);
|
|
|
- List<int> numList = GetArrByConfigStep(cfg.step);
|
|
|
- while (CheckListCorrect(numList))
|
|
|
- {
|
|
|
- numList = GetArrByConfigStep(cfg.step);
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
Vector2 originPos = _ui.m_item.target.position;
|
|
|
|
|
|
for (int i = 0; i < _gridNum; i++)
|
|
@@ -152,12 +165,7 @@ namespace GFGGame
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 根据配置步数打乱数组
|
|
|
- /// </summary>
|
|
|
- /// <param name="configStep"></param>
|
|
|
- /// <returns></returns>
|
|
|
- private List<int> GetArrByConfigStep(int configStep)
|
|
|
+ private List<int> CreateIncreaseArr()
|
|
|
{
|
|
|
List<int> list = new List<int>();
|
|
|
|
|
@@ -167,6 +175,18 @@ namespace GFGGame
|
|
|
list.Add(i);
|
|
|
}
|
|
|
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 根据配置步数打乱数组
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="configStep"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private List<int> GetArrByConfigStep(int configStep)
|
|
|
+ {
|
|
|
+ List<int> list = CreateIncreaseArr();
|
|
|
+
|
|
|
int num = 0;
|
|
|
Vector2 zeroPos = new Vector2(0, 0);
|
|
|
Vector2[] dirArr = { new Vector2(-1, 0), new Vector2(1, 0), new Vector2(0, -1), new Vector2(0, 1) };
|
|
@@ -223,7 +243,9 @@ namespace GFGGame
|
|
|
gObject.name = "item" + i;
|
|
|
gObject.onClick.Add(OnItemClick);
|
|
|
_ui.m_items.target.AddChild(gObject);
|
|
|
+ UI_item item = UI_item.Proxy(gObject);
|
|
|
_items.Add(gObject);
|
|
|
+ UI_item.ProxyEnd();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -240,7 +262,8 @@ namespace GFGGame
|
|
|
_ui.m_items.target.touchable = true;
|
|
|
if (CheckWin())
|
|
|
{
|
|
|
- Win();
|
|
|
+ _ui.m_maskGlobal.visible = true;
|
|
|
+ Win(cancellationTokenSource.Token);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -358,8 +381,16 @@ namespace GFGGame
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private void Win()
|
|
|
+ private async Task Win(CancellationToken cancellationToken)
|
|
|
{
|
|
|
+ await Task.Delay(200, cancellationToken);
|
|
|
+ blankItem.visible = true;
|
|
|
+ blankItem.position = _gridArr[0, 0].pos;
|
|
|
+ UI_item item = UI_item.Proxy(blankItem);
|
|
|
+ item.m_icon.url = string.Format("ui://ActivityHuaRongDao/hrd_1-{0}", 1);
|
|
|
+ UI_item.ProxyEnd();
|
|
|
+ await Task.Delay(400, cancellationToken);
|
|
|
+
|
|
|
// 关卡推进
|
|
|
int passLevel = cfg.resArr[0];
|
|
|
ActivityHuaRongDaoEntryView.curLevel = Mathf.Max(passLevel, ActivityHuaRongDaoEntryView.curLevel);
|
|
@@ -368,6 +399,7 @@ namespace GFGGame
|
|
|
ViewManager.Show<ActivityHuaRongDaoSuccessView>(cfg);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private int countDownNum;
|
|
|
private void Countdown(object param)
|
|
|
{
|
|
@@ -406,5 +438,114 @@ namespace GFGGame
|
|
|
Hide();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private async Task StartAnimation(CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _ui.m_hideMask.Play();
|
|
|
+ _ui.m_maskGlobal.visible = true;
|
|
|
+ List<int> numList = CreateIncreaseArr();
|
|
|
+ SetGridInfo(numList);
|
|
|
+ InitItems();
|
|
|
+ CreateOriginPic();
|
|
|
+
|
|
|
+ // 隐藏所有
|
|
|
+ UI_item item;
|
|
|
+ for (int i = 0; i < _items.Count; i++)
|
|
|
+ {
|
|
|
+ item = UI_item.Proxy(_items[i]);
|
|
|
+ item.m_hide.Play();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 入场
|
|
|
+ for (int i = 0; i < _items.Count; i++)
|
|
|
+ {
|
|
|
+ item = UI_item.Proxy(_items[i]);
|
|
|
+ item.m_show.Play();
|
|
|
+ await Task.Delay(100, cancellationToken);
|
|
|
+ }
|
|
|
+ UI_item.ProxyEnd();
|
|
|
+
|
|
|
+ // 出现白色遮罩,刷新数组
|
|
|
+ await Task.Delay(900, cancellationToken);
|
|
|
+ _ui.m_showMask.Play(() =>
|
|
|
+ {
|
|
|
+ _ui.m_maskGlobal.visible = false;
|
|
|
+ _ui.m_hideMask.Play();
|
|
|
+ _gameStart = true;
|
|
|
+ });
|
|
|
+
|
|
|
+ await Task.Delay(200, cancellationToken);
|
|
|
+ numList = GetArrByConfigStep(cfg.step);
|
|
|
+ while (CheckListCorrect(numList))
|
|
|
+ {
|
|
|
+ numList = GetArrByConfigStep(cfg.step);
|
|
|
+ }
|
|
|
+ SetGridInfo(numList);
|
|
|
+ InitItems();
|
|
|
+ }
|
|
|
+
|
|
|
+ catch (TaskCanceledException)
|
|
|
+ {
|
|
|
+ //Debug.Log("异步函数被停止");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取消异步函数
|
|
|
+ public void StopMyAsyncFunction()
|
|
|
+ {
|
|
|
+ if (cancellationTokenSource != null)
|
|
|
+ {
|
|
|
+ cancellationTokenSource.Cancel();
|
|
|
+ cancellationTokenSource.Dispose();
|
|
|
+ cancellationTokenSource = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 创建原图
|
|
|
+ /// </summary>
|
|
|
+ private void CreateOriginPic()
|
|
|
+ {
|
|
|
+ List<GObject> items = new List<GObject>();
|
|
|
+ for (int i = 1; i <= _gridNum * _gridNum; i++)
|
|
|
+ {
|
|
|
+ GObject gObject = UIPackage.CreateObject("ActivityHuaRongDao", "item");
|
|
|
+ _ui.m_itemsOrigin.target.AddChild(gObject);
|
|
|
+ items.Add(gObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ int itemIndex = 0;
|
|
|
+ for (int i = 0; i < _gridNum; i++)
|
|
|
+ {
|
|
|
+ for (int j = 0; j < _gridNum; j++)
|
|
|
+ {
|
|
|
+ items[itemIndex].position = _gridArr[i, j].pos;
|
|
|
+ UI_item item = UI_item.Proxy(items[itemIndex]);
|
|
|
+ item.m_index.text = _gridArr[i, j].num.ToString();
|
|
|
+ item.m_icon.url = string.Format("ui://ActivityHuaRongDao/hrd_1-{0}", _gridArr[i, j].num + 1);
|
|
|
+ UI_item.ProxyEnd();
|
|
|
+ ++itemIndex;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnClickBtnShowOriginPic()
|
|
|
+ {
|
|
|
+ _ui.m_items.target.visible = false;
|
|
|
+ _ui.m_itemsOrigin.target.visible = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnClickBtnHideOriginPic()
|
|
|
+ {
|
|
|
+ _ui.m_items.target.visible = true;
|
|
|
+ _ui.m_itemsOrigin.target.visible = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnClickBtnRefresh()
|
|
|
+ {
|
|
|
+ StartAnimation(cancellationTokenSource.Token);
|
|
|
+ }
|
|
|
}
|
|
|
}
|