public IEnumerator Swing(bool front) { RotationPending = true; Transform t = transform; RotationTimelineData CurrentRotationBlock = RotationTimeline[CurrentRotationBlockIndex]; float TimeProgression = 0f; if (AngleConvention == 0) // Alex's Door System Convention { SwingStart = Quaternion.Euler(0, -CurrentRotationBlock.FrontAngle, 0); SwingMid = Quaternion.Euler(0, -CurrentRotationBlock.MiddleAngle, 0); SwingEnd = Quaternion.Euler(0, -CurrentRotationBlock.BackAngle, 0); } else if (AngleConvention == 1) // Unity Convention { SwingStart = Quaternion.Euler(0, CurrentRotationBlock.FrontAngle, 0); SwingMid = Quaternion.Euler(0, CurrentRotationBlock.MiddleAngle, 0); SwingEnd = Quaternion.Euler(0, CurrentRotationBlock.BackAngle, 0); } if (DoorScale == ScaleOfDoor.Unity3DUnits && PivotPosition == PositionOfPivot.Centered) { t = hinge.transform; if (TimesRotated == 0 && SwingState == 1) { t.rotation = SwingStart; } if (TimesRotated == 0 && SwingState == 2) { t.rotation = SwingMid; } if (TimesRotated == 0 && SwingState == 3) { t.rotation = SwingEnd; } } else if (PivotPosition == PositionOfPivot.CorrectlyPositioned) { if (TimesRotated == 0) { t.rotation = StartRotation; } } if (TimesRotated < CurrentRotationBlock.TimesMoveable || CurrentRotationBlock.TimesMoveable == 0) { while (TimeProgression <= (1 / CurrentRotationBlock.Speed)) { TimeProgression += Time.deltaTime; float RotationProgression = Mathf.Clamp01(TimeProgression / (1 / CurrentRotationBlock.Speed)); float RotationCurveValue = CurrentRotationBlock.RotationCurve.Evaluate(RotationProgression); if (front) { if (SwingState == 1) { t.rotation = RotationTools.Lerp(SwingStart, SwingMid, RotationCurveValue, ShortestWay); } if (SwingState == 2) { t.rotation = RotationTools.Lerp(SwingMid, SwingEnd, RotationCurveValue, ShortestWay); } if (SwingState == 3) { t.rotation = RotationTools.Lerp(SwingEnd, SwingMid, RotationCurveValue, ShortestWay); } } if (!front) { if (SwingState == 3) { t.rotation = RotationTools.Lerp(SwingEnd, SwingMid, RotationCurveValue, ShortestWay); } if (SwingState == 2) { t.rotation = RotationTools.Lerp(SwingMid, SwingStart, RotationCurveValue, ShortestWay); } if (SwingState == 1) { t.rotation = RotationTools.Lerp(SwingStart, SwingMid, RotationCurveValue, ShortestWay); } } yield return(null); } if (front && SwingState == 1) { SwingState++; } else if (front && SwingState == 2) { SwingState++; } else if (front && SwingState == 3) { SwingState--; } else if (!front && SwingState == 1) { SwingState++; } else if (!front && SwingState == 2) { SwingState--; } else if (!front && SwingState == 3) { SwingState--; } TimesRotated++; if (TimesRotated == CurrentRotationBlock.TimesMoveable && CurrentRotationBlock.TimesMoveable != 0) { TimesRotated = 0; CurrentRotationBlockIndex++; } } RotationPending = false; }
public IEnumerator Rotate() { RotationPending = true; Transform t = transform; RotationTimelineData CurrentRotationBlock = RotationTimeline[CurrentRotationBlockIndex]; float TimeProgression = 0f; if (CurrentRotationBlock.RotationType == RotationTimelineData.TypeOfRotation.SingleRotation) { CurrentRotationBlock.TimesMoveable = 1; } if (AngleConvention == 0) // Alex's Door System Convention { StartRotation = Quaternion.Euler(0, -CurrentRotationBlock.InitialAngle, 0); EndRotation = Quaternion.Euler(0, -CurrentRotationBlock.FinalAngle, 0); } else if (AngleConvention == 1) // Unity Convention { StartRotation = Quaternion.Euler(0, CurrentRotationBlock.InitialAngle, 0); EndRotation = Quaternion.Euler(0, CurrentRotationBlock.FinalAngle, 0); } if (DoorScale == ScaleOfDoor.Unity3DUnits && PivotPosition == PositionOfPivot.Centered) { t = hinge.transform; RotationOffset = Quaternion.identity; } if (TimesRotated == 0) { t.rotation = StartRotation * RotationOffset; } if (TimesRotated < CurrentRotationBlock.TimesMoveable || CurrentRotationBlock.TimesMoveable == 0) { if (t.rotation == (RotationState == 0 ? EndRotation * RotationOffset : StartRotation *RotationOffset)) { RotationState ^= 1; } while (TimeProgression <= (1 / CurrentRotationBlock.Speed)) { TimeProgression += Time.deltaTime; float RotationProgression = Mathf.Clamp01(TimeProgression / (1 / CurrentRotationBlock.Speed)); float RotationCurveValue = CurrentRotationBlock.RotationCurve.Evaluate(RotationProgression); if (RotationState == 0) // Door is closed { t.rotation = RotationTools.Lerp(StartRotation * RotationOffset, EndRotation * RotationOffset, RotationCurveValue, ShortestWay); } if (RotationState == 1) // Door is opened { t.rotation = RotationTools.Lerp(EndRotation * RotationOffset, StartRotation * RotationOffset, RotationCurveValue, ShortestWay); } yield return(null); } TimesRotated++; if (TimesRotated == CurrentRotationBlock.TimesMoveable && CurrentRotationBlock.TimesMoveable != 0) { TimesRotated = 0; CurrentRotationBlockIndex++; } } RotationPending = false; }