// turn so that you are standing correctly public IEnumerator Turn(Directions dir) { TransformLocalEulerTweener t = (TransformLocalEulerTweener)transform.RotateToLocal(dir.ToEuler(), 0.25f, EasingEquations.EaseInOutQuad); float roundedStart = Mathf.Round(t.startValue.z); float roundedEnd = Mathf.Round(t.endValue.z); // When rotating between South and West, we must make an exception so it looks like the unit // rotates the most efficient way (since 0 and 360 are treated the same) if (roundedStart == 0 && roundedEnd == 270) { t.startValue = new Vector3(t.startValue.x, t.startValue.y, 360f); } else if (roundedStart == 270 && roundedEnd == 0) { t.endValue = new Vector3(t.startValue.x, t.startValue.y, 360f); } while (t != null) { GameController.gravTransitionState = true; // make sure GameController.gravTransitionState remains true while we're animating grounded = false; yield return(null); } }
// 회전을 담당하는 함수 protected virtual IEnumerator Turn(Directions dir) { // 다른 강좌에서 했던 내용입니다. // 차후 해당 강좌도 블로그에서 설명하겠습니다. // 각도 회전 등을 반환합니다. TransformLocalEulerTweener t = (TransformLocalEulerTweener)transform.RotateToLocal ( dir.ToEuler(), 0.25f, EasingEquations.EaseInOutQuad ); // 북쪽과 서쪽 사이를 회전할 때는 장치가 가장 효율적인 방법으로 회전하는 것처럼 보이도록 // 예외를 만들어야 한다. (0 과 360도는 동일하게 본다.) if (Mathf.Approximately(t.startValue.y, 0f) && Mathf.Approximately(t.endValue.y, 270f)) { t.startValue = new Vector3(t.startValue.x, 360f, t.startValue.z); } else if (Mathf.Approximately(t.startValue.y, 270) && Mathf.Approximately(t.endValue.y, 0)) { t.endValue = new Vector3(t.startValue.x, 360f, t.startValue.z); } unit.dir = dir; while (t != null) { yield return(null); } }
protected virtual IEnumerator Turn(Directions dir) { TransformLocalEulerTweener t = (TransformLocalEulerTweener)transform.RotateToLocal(dir.ToEuler(), 0.25f, EasingEquations.EaseInOutQuad); // When rotating between North and West, we must make an exception so it looks like the unit // rotates the most efficient way (since 0 and 360 are treated the same) if (Mathf.Approximately(t.startTweenValue.y, 0f) && Mathf.Approximately(t.endTweenValue.y, 270f)) { t.startTweenValue = new Vector3(t.startTweenValue.x, 360f, t.startTweenValue.z); }
public static Tweener RotateToLocal(this Transform t, Vector3 euler, float duration, Func <float, float, float, float> equation) { TransformLocalEulerTweener tweener = t.gameObject.AddComponent <TransformLocalEulerTweener> (); tweener.startTweenValue = t.localEulerAngles; tweener.endTweenValue = euler; tweener.duration = duration; tweener.equation = equation; tweener.Play(); return(tweener); }
public static Tweener RotateToLocalUsingCurve(this Transform t, Vector3 euler, float duration, AnimationCurve curve) { TransformLocalEulerTweener tweener = t.gameObject.AddComponent <TransformLocalEulerTweener>(); tweener.StartTweenValue = t.localEulerAngles; tweener.EndTweenValue = euler; tweener.duration = duration; tweener.curve = curve; tweener.useAnimationCurve = true; tweener.Play(); return(tweener); }
protected virtual IEnumerator Turn(Directions dir) { TransformLocalEulerTweener t = (TransformLocalEulerTweener)transform.RotateToLocal(dir.ToEuler(), 0.25f, EasingEquations.EaseInOutQuad); if (Mathf.Approximately(t.startValue.y, 0f) && Mathf.Approximately(t.endValue.y, 270f)) { t.startValue = new Vector3(t.startValue.x, 360f, t.startValue.z); } else if (Mathf.Approximately(t.startValue.y, 270) && Mathf.Approximately(t.endValue.y, 0)) { t.endValue = new Vector3(t.startValue.x, 360f, t.startValue.z); } unit.Dir = dir; while (t != null) { yield return(null); } }
//Turn, but immediate protected virtual IEnumerator Flip(Directions dir) { TransformLocalEulerTweener t = (TransformLocalEulerTweener)transform.RotateToLocal(dir.ToEuler(), 0f, EasingEquations.Linear); // When rotating between North and West, we must make an exception so it looks like the unit // rotates the most efficient way (since 0 and 360 are treated the same) if (Mathf.Approximately(t.startValue.y, 0f) && Mathf.Approximately(t.endValue.y, 270f)) { t.startValue = new Vector3(t.startValue.x, 360f, t.startValue.z); } else if (Mathf.Approximately(t.startValue.y, 270) && Mathf.Approximately(t.endValue.y, 0)) { t.endValue = new Vector3(t.startValue.x, 360f, t.startValue.z); } unit.dir = dir; while (t != null) { yield return(null); } }
public abstract IEnumerator Traverse(Tile tile); //在路徑上移動的動畫,根據不同移動類型有不同的演出(腳本) protected virtual IEnumerator Turn(Directions sw) //轉向 { TransformLocalEulerTweener tweener = (TransformLocalEulerTweener)transform.RotateToLocal(sw.ToEuler(), 0.25f, EasingEquations.EaseInOutQuad); Vector3 temp = (tweener.startValue - tweener.endValue); if (temp.y > 180f) { tweener.startValue = new Vector3(tweener.startValue.x, tweener.startValue.y - 360f, tweener.startValue.z); } else if (temp.y < -180f) { tweener.startValue = new Vector3(tweener.startValue.x, tweener.startValue.y + 360f, tweener.startValue.z); } unit.dir = sw; while (tweener != null) { yield return(null); } }
public abstract IEnumerator Logica(Area area); // Logica /// <summary> /// <para>Realiza el giro de la unidad hacia una direccion.</para> /// </summary> /// <param name="dir">Direccion</param> /// <returns></returns> public virtual IEnumerator Giro(Direcciones dir) // Realiza el giro de la unidad hacia una direccion { TransformLocalEulerTweener a = (TransformLocalEulerTweener)transform.RotateToLocal(dir.DireccionAVector3(), 0.25f, EasingEquations.EaseInOutQuad); // Cuando giramos entre el norte y el oeste, debemos hacer una excepcion para que parezca que la unidad // gira de la manera mas eficiente (ya que 0 y 360 es igual) if (Mathf.Approximately(a.startTweenValue.y, 0f) && Mathf.Approximately(a.endTweenValue.y, 270f)) { a.startTweenValue = new Vector3(a.startTweenValue.x, 360f, a.startTweenValue.z); } else if (Mathf.Approximately(a.startTweenValue.y, 270) && Mathf.Approximately(a.endTweenValue.y, 0)) { a.endTweenValue = new Vector3(a.startTweenValue.x, 360f, a.startTweenValue.z); } // Fijamos la direccion de la unidad unidad.dir = dir; while (a != null) { yield return(null); } }
public virtual IEnumerator Turn(HexDirection dir) { anim.Walking = false; TransformLocalEulerTweener t = (TransformLocalEulerTweener)transform.RotateToLocal(dir.ToEuler(), 0.25f, EasingEquations.EaseInOutQuad); // When rotating between North and West, we must make an exception so it looks like the unit // rotates the most efficient way (since 0 and 360 are treated the same) if (Mathf.Approximately(t.startTweenValue.y, 0f) && Mathf.Approximately(t.endTweenValue.y, 270f)) { t.startTweenValue = new Vector3(t.startTweenValue.x, 360f, t.startTweenValue.z); } else if (Mathf.Approximately(t.startTweenValue.y, 270) && Mathf.Approximately(t.endTweenValue.y, 0)) { t.endTweenValue = new Vector3(t.startTweenValue.x, 360f, t.startTweenValue.z); } unit.direction = dir; while (t != null) { yield return(null); } }
/// <summary> /// Rotates a character to face a given direction by rotating the fastest direction to get there /// </summary> /// <param name="dir">direction to face</param> /// <returns></returns> protected virtual IEnumerator Turn(Directions dir) { TransformLocalEulerTweener tweener = (TransformLocalEulerTweener)transform.RotateToLocal( dir.ToEuler(), 0.25f, EasingEquations.EaseInOutQuad); // When rotating between N & W, make an exception so it looks like the unit // Rotates the most efficient way (0 & 360 are treated the same) if (Mathf.Approximately(tweener.startValue.y, 0f) && Mathf.Approximately(tweener.endValue.y, 270f)) { tweener.startValue = new Vector3(tweener.startValue.x, 360f, tweener.startValue.z); } else if (Mathf.Approximately(tweener.startValue.y, 270) && Mathf.Approximately(tweener.endValue.y, 0)) { tweener.endValue = new Vector3(tweener.startValue.x, 260f, tweener.startValue.z); } unit.dir = dir; while (tweener != null) { yield return(null); } }