private IEnumerator AccelerateTo(float targetSpeed, AccelerationConstraint constraint, float value)
    {
        isAccelerating = true;
        float localAcceleration = 0f;

        switch (constraint)
        {
        case AccelerationConstraint.Time:
            localAcceleration = (targetSpeed - currentSpeed) / value;
            break;

        case AccelerationConstraint.Space:
            localAcceleration = (Mathf.Pow(targetSpeed, 2f) - Mathf.Pow(currentSpeed, 2f)) / (2f * value);
            break;

        case AccelerationConstraint.SetValue:
            localAcceleration = value;
            break;
        }

        while (currentSpeed != targetSpeed)
        {
            if (!isPaused)
            {
                currentSpeed = (localAcceleration >= 0f) ? Mathf.Min(currentSpeed + localAcceleration * Time.deltaTime * playbackSpeed, targetSpeed) : Mathf.Max(currentSpeed + localAcceleration * Time.deltaTime * playbackSpeed, targetSpeed);
            }
            yield return(new WaitForEndOfFrame());
        }
        isAccelerating = false;
    }
예제 #2
0
 public void Write(TProtocol oprot)
 {
     oprot.IncrementRecursionDepth();
     try
     {
         TStruct struc = new TStruct("MConstraint");
         oprot.WriteStructBegin(struc);
         TField field = new TField();
         if (ID == null)
         {
             throw new TProtocolException(TProtocolException.INVALID_DATA, "required field ID not set");
         }
         field.Name = "ID";
         field.Type = TType.String;
         field.ID   = 1;
         oprot.WriteFieldBegin(field);
         oprot.WriteString(ID);
         oprot.WriteFieldEnd();
         if (GeometryConstraint != null && __isset.GeometryConstraint)
         {
             field.Name = "GeometryConstraint";
             field.Type = TType.Struct;
             field.ID   = 2;
             oprot.WriteFieldBegin(field);
             GeometryConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (VelocityConstraint != null && __isset.VelocityConstraint)
         {
             field.Name = "VelocityConstraint";
             field.Type = TType.Struct;
             field.ID   = 3;
             oprot.WriteFieldBegin(field);
             VelocityConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (AccelerationConstraint != null && __isset.AccelerationConstraint)
         {
             field.Name = "AccelerationConstraint";
             field.Type = TType.Struct;
             field.ID   = 4;
             oprot.WriteFieldBegin(field);
             AccelerationConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (PathConstraint != null && __isset.PathConstraint)
         {
             field.Name = "PathConstraint";
             field.Type = TType.Struct;
             field.ID   = 5;
             oprot.WriteFieldBegin(field);
             PathConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (JointPathConstraint != null && __isset.JointPathConstraint)
         {
             field.Name = "JointPathConstraint";
             field.Type = TType.Struct;
             field.ID   = 6;
             oprot.WriteFieldBegin(field);
             JointPathConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (PostureConstraint != null && __isset.PostureConstraint)
         {
             field.Name = "PostureConstraint";
             field.Type = TType.Struct;
             field.ID   = 7;
             oprot.WriteFieldBegin(field);
             PostureConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (JointConstraint != null && __isset.JointConstraint)
         {
             field.Name = "JointConstraint";
             field.Type = TType.Struct;
             field.ID   = 8;
             oprot.WriteFieldBegin(field);
             JointConstraint.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (Properties != null && __isset.Properties)
         {
             field.Name = "Properties";
             field.Type = TType.Map;
             field.ID   = 9;
             oprot.WriteFieldBegin(field);
             {
                 oprot.WriteMapBegin(new TMap(TType.String, TType.String, Properties.Count));
                 foreach (string _iter4 in Properties.Keys)
                 {
                     oprot.WriteString(_iter4);
                     oprot.WriteString(Properties[_iter4]);
                 }
                 oprot.WriteMapEnd();
             }
             oprot.WriteFieldEnd();
         }
         oprot.WriteFieldStop();
         oprot.WriteStructEnd();
     }
     finally
     {
         oprot.DecrementRecursionDepth();
     }
 }
    private IEnumerator AccelerateTo(float targetSpeed, AccelerationConstraint constraint, float value)
    {
        isAccelerating = true;
        float localAcceleration = 0f;
        switch(constraint)
        {
        case AccelerationConstraint.Time:
            localAcceleration = (targetSpeed - currentSpeed)/value;
            break;
        case AccelerationConstraint.Space:
            localAcceleration = (Mathf.Pow(targetSpeed, 2f) - Mathf.Pow (currentSpeed, 2f))/(2f * value);
            break;
        case AccelerationConstraint.SetValue:
            localAcceleration = value;
            break;
        }

        while(currentSpeed != targetSpeed)
        {
            if(!isPaused)
            {
                currentSpeed = (localAcceleration >= 0f) ? Mathf.Min(currentSpeed + localAcceleration * Time.deltaTime * playbackSpeed, targetSpeed) : Mathf.Max(currentSpeed + localAcceleration * Time.deltaTime * playbackSpeed, targetSpeed);
            }
            yield return new WaitForEndOfFrame();
        }
        isAccelerating = false;
    }