95 lines
2.2 KiB
C#
95 lines
2.2 KiB
C#
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,
|
|
CaptureEnd,
|
|
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;
|
|
}
|
|
}
|