//This makes sure that every frame the timestep is determined only once; all other Modular Fuel parts then use that timestep for all operations //This function must occur AFTER part-specific functions that are dependent on it if you also want to use precisionDeltaTime for persistence purposes public override void OnUpdate() { base.OnUpdate(); //If the controller module isn't assigned, assign it; we cast to object because that is faster than the standard == null function, which involves Unity checking if the object was destroyed in addition to being null if ((object)controllerModule == null) controllerModule = this; //Here the controller does the floating point math if (controllerModule == this) { double tempTimeStamp = Planetarium.GetUniversalTime(); controllerPrecisionDeltaTime = tempTimeStamp - controllerTimeStamp; controllerTimeStamp = tempTimeStamp; } precisionDeltaTime = controllerPrecisionDeltaTime; //Assign the deltaTime for each part from the static field, so that this field can also be used for handling persistence stuff }
//This makes sure that every frame the timestep is determined only once; all other Modular Fuel parts then use that timestep for all operations //This function must occur AFTER part-specific functions that are dependent on it if you also want to use precisionDeltaTime for persistence purposes public override void OnUpdate() { base.OnUpdate(); //If the controller module isn't assigned, assign it; we cast to object because that is faster than the standard == null function, which involves Unity checking if the object was destroyed in addition to being null if ((object)controllerModule == null) { controllerModule = this; } //Here the controller does the floating point math if (controllerModule == this) { double tempTimeStamp = Planetarium.GetUniversalTime(); controllerPrecisionDeltaTime = tempTimeStamp - controllerTimeStamp; controllerTimeStamp = tempTimeStamp; } precisionDeltaTime = controllerPrecisionDeltaTime; //Assign the deltaTime for each part from the static field, so that this field can also be used for handling persistence stuff }
public void OnDestroy() { controllerModule = null; }