protected void UF_UpdateMoveBack(float dtime) { if (!m_isMovingBack) { return; } if (m_MoveBackDuration <= 0.0001f || ower == null) { this.UF_Stop(); return; } else { m_MoveBackDurationTick += dtime; float progress = Mathf.Clamp01(m_MoveBackDurationTick / m_MoveBackDuration); Vector3 pos = m_MoveBackSorPositon * (1 - progress) + ower.transform.position * progress; this.position = pos; //设置角度指向 this.euler = new Vector3(0, MathX.UF_EulerAngle(this.position, ower.transform.position).y, 0); if (progress >= 1) { this.UF_Stop(); } } }
protected override void UF_OnPlay(GameObject tar, Vector3 tarPos, Vector3 vecforward) { if (speed <= 0.01f) { Debugger.UF_Error("Speed is too samll,play failed!"); this.UF_Stop(); return; } if (m_Target == null) { this.UF_Stop(); return; } m_TimeTick = 0; m_SourcePos = this.position; //计算出总时间 float distance = Vector3.Distance(m_SourcePos, tar.transform.position); m_Duration = distance / speed; //设置角度指向 this.euler = new Vector3(0, MathX.UF_EulerAngle(vecforward).y, 0); //偏移幅度 m_trackOffset.x = offset.x * (Random.Range(1, 100) - 50.0f) / 50.0f; m_trackOffset.y = offset.y * (Random.Range(1, 50)) / 50.0f; m_Target = tar; m_CurTargetPos = m_Target.transform.position; EffectControl.UF_ResetTailRender(this.gameObject); }
protected override void UF_OnPlay(GameObject tar, Vector3 tarPos, Vector3 vecforward) { if (speed <= 0.01f) { Debugger.UF_Error("Speed is too samll,play failed!"); m_IsPlaying = false; return; } vecforward.y = 0; m_Forward = vecforward.normalized; float len = Vector3.Distance(tarPos, this.position); tarPos = len * m_Forward + this.position; m_TarPosition = tarPos + tarOffset * m_Forward; if (inGround) m_TarPosition.y = 0; m_SorPosition = this.position; m_Distance = Vector3.Distance(tarPos, this.position); m_Duration = m_Distance / speed; m_DurationTick = 0; lastPosition = this.position; //设置角度指向 this.euler = new Vector3(0, MathX.UF_EulerAngle(this.position, tarPos).y, 0); EffectControl.UF_ResetTailRender(this.gameObject); }
public void TurnForward(Vector3 forward) { if (!isActive) { return; } UF_TurnTo(MathX.UF_EulerAngle(forward).y); }
protected override void UF_OnPlay(GameObject tar, Vector3 tarPos, Vector3 vecforward) { //this.transform.eulerAngles = MathX.UF_EulerAngle(vecforward); //设置角度指向 if (fixEulerOnPlay) { this.euler = new Vector3(0, MathX.UF_EulerAngle(vecforward).y, 0); } }
protected override void UF_OnStart() { if (spaceWorld && worldForwardMode) { //重新计算 Vector3 fvEuler = MathX.UF_EulerAngle(this.transform.forward); m_Source += fvEuler; m_Target += fvEuler; } }
private void UF_UpdateRotate(Vector3 forward) { if (rotateRange) { var vAngle = MathX.UF_EulerAngle(forward); if (joyRange != null) { var e = joyRange.transform.localEulerAngles; e.z = -vAngle.y; joyRange.transform.localEulerAngles = e; } } }
public void UF_TurnTo(Vector3 point) { if (!isActive) { return; } if (m_Avatar == null) { Debugger.UF_Warn("m_TransAvatar is null TurnToPoint Fial"); return; } UF_TurnTo(MathX.UF_EulerAngle(m_Avatar.position, point).y); }
protected override void UF_OnPlay(GameObject tar, Vector3 tarPos, Vector3 vecforward) { if (speed <= 0.01f) { Debugger.UF_Error("Speed is too samll,play failed!"); m_IsPlaying = false; return; } tarPos.y = this.position.y; useReboundTimes = 0; lastPosition = this.position; //设置角度指向 this.euler = new Vector3(0, MathX.UF_EulerAngle(vecforward).y, 0); EffectControl.UF_ResetTailRender(this.gameObject); }
protected override void UF_UpdateMoveForward(float dtime) { lastPosition = this.position; float offsetVal = offset; if (offsetRate > 0) { m_OffsetRateTick += dtime * offsetRate; offsetVal = Mathf.Min(m_OffsetRateTick, offset); } m_DegRateTick += degRate * dtime; Vector3 offsetPos = m_SinForward * (Mathf.Sin(m_DegRateTick)) * offsetVal; this.position += speed * m_Forward * dtime + offsetPos * dtime; this.euler = MathX.UF_EulerAngle(lastPosition, this.position); }
protected IEnumerator UF_MotionTransPosition( Transform target, Vector3 vfrom, Transform toObj, float duration, bool ingoreTimeScale, float heightOffset, bool spaceWorld, Vector3 offset, bool focusAngle, DelegateVoid eventFinish) { float progress = 0; float tickBuff = 0; while (progress < 1) { float delta = ingoreTimeScale ? GTime.RunDeltaTime : GTime.UnscaleDeltaTime; tickBuff += delta; progress = Mathf.Clamp01(tickBuff / duration); Vector3 current = progress * (toObj.position + offset) + (1 - progress) * vfrom; Vector3 currentOffset = new Vector3(0, heightOffset * Mathf.Sin(Mathf.PI * progress), 0); Vector3 lastPositon = default(Vector3); if (spaceWorld) { lastPositon = target.position; target.position = current + currentOffset; if (focusAngle) { target.eulerAngles = MathX.UF_EulerAngle(lastPositon, target.position); } } else { lastPositon = target.localPosition; target.localPosition = current + currentOffset; if (focusAngle) { target.localEulerAngles = MathX.UF_EulerAngle(lastPositon, target.position); } } yield return(null); } GHelper.UF_SafeCallDelegate(eventFinish); }
protected void UF_UpdateRebound(float dtime) { if (m_isRebounding) { m_isRebounding = false; useReboundTimes++; Vector3 normal = UF_GetNormalFormBlock(m_hitTargetPos, lastPosition, m_Forward); //求得反射方向 m_Forward = m_Forward - 2 * Vector3.Dot(normal, m_Forward) * normal; m_Forward.y = 0; m_Forward = m_Forward.normalized; //设置角度指向 this.euler = new Vector3(0, MathX.UF_EulerAngle(m_Forward).y, 0); //更新一次Forward避免异常碰撞 UF_UpdateMoveForward(dtime); } }
protected override void UF_OnRun(float dtime) { float progress = 0; m_TimeTick += dtime; if (m_Duration > 0) { progress = Mathf.Clamp01(m_TimeTick / m_Duration); } if (m_Target != null) { Vector3 tarpos = m_Target.transform.position; if (!m_Target.activeSelf) { tarpos = m_CurTargetPos; } tarpos.y = m_SourcePos.y; Vector3 current = progress * (tarpos) + (1 - progress) * m_SourcePos; float sinVal = Mathf.Sin(Mathf.PI * progress); Vector3 currentOffset = new Vector3(m_trackOffset.x * sinVal, m_trackOffset.y * sinVal, 0); m_LastPos = this.position; m_CurTargetPos = m_Target.transform.position; this.position = current + currentOffset; if (focusAngle) { this.euler = MathX.UF_EulerAngle(m_LastPos, this.position); } if ((progress) >= 1f) { //this.Stop(); UF_OnColliderEnter(m_Target, this.position); } } else { this.UF_Stop(); } }
protected IEnumerator UF_MotionPathPoint( Transform target, List <Vector3> pathPoints, float duration, bool ingoreTimeScale, float heightOffset, bool spaceWorld, Vector3 offset, bool focusAngle, DelegateVoid eventFinish) { if (pathPoints.Count == 1) { target.position = pathPoints[0]; yield break; } //计算总长度 float totalLenght = 0; for (int k = 1; k < pathPoints.Count; k++) { totalLenght += Vector3.Distance(pathPoints[k - 1], pathPoints[k]); } if (totalLenght <= 0) { target.position = pathPoints[pathPoints.Count - 1]; yield break; } for (int k = 1; k < pathPoints.Count; k++) { float progress = 0; float tickBuff = 0; Vector3 vfrom = pathPoints[k]; Vector3 vto = pathPoints[k - 1]; //计算每段的时间片段 float unitDuration = Vector3.Distance(vfrom, vto) / totalLenght; if (unitDuration <= 0) { continue; } while (progress < 1) { float delta = ingoreTimeScale ? GTime.RunDeltaTime : GTime.UnscaleDeltaTime; tickBuff += delta; progress = Mathf.Clamp01(tickBuff / duration); Vector3 current = progress * (vto + offset) + (1 - progress) * vfrom; Vector3 currentOffset = new Vector3(0, heightOffset * Mathf.Sin(Mathf.PI * progress), 0); Vector3 lastPositon = default(Vector3); if (spaceWorld) { lastPositon = target.position; target.position = current + currentOffset; if (focusAngle) { target.eulerAngles = MathX.UF_EulerAngle(lastPositon, target.position); } } else { lastPositon = target.localPosition; target.localPosition = current + currentOffset; if (focusAngle) { target.localEulerAngles = MathX.UF_EulerAngle(lastPositon, target.position); } } yield return(null); } } GHelper.UF_SafeCallDelegate(eventFinish); }
protected virtual void UF_OnPlay(GameObject tar, Vector3 tarPos, Vector3 vecforward) { //设置角度指向 this.euler = new Vector3(0, MathX.UF_EulerAngle(vecforward).y, 0); }