备份CatanBuilding瘦身独立工程
This commit is contained in:
228
Assets/Scripts/Duel/UI/DuelRandomMapPanel.cs
Normal file
228
Assets/Scripts/Duel/UI/DuelRandomMapPanel.cs
Normal file
@@ -0,0 +1,228 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using GameCore;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DuelRandomMapPanel : MonoBehaviour
|
||||
{
|
||||
public Transform arrow1;
|
||||
public Transform arrow2;
|
||||
public float StartDelay = 0.5f;
|
||||
public float StartDuration = 0.4f;
|
||||
public int AccNum = 4;
|
||||
public float LoopDuration = 0.2f;
|
||||
/*
|
||||
* 选定阶段
|
||||
在[0, 1]之间选一个参数,然后如下的3个参数都取相同的比例:
|
||||
间隔多少张图:SelectedMapNumRand = [2,5]
|
||||
回弹:最后一张图的回弹比例,必须大于0,[0.2, 0.4]
|
||||
二次回弹:弹回去之后[0, 0.1]
|
||||
回弹速度:在这段时间内,整体速度逐渐变成0
|
||||
*/
|
||||
public int[] SelectedMapNumRand = new[] { 2, 5 };
|
||||
public float[] BackRatioRand = new[] { 0.2f, 0.4f };
|
||||
public float[] SecondBackRatioRand = new[] { 0f, 0.1f };
|
||||
public int[] ArrowRotationRand = new[] { 10, 15 };
|
||||
int MapNum = 2;
|
||||
float BackRatio;
|
||||
float SecondBackRatio;
|
||||
|
||||
FishingDuelManager FDM;
|
||||
RectTransform Content;
|
||||
GameObject img_map;
|
||||
int allCount = 5;
|
||||
float height;
|
||||
IUIService uIService;
|
||||
|
||||
GameObject text_title;
|
||||
TMP_Text text_map;
|
||||
Tables _tables;
|
||||
List<MapData> mapDatas;
|
||||
List<int> newIDs;
|
||||
bool isClose;
|
||||
[HideInInspector]
|
||||
public bool IsStop;
|
||||
private void Awake()
|
||||
{
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
uIService = GContext.container.Resolve<IUIService>();
|
||||
FDM = GContext.container.Resolve<FishingDuelManager>();
|
||||
Content = transform.Find("Viewport/Content").GetComponent<RectTransform>();
|
||||
img_map = transform.Find("Viewport/Content/Item").gameObject;
|
||||
height = img_map.GetComponent<RectTransform>().rect.height;
|
||||
img_map.SetActive(false);
|
||||
|
||||
text_title = transform.Find("title").gameObject;
|
||||
text_map = transform.Find("title/text_map").GetComponent<TMP_Text>();
|
||||
}
|
||||
|
||||
public void StartMap()
|
||||
{
|
||||
float t = Random.Range(0f, 1f);
|
||||
MapNum = Mathf.RoundToInt(SelectedMapNumRand[0] + (SelectedMapNumRand[1] - SelectedMapNumRand[0]) * t);
|
||||
BackRatio = BackRatioRand[0] + (BackRatioRand[1] - BackRatioRand[0]) * t;
|
||||
SecondBackRatio = SecondBackRatioRand[0] + (SecondBackRatioRand[1] - SecondBackRatioRand[0]) * t;
|
||||
|
||||
IsStop = false;
|
||||
text_title.SetActive(false);
|
||||
isClose = false;
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
var lastMapID = GContext.container.Resolve<PlayerData>().lastMapId;
|
||||
mapDatas = _tables.TbMapData.DataList;
|
||||
List<int> indexs = new List<int>
|
||||
{
|
||||
0,1
|
||||
};
|
||||
for (int i = 2; i < mapDatas.Count; i++)
|
||||
{
|
||||
if (mapDatas[i].ID <= lastMapID)
|
||||
{
|
||||
indexs.Insert(Random.Range(0, indexs.Count), i);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (indexs.Count < allCount + MapNum)
|
||||
{
|
||||
indexs.AddRange(indexs);
|
||||
}
|
||||
|
||||
newIDs = indexs;
|
||||
for (int i = 0; i < allCount; i++)
|
||||
{
|
||||
SetMapBg(mapDatas[newIDs[i]].Bg);
|
||||
}
|
||||
SetMapBg(mapDatas[newIDs[0]].Bg);
|
||||
for (int i = 0; i < MapNum - 1; i++)
|
||||
{
|
||||
SetMapBg(mapDatas[newIDs[allCount + i]].Bg);
|
||||
}
|
||||
StartCoroutine(Play());
|
||||
}
|
||||
public void SetClose()
|
||||
{
|
||||
int mapId = FDM.MapId;
|
||||
var mapData = _tables.TbMapData.DataMap[mapId];
|
||||
SetMapBg(mapData.Bg);
|
||||
SetMapBg(mapDatas[newIDs[0]].Bg);
|
||||
text_map.text = LocalizationMgr.GetText(mapData.Name_l10n_key);
|
||||
isClose = true;
|
||||
//Content.DOKill();
|
||||
//Content.anchoredPosition = new Vector2(0, allCount * height);
|
||||
//StartCoroutine(Close());
|
||||
//FDM.SetMapId(mapId);
|
||||
}
|
||||
void SetMapBg(string bg)
|
||||
{
|
||||
GameObject go = Instantiate(img_map, Content);
|
||||
Image image = go.transform.GetChild(0).GetComponent<Image>();
|
||||
go.SetActive(true);
|
||||
uIService.SetImageSprite(image, bg);
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
Content.DOKill();
|
||||
}
|
||||
IEnumerator PlayArrow()
|
||||
{
|
||||
int cur = 1;
|
||||
float acc = (StartDuration - LoopDuration) / AccNum;
|
||||
float time = StartDuration;
|
||||
float arrowTime = time / 4;
|
||||
int ArrowRotation = Random.Range(ArrowRotationRand[0], ArrowRotationRand[1]);
|
||||
arrow1.DOLocalRotate(new Vector3(0, 0, ArrowRotation), arrowTime);
|
||||
arrow2.DOLocalRotate(new Vector3(0, 0, -ArrowRotation), arrowTime);
|
||||
yield return new WaitForSeconds(arrowTime);
|
||||
arrowTime = time / 4;
|
||||
while (cur < AccNum)
|
||||
{
|
||||
cur++;
|
||||
time -= acc;
|
||||
arrowTime = arrowTime + time / 4;
|
||||
ArrowRotation = Random.Range(ArrowRotationRand[0], ArrowRotationRand[1]);
|
||||
arrow1.DOLocalRotate(new Vector3(0, 0, -ArrowRotation), arrowTime);
|
||||
arrow2.DOLocalRotate(new Vector3(0, 0, ArrowRotation), arrowTime);
|
||||
yield return new WaitForSeconds(arrowTime);
|
||||
arrowTime = time / 2;
|
||||
ArrowRotation = Random.Range(ArrowRotationRand[0], ArrowRotationRand[1]);
|
||||
arrow1.DOLocalRotate(new Vector3(0, 0, ArrowRotation), arrowTime);
|
||||
arrow2.DOLocalRotate(new Vector3(0, 0, -ArrowRotation), arrowTime);
|
||||
yield return new WaitForSeconds(arrowTime);
|
||||
arrowTime = time / 4;
|
||||
}
|
||||
while (!IsStop)
|
||||
{
|
||||
arrowTime = LoopDuration / 2;
|
||||
ArrowRotation = Random.Range(ArrowRotationRand[0], ArrowRotationRand[1]);
|
||||
arrow1.DOLocalRotate(new Vector3(0, 0, -ArrowRotation), arrowTime);
|
||||
arrow2.DOLocalRotate(new Vector3(0, 0, ArrowRotation), arrowTime);
|
||||
yield return new WaitForSeconds(arrowTime);
|
||||
arrowTime = LoopDuration / 2;
|
||||
ArrowRotation = Random.Range(ArrowRotationRand[0], ArrowRotationRand[1]);
|
||||
arrow1.DOLocalRotate(new Vector3(0, 0, ArrowRotation), arrowTime);
|
||||
arrow2.DOLocalRotate(new Vector3(0, 0, -ArrowRotation), arrowTime);
|
||||
yield return new WaitForSeconds(arrowTime);
|
||||
}
|
||||
}
|
||||
Coroutine playArrow;
|
||||
IEnumerator Play()
|
||||
{
|
||||
Content.anchoredPosition = Vector2.zero;
|
||||
yield return new WaitForSeconds(StartDelay);
|
||||
int cur = 0;
|
||||
float acc = (StartDuration - LoopDuration) / AccNum;
|
||||
float time = StartDuration;
|
||||
playArrow = StartCoroutine(PlayArrow());
|
||||
while (cur < AccNum)
|
||||
{
|
||||
cur++;
|
||||
Content.DOAnchorPosY(cur * height, time).SetEase(Ease.Linear);
|
||||
yield return new WaitForSeconds(time);
|
||||
time -= acc;
|
||||
}
|
||||
time = LoopDuration * (allCount - cur);
|
||||
Content.DOAnchorPosY(allCount * height, time).SetEase(Ease.Linear);
|
||||
yield return new WaitForSeconds(time);
|
||||
|
||||
time = LoopDuration * allCount;
|
||||
while (!isClose)
|
||||
{
|
||||
Content.anchoredPosition = Vector2.zero;
|
||||
Content.DOAnchorPosY(allCount * height, time).SetEase(Ease.Linear);
|
||||
yield return new WaitForSeconds(time);
|
||||
}
|
||||
StartCoroutine(Close());
|
||||
}
|
||||
IEnumerator Close()
|
||||
{
|
||||
var sequence = DOTween.Sequence();
|
||||
//跑马灯动画
|
||||
float index2 = allCount + MapNum + BackRatio;
|
||||
float time1 = (BackRatio + MapNum) * LoopDuration;
|
||||
float time2 = SecondBackRatio;
|
||||
|
||||
sequence.Append(Content.DOAnchorPosY(index2 * height, time1).SetEase(Ease.Linear));
|
||||
sequence.Append(Content.DOAnchorPosY((allCount + MapNum) * height, time2).SetEase(Ease.InSine));
|
||||
sequence.Play();
|
||||
yield return new WaitForSeconds(time1);
|
||||
StopCoroutine(playArrow);
|
||||
arrow1.DOKill();
|
||||
arrow2.DOKill();
|
||||
arrow1.DOLocalRotate(new Vector3(0, 0, 0), time2);
|
||||
arrow2.DOLocalRotate(new Vector3(0, 0, 0), time2);
|
||||
yield return new WaitForSeconds(time2);
|
||||
IsStop = true;
|
||||
GContext.Publish(new VibrationData(HapticTypes.HeavyImpact));
|
||||
text_title.SetActive(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user