备份CatanBuilding瘦身独立工程
This commit is contained in:
93
Assets/Scripts/GampPlay/Fishing/HandPosShootController.cs
Normal file
93
Assets/Scripts/GampPlay/Fishing/HandPosShootController.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using asap.core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UniRx;
|
||||
|
||||
public enum EShootState
|
||||
{
|
||||
Appear,
|
||||
Idle,
|
||||
Aim,
|
||||
Back,
|
||||
Shoot,
|
||||
Capture,
|
||||
Escape,
|
||||
}
|
||||
[Serializable]
|
||||
public class ShootState
|
||||
{
|
||||
public EShootState state;
|
||||
public float time;
|
||||
public Vector3 pos;
|
||||
}
|
||||
public class HandPosShootController : MonoBehaviour
|
||||
{
|
||||
[Header("专为射场射鱼使用,其他场景不再初始化")]
|
||||
|
||||
public List<ShootState> ShootStateDic;
|
||||
public EShootState curEShootState;
|
||||
Coroutine coroutine;
|
||||
IDisposable disposable;
|
||||
bool isInShooterFishAct = false;
|
||||
private void Awake()
|
||||
{
|
||||
IAct act = GContext.container.ResolveAct("ShooterFishAct");
|
||||
isInShooterFishAct = act != null;
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
if (isInShooterFishAct)
|
||||
{
|
||||
disposable = GContext.OnEvent<EShootState>().Subscribe(SetShootStateDic);
|
||||
SetShootStateDic(EShootState.Appear);
|
||||
}
|
||||
}
|
||||
public void SetShootStateDic(EShootState state)
|
||||
{
|
||||
ShootState ShootState = null;
|
||||
foreach (var item in ShootStateDic)
|
||||
{
|
||||
if (item.state == state)
|
||||
{
|
||||
ShootState = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ShootState != null)
|
||||
{
|
||||
if (coroutine != null)
|
||||
{
|
||||
StopCoroutine(coroutine);
|
||||
}
|
||||
coroutine = StartCoroutine(SetRightHandTarget(ShootState));
|
||||
}
|
||||
}
|
||||
IEnumerator SetRightHandTarget(ShootState ShootState)
|
||||
{
|
||||
curEShootState = ShootState.state;
|
||||
Vector3 pos = ShootState.pos;
|
||||
Vector3 starPos = transform.localPosition;
|
||||
float time = ShootState.time;
|
||||
float timer = 0;
|
||||
if (time > 0.01)
|
||||
{
|
||||
while (timer < time)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
transform.localPosition = Vector3.Lerp(starPos, pos, timer / time);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localPosition = pos;
|
||||
}
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
disposable?.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user