备份CatanBuilding瘦身独立工程
This commit is contained in:
97
Assets/Scripts/GampPlay/Fishing/HandPosController.cs
Normal file
97
Assets/Scripts/GampPlay/Fishing/HandPosController.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using asap.core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UniRx;
|
||||
|
||||
public enum ERightState
|
||||
{
|
||||
Idle,
|
||||
Throwing,
|
||||
Waiting,
|
||||
Piercing,
|
||||
Drawing,
|
||||
Pulling,
|
||||
Preparing,
|
||||
Noviceguide,
|
||||
MaxCombo,
|
||||
Shock,
|
||||
PiercingSp,
|
||||
}
|
||||
[Serializable]
|
||||
public class RightState
|
||||
{
|
||||
public ERightState state;
|
||||
public float time;
|
||||
public Vector3 pos;
|
||||
}
|
||||
|
||||
public class HandPosController : MonoBehaviour
|
||||
{
|
||||
[Header("专为钓场钓鱼使用,其他场景不再初始化")]
|
||||
public List<RightState> RightStateDic;
|
||||
public ERightState curERightState;
|
||||
Coroutine coroutine;
|
||||
IDisposable disposable;
|
||||
bool isInFishingAct = false;
|
||||
private void Awake()
|
||||
{
|
||||
IAct act = GContext.container.ResolveAct("ShooterFishAct");
|
||||
isInFishingAct = act == null;
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
if (isInFishingAct)
|
||||
{
|
||||
disposable = GContext.OnEvent<ERightState>().Subscribe(SetRightStateDic);
|
||||
SetRightStateDic(ERightState.Preparing);
|
||||
}
|
||||
}
|
||||
public void SetRightStateDic(ERightState state)
|
||||
{
|
||||
RightState rightState = null;
|
||||
foreach (var item in RightStateDic)
|
||||
{
|
||||
if (item.state == state)
|
||||
{
|
||||
rightState = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rightState != null)
|
||||
{
|
||||
if (coroutine != null)
|
||||
{
|
||||
StopCoroutine(coroutine);
|
||||
}
|
||||
coroutine = StartCoroutine(SetRightHandTarget(rightState));
|
||||
}
|
||||
}
|
||||
IEnumerator SetRightHandTarget(RightState rightState)
|
||||
{
|
||||
curERightState = rightState.state;
|
||||
Vector3 pos = rightState.pos;
|
||||
Vector3 starPos = transform.localPosition;
|
||||
float time = rightState.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