static PerformanceValues() { Worst = new PerformanceValues() { physicsSolverIterationCount = 2, physicsSleepVelocity = 0.5f,//1f, physicsSleepAngularVelocity = 0.5f,//1f, physicsMinPenetrationForPenalty = 0.05f,//1f, timeFixedTimestep = 0.1f,//0.2f, timeMaximumeAllowedTimestep = 0.2f, simpleJointSleepDistance = 0.2f }; Best = new PerformanceValues() { physicsSolverIterationCount = 7, physicsSleepVelocity = 0.3f,// 0.15f, physicsSleepAngularVelocity = 0.3f,//0.14f, physicsMinPenetrationForPenalty = 0.01f,//1f, timeFixedTimestep = 0.015f, timeMaximumeAllowedTimestep = 0.33f, simpleJointSleepDistance = 0.02f }; Range = new PerformanceValues() { physicsSolverIterationCount = Best.physicsSolverIterationCount - Worst.physicsSolverIterationCount, physicsSleepVelocity = Best.physicsSleepVelocity - Worst.physicsSleepVelocity, physicsSleepAngularVelocity = Best.physicsSleepAngularVelocity - Worst.physicsSleepAngularVelocity, physicsMinPenetrationForPenalty = Best.physicsMinPenetrationForPenalty - Worst.physicsMinPenetrationForPenalty, timeFixedTimestep = Best.timeFixedTimestep - Worst.timeFixedTimestep, timeMaximumeAllowedTimestep = Best.timeMaximumeAllowedTimestep - Worst.timeMaximumeAllowedTimestep, simpleJointSleepDistance = Best.simpleJointSleepDistance - Worst.simpleJointSleepDistance }; }
public static PerformanceValues GetValuesAtRatio(float performanceRatio) { performanceRatio = Mathf.Clamp(performanceRatio, 0.0f, 1.0f); var values = new PerformanceValues() { hasValue = true, physicsSolverIterationCount = (int)(Worst.physicsSolverIterationCount + Range.physicsSolverIterationCount * performanceRatio), physicsSleepVelocity = Worst.physicsSleepVelocity + Range.physicsSleepVelocity * performanceRatio, physicsSleepAngularVelocity = Worst.physicsSleepAngularVelocity + Range.physicsSleepAngularVelocity * performanceRatio, physicsMinPenetrationForPenalty = Worst.physicsMinPenetrationForPenalty + Range.physicsMinPenetrationForPenalty * performanceRatio, timeFixedTimestep = Worst.timeFixedTimestep + Range.timeFixedTimestep * performanceRatio, timeMaximumeAllowedTimestep = Worst.timeMaximumeAllowedTimestep + Range.timeMaximumeAllowedTimestep * performanceRatio, simpleJointSleepDistance = Worst.simpleJointSleepDistance + Range.simpleJointSleepDistance * performanceRatio, isMirroringEnabled = performanceRatio < isMirroringEnabledMinRatio ? false : true }; return values; }
private static void ChangePerformance(float targetPerformanceRatio) { targetPerformanceRatio = Mathf.Clamp(targetPerformanceRatio, 0.0f, 1.0f); targetPerformanceRatio = Mathf.Clamp(targetPerformanceRatio, minPerformanceRatio, maxPerformanceRatio); if (performanceRatio == targetPerformanceRatio) { return; } performanceRatio = targetPerformanceRatio; var values = PerformanceValues.GetValuesAtRatio(performanceRatio); performanceValues = values; Physics.solverIterationCount = values.physicsSolverIterationCount; Physics.sleepVelocity = values.physicsSleepVelocity; Physics.sleepAngularVelocity = values.physicsSleepAngularVelocity; Physics.minPenetrationForPenalty = values.physicsMinPenetrationForPenalty; Time.fixedDeltaTime = values.timeFixedTimestep; Time.maximumDeltaTime = values.timeMaximumeAllowedTimestep; MirrorObject.isEnabledGlobal = values.isMirroringEnabled; SimpleJoint.sleepDistance = values.simpleJointSleepDistance; timeAtChange = Time.time; Debug.Log( "Performance Changed: PerformanceRatio=" + performanceRatio + ", " + "physicsSolverIterationCount=" + values.physicsSolverIterationCount + ", " + "physicsSleepVelocity=" + values.physicsSleepVelocity + ", " + "physicsSleepAngularVelocity=" + values.physicsSleepAngularVelocity + ", " + "physicsMinPenetrationForPenalty=" + values.physicsMinPenetrationForPenalty + ", " + "timeFixedTimestep=" + values.timeFixedTimestep + ", " + "timeMaximumeAllowedTimestep=" + values.timeMaximumeAllowedTimestep + ", " + "isMirroringEnabled=" + values.isMirroringEnabled + ", " + "simpleJointSleepDistance=" + values.simpleJointSleepDistance ); }