using Snxxz.UI;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
public class GuardRun : SMB_Base
|
{
|
[HideInInspector]
|
public Vector3 nextPosition;
|
private Vector3 lastPosition;
|
private SFXController _sfXctl;
|
private float m_Time;
|
private float guardClosingTime = 0;
|
private List<int> dropItemList = new List<int>();
|
private GA_Guard guard;
|
private float m_PickUpPackTime = 0;
|
private float m_PickUpDelayTime = 1.0f;
|
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
protected override void OnEnter(GActor owner, Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
{
|
base.OnEnter(owner, animator, stateInfo, layerIndex);
|
guard = owner as GA_Guard;
|
if (guard == null)
|
{
|
return;
|
}
|
if (_sfXctl == null)
|
{
|
var mountPoint = guard.Root.GetChildTransformDeeply(GAStaticDefine.MountPointBoneName);
|
_sfXctl = SFXPlayUtility.Instance.PlayBattleEffect(guard.guardEffects[1], owner);
|
if (_sfXctl != null)
|
{
|
_sfXctl.duration = 0;
|
_sfXctl.transform.SetParent(mountPoint);
|
_sfXctl.transform.localPosition = Vector3.zero;
|
}
|
}
|
else
|
{
|
_sfXctl.SetActive(true);
|
}
|
|
m_Time = 0;
|
switch (guard.guardState)
|
{
|
case GA_Guard.GuardState.Track:
|
{
|
}
|
break;
|
case GA_Guard.GuardState.Dance:
|
{
|
}
|
break;
|
case GA_Guard.GuardState.Inter:
|
{
|
if (guard.targetPlayer == null)
|
{
|
return;
|
}
|
nextPosition = guard.targetPlayer.Root.position.SetY(0);
|
lastPosition = guard.Root.position;
|
guard.Forward = nextPosition - guard.Root.position;
|
guardClosingTime = Vector3.Distance(nextPosition, guard.Root.position) / guard.GuardianSpeed;
|
}
|
break;
|
case GA_Guard.GuardState.PickUp:
|
{
|
OnPickUpEnter();
|
}
|
break;
|
}
|
}
|
|
public void OnPickUpEnter()
|
{
|
m_PickUpPackTime = 0.0f;
|
DTC0702_tagDropItemDisappear.OnDropItemDisapperEvent -= OnDropItemDisapperEvent;
|
DTC0702_tagDropItemDisappear.OnDropItemDisapperEvent += OnDropItemDisapperEvent;
|
OnDropItemDisapperEvent();
|
}
|
|
private void OnDropItemDisapperEvent()
|
{
|
if (guard == null)
|
{
|
return;
|
}
|
dropItemList.Clear();
|
DropItemManager.TryGetGuardPickUpItem(guard, ref dropItemList);
|
dropItemList.Sort(Compare);
|
RequestDropItem();
|
}
|
|
protected override void OnExit(GActor owner, Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
{
|
base.OnExit(owner, animator, stateInfo, layerIndex);
|
ReleaseSFX();
|
DTC0702_tagDropItemDisappear.OnDropItemDisapperEvent -= OnDropItemDisapperEvent;
|
guard = null;
|
}
|
|
protected override void OnUpdate(GActor owner, Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
{
|
base.OnUpdate(owner, animator, stateInfo, layerIndex);
|
if (owner == null || guard == null)
|
{
|
return;
|
}
|
var hero = guard.targetPlayer;
|
if (guard.targetPlayer == null)
|
{
|
return;
|
}
|
switch (guard.guardState)
|
{
|
case GA_Guard.GuardState.Idle:
|
break;
|
case GA_Guard.GuardState.Track:
|
{
|
var _heroPos = hero.Root.position;
|
if (MathUtility.CalDistance(guard.Root.position, _heroPos) > guard.GuardianImpendRange * guard.GuardianImpendRange)
|
{
|
guard.Root.LookAt(new Vector3(_heroPos.x, _heroPos.y + guard.GuardianHeight, _heroPos.z));
|
guard.Root.Translate(Vector3.forward * hero.ActorInfo.moveSpeed * Time.deltaTime);
|
}
|
else
|
{
|
guard.Idle();
|
}
|
}
|
break;
|
case GA_Guard.GuardState.Dance:
|
{
|
var _heroPos = hero.Root.position;
|
nextPosition = _heroPos + hero.Root.right.normalized * 0.6f - hero.Forward * 0.3f;
|
nextPosition.y = _heroPos.y + guard.GuardianHeight;
|
var dis = Vector3.Distance(nextPosition, guard.Root.position);
|
if (dis > 0.1f)
|
{
|
guard.Forward = nextPosition - guard.Root.position;
|
var deltapos = Vector3.Lerp(guard.Root.position, nextPosition, hero.ActorInfo.moveSpeed * Time.deltaTime);
|
guard.Root.position = deltapos;
|
}
|
else
|
{
|
guard.Forward = hero.Forward;
|
guard.NextAction = GA_Guard.GuardAction_Dance2;
|
}
|
}
|
break;
|
case GA_Guard.GuardState.Inter:
|
{
|
m_Time += Time.deltaTime;
|
guard.Root.position = Vector3.Lerp(lastPosition, nextPosition, Mathf.Min(1, m_Time / guardClosingTime));
|
if (m_Time >= guardClosingTime)
|
{
|
ReleaseSFX();
|
(owner as GA_Guard).Disappear();
|
}
|
}
|
break;
|
case GA_Guard.GuardState.PickUp:
|
{
|
m_PickUpPackTime += Time.deltaTime;
|
if (guard.Root.position != nextPosition)
|
{
|
m_Time += Time.deltaTime;
|
guard.Root.position = Vector3.Lerp(lastPosition, nextPosition, Mathf.Min(1, m_Time / guardClosingTime));
|
if (m_Time >= guardClosingTime)
|
{
|
RequestDropItem();
|
DropItemManager.CheckGuardPickUpItem(guard);
|
}
|
}
|
else
|
{
|
RequestDropItem();
|
}
|
}
|
break;
|
}
|
}
|
|
int Compare(int x, int y)
|
{
|
Vector3 xpos;
|
Vector3 ypos;
|
DropItemManager.TryGetDropPositionFromInstanceId(x, out xpos);
|
DropItemManager.TryGetDropPositionFromInstanceId(y, out ypos);
|
float xdis = Vector3.Distance(xpos, nextPosition);
|
float ydis = Vector3.Distance(ypos, nextPosition);
|
return -xdis.CompareTo(ydis);
|
}
|
|
void RequestDropItem()
|
{
|
m_Time = 0;
|
if (dropItemList.Count == 0)
|
{
|
guard.guardState = GA_Guard.GuardState.Track;
|
return;
|
}
|
lastPosition = guard.Root.position;
|
if (guard.targetPlayer == null)
|
{
|
return;
|
}
|
if (DropItemManager.TryGetDropPositionFromInstanceId(dropItemList[0], out nextPosition))
|
{
|
nextPosition.y = guard.targetPlayer.Root.position.y + guard.GuardianHeight;
|
guard.Forward = nextPosition - lastPosition;
|
}
|
if (dropItemList.Count > 0 && Vector3.Distance(guard.Root.position, nextPosition) < 0.1f
|
&& m_PickUpPackTime >= m_PickUpDelayTime)
|
{
|
m_PickUpPackTime = 0.0f;
|
DropItemManager.CheckGuardPickUpItem(guard);
|
}
|
guardClosingTime = Vector3.Distance(lastPosition, nextPosition) / guard.GuardianSpeed;
|
}
|
|
void ReleaseSFX()
|
{
|
if (_sfXctl != null)
|
{
|
SFXPlayUtility.Instance.Release(_sfXctl);
|
_sfXctl = null;
|
}
|
}
|
}
|