浏览代码

Fixes in FollowPathRig

/main
Thomas ICHÉ 6 年前
当前提交
feeeef36
共有 1 个文件被更改,包括 58 次插入18 次删除
  1. 76
      Runtime/Rigs/FollowPathRig.cs

76
Runtime/Rigs/FollowPathRig.cs


using NaughtyAttributes;
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;

public bool StopOnSteps = false;
public float Speed = 2.0f;
[ReorderableList, SerializeField]
[ReorderableList, SerializeField, NonNullCheck]
[SerializeField]
float progress;
float m_Progress;
public void SetProgress(float progress)
{
m_Progress = Mathf.Clamp(progress, 0, Path.Length - 1);
}
public void Play(float progress = -1.0f)
{
if (progress >= 0.0f)
SetProgress(progress);
m_PlayMode = PlayMode.Playing;
}
public void Reverse(float progress = -1.0f)
{
if (progress >= 0.0f)
SetProgress(progress);
m_PlayMode = PlayMode.Reverse;
}
public void Stop(float progress = -1.0f)
{
if (progress >= 0.0f)
SetProgress(progress);
m_PlayMode = PlayMode.Stopped;
}
progress = 0.0f;
m_Progress = 0.0f;
private void Update()
private void LateUpdate()
if(Path.Where(o => o == null).Count() > 0)
{
Debug.LogWarning("Path contains null objects. Cannot Compute.", this);
}
if((m_PlayMode == PlayMode.Playing && progress == Path.Length - 1) || (m_PlayMode == PlayMode.Reverse && progress == 0.0f))
if((m_PlayMode == PlayMode.Playing && m_Progress == Path.Length - 1) || (m_PlayMode == PlayMode.Reverse && m_Progress == 0.0f))
{
m_PlayMode = PlayMode.Stopped;
return;

if (m_PlayMode == PlayMode.Playing && progress == Path.Length -1)
if (m_PlayMode == PlayMode.Playing && m_Progress == Path.Length -1)
progress = 0.0f;
m_Progress = 0.0f;
else if (m_PlayMode == PlayMode.Reverse && progress == 0.0f)
else if (m_PlayMode == PlayMode.Reverse && m_Progress == 0.0f)
progress = Path.Length -1;
m_Progress = Path.Length -1;
if (m_PlayMode == PlayMode.Playing && progress == Path.Length -1)
if (m_PlayMode == PlayMode.Playing && m_Progress == Path.Length -1)
else if (m_PlayMode == PlayMode.Reverse && progress == 0.0f)
else if (m_PlayMode == PlayMode.Reverse && m_Progress == 0.0f)
{
m_PlayMode = PlayMode.Playing;
}

if (m_PlayMode == PlayMode.Reverse)
sign = -1.0f;
int idx = (int)Mathf.Floor(progress);
int idx = Mathf.Clamp( sign > 0? (int)Mathf.Floor(m_Progress) : (int)Mathf.Ceil(m_Progress), 0 , Path.Length-1);
int nextidx = idx + (int)sign;
Vector3 inPos = Path[idx].transform.position;

Vector3 pos = Vector3.Lerp(inPos, outPos, (sign > 0)? progress % 1.0f : 1.0f-(progress % 1.0f));
Vector3 pos = Vector3.Lerp( sign > 0? inPos : outPos, sign > 0? outPos : inPos, m_Progress % 1.0f);
progress = Mathf.Clamp(progress + moveT * sign, idx, nextidx);
m_Progress = Mathf.Clamp(m_Progress + moveT, (sign > 0)? idx : nextidx, (sign > 0) ? nextidx : idx);
if(progress == nextidx)
if(m_Progress == nextidx)
transform.position = Vector3.Lerp(inPos, outPos, (sign > 0) ? progress % 1.0f : 1.0f - (progress % 1.0f));
transform.position = Vector3.Lerp(inPos, outPos, (sign > 0) ? m_Progress % 1.0f : 1.0f - (m_Progress % 1.0f));
if((m_Progress %1.0f == 0.0f) && StopOnSteps)
{
m_PlayMode = PlayMode.Stopped;
}
}
}

正在加载...
取消
保存