Ejemplo n.º 1
0
		protected override void DrawExtraInspector()
		{
			editor.DrawEnumPopupLayout(_space, value => space = (RotationSpace)value, "Space");
			editor.DrawEnumPopupLayout(_orientation, value => orientation = (RotationOrientation)value, "Orientation");

			if (_orientation != RotationOrientation.Free)
			{
				if (EditorKit.IndentedButton("Correct Orientations"))
				{
					Undo.RecordObject(this, editor.undoString);

					for (int i=0; i<count; i++)
					{
						var value = GetValue(i);

						if (_space == RotationSpace.Path)
						{
							if (_orientation == RotationOrientation.ForwardTangent)
							{
								value = Quaternion.LookRotation(
									path.GetTangent(path.GetLocationByLength(GetPosition(i)), Space.Self),
									value * Vector3.up);
							}
							else if (_orientation == RotationOrientation.BackTangent)
							{
								value = Quaternion.LookRotation(
									-path.GetTangent(path.GetLocationByLength(GetPosition(i)), Space.Self),
									value * Vector3.up);
							}
						}
						else
						{
							if (_orientation == RotationOrientation.ForwardTangent)
							{
								value = Quaternion.LookRotation(
									path.GetTangent(path.GetLocationByLength(GetPosition(i))),
									value * Vector3.up);
							}
							else if (_orientation == RotationOrientation.BackTangent)
							{
								value = Quaternion.LookRotation(
									-path.GetTangent(path.GetLocationByLength(GetPosition(i))),
									value * Vector3.up);
							}
						}

						SetValue(i, value);
					}
					
					EditorUtility.SetDirty(this);
				}
			}
		}
Ejemplo n.º 2
0
    public float Rotate(RotationOrientation direction, float steerSpeed)
    {
        float rotationDelta = direction == RotationOrientation.CLOCKWISE ?
                              steerSpeed * Time.fixedDeltaTime :
                              -steerSpeed * Time.fixedDeltaTime;

        float newRotationAngle = (rotationAngle + rotationDelta) % 360f;

        // rotation as an euler angle range between 0-360 degrees only
        if (rotationAngle + rotationDelta < 0f)
        {
            newRotationAngle = 360f + newRotationAngle;
        }

        // transform.Rotate(transform.forward * rotationDelta);
        Quaternion deltaRotation = Quaternion.Euler(transform.forward * rotationDelta);

        rb.MoveRotation(rb.rotation * deltaRotation);
        return(newRotationAngle);
    }