public void Sleep() { _isAwake = false; if (stateSettings != null) { activeLODIndex = stateSettings.LODs.Count - 1; activeLOD = stateSettings.LODs[activeLODIndex]; } onSleep.Invoke(); }
public void LODCheck() { if (stateSettings == null) { return; } _lodCount = stateSettings.LODs.Count; if (!_isAwake && _lodCount > 0) // Vehicle is sleeping, force the highest lod { activeLODIndex = _lodCount - 1; activeLOD = stateSettings.LODs[activeLODIndex]; } else if (updateLODs) // Vehicle is awake, determine LOD based on distance { if (useCameraMainForLOD) { LODCamera = Camera.main; } else { if (LODCamera == null) { Debug.LogWarning("LOD camera is null. Set the LOD camera or enable 'useCameraMainForLOD' instead. Falling back to Camera.main."); LODCamera = Camera.main; } } if (_lodCount > 0 && LODCamera != null) { _cameraTransform = LODCamera.transform; stateSettings.LODs[_lodCount - 2].distance = Mathf.Infinity; // Make sure last non-sleep LOD is always matched vehicleToCamDistance = Vector3.Distance(vehicleTransform.position, _cameraTransform.position); for (int i = 0; i < _lodCount - 1; i++) { if (stateSettings.LODs[i].distance > vehicleToCamDistance) { activeLODIndex = i; activeLOD = stateSettings.LODs[i]; break; } } } else { activeLODIndex = -1; activeLOD = null; } } }