备份CatanBuilding瘦身独立工程
This commit is contained in:
86
Assets/Scripts/UI/SmallGame/BombBuilding.cs
Normal file
86
Assets/Scripts/UI/SmallGame/BombBuilding.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using asap.core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using UniRx;
|
||||
using TMPro;
|
||||
using GameCore;
|
||||
using DG.Tweening;
|
||||
|
||||
public class BombBuilding : MonoBehaviour
|
||||
{
|
||||
System.IDisposable disposable;
|
||||
public Transform[] bombPos;
|
||||
public PlayableDirector[] bombClip;
|
||||
public CannonRoot cannonRoot;
|
||||
|
||||
int posCount = 10;
|
||||
private void Awake()
|
||||
{
|
||||
cannonRoot = GetComponentInChildren<CannonRoot>();
|
||||
disposable = GContext.OnEvent<BombBuildingDataEvent>().Subscribe(OnBombBuildingDataEvent);
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
cannonRoot.virtualCamera1.gameObject.SetActive(false);
|
||||
cannonRoot.shell.gameObject.SetActive(false);
|
||||
if (GContext.container.Resolve<PlayerData>().GetMagnification() > 1)
|
||||
{
|
||||
cannonRoot.text_beilv.text = $"x{GContext.container.Resolve<PlayerData>().GetMagnification()}";
|
||||
}
|
||||
else
|
||||
{
|
||||
cannonRoot.text_beilv.text = "";
|
||||
}
|
||||
}
|
||||
void OnBombBuildingDataEvent(BombBuildingDataEvent e)
|
||||
{
|
||||
if (e.index >= 0)
|
||||
{
|
||||
ShellPlay(e.index);
|
||||
}
|
||||
else if (e.index == -1)
|
||||
{
|
||||
e.bombBuilding = this;
|
||||
e.bombPos = bombPos;
|
||||
}
|
||||
else if (e.index == -2)
|
||||
{
|
||||
cannonRoot.cannon.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
public async void ShellPlay(int index)
|
||||
{
|
||||
Vector3 targetPos = bombPos[index].position;
|
||||
Vector3 position = new Vector3(targetPos.x, cannonRoot.cannon.position.y, targetPos.z);
|
||||
cannonRoot.cannon.DOLookAt(position, 0.5f);
|
||||
cannonRoot.fire.Play();
|
||||
cannonRoot.MoveCamera();
|
||||
await Awaiters.Seconds(cannonRoot.shellShowStay);
|
||||
Vector3 startPos = cannonRoot.shellStartPos.position;
|
||||
cannonRoot.shell.position = startPos;
|
||||
cannonRoot.shell.gameObject.SetActive(true);
|
||||
Vector3[] linePoints = new Vector3[3];
|
||||
linePoints[0] = targetPos;
|
||||
linePoints[1] = new Vector3(targetPos.x, startPos.y, targetPos.z);
|
||||
linePoints[2] = startPos;
|
||||
if (cannonRoot.cameraDuration > cannonRoot.duration * cannonRoot.durationRatio)
|
||||
{
|
||||
cannonRoot.cameraDuration = cannonRoot.duration * cannonRoot.durationRatio;
|
||||
}
|
||||
cannonRoot.shell.DOPath(linePoints, cannonRoot.duration, PathType.CubicBezier, PathMode.Ignore, posCount, Color.red).SetEase(Ease.Linear);
|
||||
cannonRoot.shellSub.DOScale(cannonRoot.shellScaleValue, cannonRoot.duration).SetEase(cannonRoot.shellScaleCurve);
|
||||
await Awaiters.Seconds(cannonRoot.duration * cannonRoot.durationRatio);
|
||||
cannonRoot.virtualCamera1.SetParent(transform);
|
||||
cannonRoot.virtualCamera1.GetComponent<DOTweenAnimation>().DORestart();
|
||||
cannonRoot.shell.gameObject.SetActive(false);
|
||||
bombClip[index].Play();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (disposable != null)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user