备份CatanBuilding瘦身独立工程
This commit is contained in:
204
Assets/Scripts/SupplyDrop/SupplyDropCashGameRoot.cs
Normal file
204
Assets/Scripts/SupplyDrop/SupplyDropCashGameRoot.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using DG.Tweening;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
public class SupplyDropCashGameRoot : MonoBehaviour
|
||||
{
|
||||
public SupplyDropItemCashGun gun;
|
||||
public GameObject GrabCashTextReady;
|
||||
public GameObject GrabCashTextTitle;
|
||||
public Transform[] posFlyEndLeft;
|
||||
public Transform[] posFlyEndRight;
|
||||
public List<GameObject> cashs = new List<GameObject>();
|
||||
public GameObject cashNum;
|
||||
public List<SupplyDropCashEmitter> cashPosList = new List<SupplyDropCashEmitter>();
|
||||
public SupplyDropCashEmitter pos_start;
|
||||
public float CashGunFlyTime = 0.45f;
|
||||
public Vector3 CashGunFlyPos = new(0, -1.5f, 3f);
|
||||
|
||||
//钞票枪发射阶段
|
||||
public float PlaySprayStartDelay = 0.533f;
|
||||
public float PlaySprayDuration = 1.5f;
|
||||
public float PlaySprayCashFlyTime = 1f;
|
||||
public float PlaySprayCashInterval = 0.066f;
|
||||
public AnimationCurve PlayCashSprayAnimationCurve = AnimationCurve.Linear(0, 0, 1, 1);
|
||||
|
||||
//下落表现阶段
|
||||
public float PlayCashFallStartDelay = 0.8f;
|
||||
public float PlayCashFallDuration = 2f;
|
||||
|
||||
//抓钞票阶段
|
||||
public float PlayFallToGrabDelay = 2;
|
||||
public float GameDuration = 7.5f;
|
||||
public float GrabCashDelay = 0.5f;
|
||||
|
||||
|
||||
public float PlayUITitleDelay = 0.1f;
|
||||
public float PlayUIReadyDelay = 2.5f;
|
||||
|
||||
float allWeight = 0f;
|
||||
List<float> weightList = new List<float>();
|
||||
List<int> dropCount = new List<int>();
|
||||
SupplyDropGameplayCashCtrl ctrl;
|
||||
|
||||
public void Init(SupplyDropGameplayCashCtrl ctrl,
|
||||
Vector3 startPos,
|
||||
float allWeight,
|
||||
List<float> weightList,
|
||||
List<int> dropCount)
|
||||
{
|
||||
gun.gameObject.SetActive(true);
|
||||
gun.transform.position = startPos;
|
||||
GunMove();
|
||||
this.ctrl = ctrl;
|
||||
this.allWeight = allWeight;
|
||||
this.weightList = weightList;
|
||||
this.dropCount = dropCount;
|
||||
ShowUI();
|
||||
}
|
||||
|
||||
void GunMove()
|
||||
{
|
||||
gun.transform.DOMove(CashGunFlyPos, CashGunFlyTime);
|
||||
|
||||
}
|
||||
|
||||
async void ShowUI()
|
||||
{
|
||||
await Awaiters.Seconds(PlayUITitleDelay);
|
||||
GrabCashTextTitle.SetActive(true);
|
||||
await Awaiters.Seconds(PlayUIReadyDelay);
|
||||
GrabCashTextReady.SetActive(true);
|
||||
}
|
||||
|
||||
public async Task IntialStage()
|
||||
{
|
||||
//开始发射钞票
|
||||
PlaySpray();
|
||||
//开始降落钞票
|
||||
await PlayCashFall();
|
||||
}
|
||||
|
||||
public async Task StartPlay()
|
||||
{
|
||||
await Awaiters.Seconds(GrabCashDelay);
|
||||
for (int i = 0; i < cashPosList.Count; i++)
|
||||
{
|
||||
SupplyDropCashEmitter emitter = cashPosList[i];
|
||||
emitter.StartPlay(ctrl, allWeight, weightList, dropCount);
|
||||
}
|
||||
|
||||
await Awaiters.Seconds(GameDuration);
|
||||
|
||||
for (int i = 0; i < cashPosList.Count; i++)
|
||||
{
|
||||
SupplyDropCashEmitter emitter = cashPosList[i];
|
||||
emitter.StopAllCoroutines();
|
||||
}
|
||||
}
|
||||
|
||||
async Task PlaySpray()
|
||||
{
|
||||
await Awaiters.Seconds(PlaySprayStartDelay);
|
||||
float sprayTime = 0;
|
||||
int type = 0;
|
||||
while (sprayTime < PlaySprayDuration)
|
||||
{
|
||||
sprayTime += 0.1f;
|
||||
type = UnityEngine.Random.Range(0, cashs.Count);
|
||||
SupplyDropCashItem item = ctrl.GetCashItem(type);
|
||||
if (item != null)
|
||||
{
|
||||
Vector3 posW = gun.Point01.position;
|
||||
item.gameObject.name = $"Cash_UP_{type}";
|
||||
item.transform.position = posW;
|
||||
item.PlayAni(1); // 随机播放动画
|
||||
item.gameObject.SetActive(true);
|
||||
//item.transform.rotation = point01.rotation;
|
||||
if (posFlyEndLeft.Length > 1)
|
||||
{
|
||||
float x = Random.Range(posFlyEndLeft[0].position.x, posFlyEndLeft[1].position.x);
|
||||
float y = Random.Range(posFlyEndLeft[0].position.y, posFlyEndLeft[1].position.y);
|
||||
float z = Random.Range(posFlyEndLeft[0].position.z, posFlyEndLeft[1].position.z);
|
||||
posW.x = x;
|
||||
posW.y = y;
|
||||
posW.z = z;
|
||||
}
|
||||
item.transform.DOMove(posW, PlaySprayCashFlyTime)
|
||||
.SetEase(PlayCashSprayAnimationCurve)
|
||||
.OnComplete(() => ctrl.Recycle(item));
|
||||
}
|
||||
SupplyDropCashItem item2 = ctrl.GetCashItem(type);
|
||||
if (item2 != null)
|
||||
{
|
||||
Vector3 posW = gun.Point02.position;
|
||||
item2.gameObject.name = $"Cash_UP_{type}";
|
||||
item2.transform.position = posW;
|
||||
item2.PlayAni(1); // 随机播放动画
|
||||
item2.gameObject.SetActive(true);
|
||||
//item2.transform.rotation = point02.rotation;
|
||||
|
||||
if (posFlyEndRight.Length > 1)
|
||||
{
|
||||
float x = Random.Range(posFlyEndRight[0].position.x, posFlyEndRight[1].position.x);
|
||||
float y = Random.Range(posFlyEndRight[0].position.y, posFlyEndRight[1].position.y);
|
||||
float z = Random.Range(posFlyEndRight[0].position.z, posFlyEndRight[1].position.z);
|
||||
posW.x = x;
|
||||
posW.y = y;
|
||||
posW.z = z;
|
||||
}
|
||||
|
||||
item2.transform.DOMove(posW, PlaySprayCashFlyTime)
|
||||
.SetEase(PlayCashSprayAnimationCurve)
|
||||
.OnComplete(() => ctrl.Recycle(item2));
|
||||
}
|
||||
await Awaiters.Seconds(PlaySprayCashInterval);
|
||||
}
|
||||
}
|
||||
async Task PlayCashFall()
|
||||
{
|
||||
await Awaiters.Seconds(PlayCashFallStartDelay);
|
||||
float cashFallTime = 0;
|
||||
int type = 0;
|
||||
while (cashFallTime < PlayCashFallDuration)
|
||||
{
|
||||
await Awaiters.Seconds(pos_start.emissionInterval);
|
||||
cashFallTime += pos_start.emissionInterval;
|
||||
for (int i = 0; i < pos_start.emissionCount; i++)
|
||||
{
|
||||
type = UnityEngine.Random.Range(0, cashs.Count);
|
||||
SupplyDropCashItem item = ctrl.GetCashItem(type);
|
||||
if (item != null)
|
||||
{
|
||||
item.gameObject.name = $"Cash_Down_{type}";
|
||||
item.gameObject.SetActive(true);
|
||||
if (pos_start.FlyIndexStart < pos_start.FlyIndexEnd)
|
||||
{
|
||||
item.PlayAni(UnityEngine.Random.Range(pos_start.FlyIndexStart, pos_start.FlyIndexEnd + 1)); // 随机播放动画
|
||||
}
|
||||
else
|
||||
{
|
||||
item.PlayAni(pos_start.FlyIndexStart); // 随机播放动画
|
||||
}
|
||||
item.transform.position = pos_start.transform.position;
|
||||
item.transform.DOMove(pos_start.GetTargetAreaPos(),
|
||||
pos_start.flyTime)
|
||||
.SetEase(PlayCashSprayAnimationCurve)
|
||||
.OnComplete(() => ctrl.Recycle(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
await Awaiters.Seconds(PlayFallToGrabDelay);
|
||||
}
|
||||
|
||||
public GameObject InstantiateItem(int type)
|
||||
{
|
||||
return Instantiate(cashs[type], transform);
|
||||
}
|
||||
|
||||
public GameObject InstantiateNumItem()
|
||||
{
|
||||
return Instantiate(cashNum, transform);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user