/// <summary> /// Updates the physical properties rougly once a second (1—1.5f). /// </summary> protected virtual IEnumerator UpdatePhysicalPropertiesCo() { float deltaTime = 0f; while (true) { if (prevProperties.temperature != properties.temperature) { Dispatch(ThingEventType.OnTemperatureChange, this); } // Temperature loss/gain from the area. var diff = properties.areaTemperature - properties.temperature; if (Mathf.Abs(diff) >= 0.01f) { var addTemperature = 1f * deltaTime; addTemperature = diff > 0 ? addTemperature : -addTemperature; properties.temperature += addTemperature; } else { properties.temperature = properties.areaTemperature; } prevProperties = properties; deltaTime = 1f + Random.Range(0, 0.5f); // Yied every 1-1.5f seconds in order to not pillow the thread with this coroutine. yield return(new WaitForSeconds(deltaTime)); } }
/// <summary> /// Updates the physical properties rougly once a second (1—1.5f). /// </summary> protected virtual IEnumerator UpdatePhysicalPropertiesCo() { float deltaTime = 0f; while (true) { if (prevProperties.temperature != properties.temperature) { Dispatch(ThingEventType.OnTemperatureChange, this); } // Temperature loss/gain from the area. var diff = properties.areaTemperature - properties.temperature; if (Mathf.Abs(diff) >= 0.01f) { var addTemperature = 1f * deltaTime; addTemperature = diff > 0 ? addTemperature : -addTemperature; properties.temperature += addTemperature; } else { properties.temperature = properties.areaTemperature; } prevProperties = properties; deltaTime = 1f + Random.Range(0, 0.5f); // Yied every 1-1.5f seconds in order to not pillow the thread with this coroutine. yield return new WaitForSeconds(deltaTime); } }