using UnityEngine;
|
using System.Collections;
|
using UnityEngine.Events;
|
|
public class SimpleMapTrasfer : MonoBehaviour
|
{
|
private Vector3 target;
|
private SFXController cloud;
|
private Animator moveAnimator;
|
private UnityAction m_OnStarted;
|
private UnityAction m_OnFinished;
|
private bool m_IsMoveHero;
|
public int curveType = 1;
|
|
public void Init(int effectID, Vector3 position, bool isMoveHero, UnityAction onStart, UnityAction onFinished)
|
{
|
target = position;
|
if (effectID != -1)
|
{
|
cloud = SFXPlayUtility.Instance.PlayWithEulerAngle(effectID, transform.position, Vector3.zero);
|
cloud.duration = -1;
|
cloud.transform.position = transform.position;
|
moveAnimator = cloud.transform.GetComponent<Animator>();
|
moveAnimator.enabled = false;
|
moveAnimator.Play("Empty");
|
}
|
m_OnFinished = null;
|
m_OnStarted = null;
|
m_OnFinished += onFinished;
|
m_OnStarted += onStart;
|
m_IsMoveHero = isMoveHero;
|
m_HasHandle = false;
|
|
if (!isMoveHero)
|
{
|
StopCoroutine("CheckHeroPosition");
|
StartCoroutine("CheckHeroPosition");
|
}
|
}
|
|
bool m_HasHandle = false;
|
|
private void OnTriggerEnter(Collider other)
|
{
|
if (m_HasHandle)
|
{
|
return;
|
}
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero == null)
|
{
|
return;
|
}
|
|
if (m_OnStarted != null)
|
{
|
m_OnStarted();
|
m_OnStarted = null;
|
}
|
|
if (m_IsMoveHero)
|
{
|
StartCoroutine(MoveHero());
|
}
|
|
vnxbqy.UI.WindowCenter.Instance.Close<vnxbqy.UI.NewGuideWin>();
|
vnxbqy.UI.WindowCenter.Instance.Close<vnxbqy.UI.GuideMessageWin>();
|
|
m_HasHandle = true;
|
}
|
|
private void OnTriggerStay(Collider other)
|
{
|
if (m_HasHandle)
|
{
|
return;
|
}
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero == null)
|
{
|
return;
|
}
|
|
if (m_OnStarted != null)
|
{
|
m_OnStarted();
|
m_OnStarted = null;
|
}
|
|
if (m_IsMoveHero)
|
{
|
StartCoroutine(MoveHero());
|
}
|
|
vnxbqy.UI.WindowCenter.Instance.Close<vnxbqy.UI.NewGuideWin>();
|
vnxbqy.UI.WindowCenter.Instance.Close<vnxbqy.UI.GuideMessageWin>();
|
|
m_HasHandle = true;
|
}
|
|
private IEnumerator CheckHeroPosition()
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero == null)
|
{
|
yield break;
|
}
|
|
float _distSqrt = float.MaxValue;
|
float _radius = transform.localScale.x * .5f;
|
while (_distSqrt > _radius * _radius)
|
{
|
_distSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, target);
|
yield return null;
|
}
|
|
if (m_OnFinished != null)
|
{
|
m_OnFinished();
|
}
|
}
|
|
private IEnumerator MoveHero()
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero == null)
|
{
|
yield break;
|
}
|
|
if (_hero.State == E_ActorState.AutoRun)
|
{
|
_hero.StopPathFind();
|
}
|
|
_hero.IdleImmediate();
|
_hero.needSyncGroundHeight = false;
|
GA_Hero.s_MapSwitching = true;
|
|
if (curveType == 1)
|
{
|
if (moveAnimator != null)
|
{
|
moveAnimator.enabled = true;
|
moveAnimator.Play("Yun_Move_1");
|
}
|
}
|
else
|
{
|
if (moveAnimator != null)
|
{
|
moveAnimator.enabled = true;
|
moveAnimator.Play("Yun_Move_2");
|
}
|
}
|
|
_hero.Root.SetParent(cloud.transform);
|
|
while (moveAnimator != null
|
&& moveAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1f)
|
{
|
_hero.PrevPos = _hero.Pos = cloud.transform.position;
|
|
yield return null;
|
}
|
|
_hero.Root.SetParent(null);
|
DontDestroyOnLoad(_hero.Root);
|
_hero.needSyncGroundHeight = true;
|
GA_Hero.s_MapSwitching = false;
|
|
if (m_OnFinished != null)
|
{
|
m_OnFinished();
|
}
|
|
yield return WaitingForSecondConst.WaitMS1000;
|
|
if (moveAnimator != null)
|
{
|
moveAnimator.Play("Empty");
|
}
|
|
yield return null;
|
SFXPlayUtility.Instance.Release(cloud);
|
cloud = null;
|
moveAnimator = null;
|
}
|
}
|