/// <summary> /// Make sure the given <see cref="NearDistance"/> and <see cref="FarDistance"/> define a valid /// distance range. /// </summary> /// <returns> /// True if <see cref="NearDistance"/> and <see cref="FarDistance"/> are both positive, and if /// <see cref="NearDistance"/> is greater than <see cref="FarDistance"/> (otherwise a specific /// error message will be shown). /// </returns> private bool VerifyRange() { // Make sure both given distances are positive. if (NearDistance <= 0f) { Debug.LogError(ExampleErrors.NotGreaterThanZero(this, NearDistance, "Near Distance")); return(false); } if (FarDistance <= 0f) { Debug.LogError(ExampleErrors.NotGreaterThanZero(this, FarDistance, "Far Distance")); return(false); } // Make sure the given far distance is greater than near distance. if (FarDistance <= NearDistance) { Debug.LogError(ExampleErrors .NotGreaterThan(this, FarDistance, "Far Distance", NearDistance, "Near Distance")); return(false); } // If have reached this point then given near and far distances are valid, so return true. return(true); }
/// <summary> /// Verify that all required parameters have been correctly defined, returning false if not. /// </summary> private bool VerifyParameters() { // Verify that an Emission Controller has been defined. if (EmissionController == null) { Debug.LogError(ExampleErrors.MissingParameter(this, EmissionController, "Emission Controller", "to control the emission values of in-scene lights/windows")); return(false); } // Get required light on this gameObject and make sure it is a directional light. Light = GetComponent <Light>(); if (Light.type != LightType.Directional) { Debug.LogWarningFormat("{0}.{1} found a {2}-light attached to {0}, when a Directional Light " + "was expected.\n Changing type from {2} to Directional.", name, GetType(), Light.type); Light.type = LightType.Directional; } // Verify given Fog Distances. if (FogStart < 0f) { Debug.LogError(ExampleErrors.NotGreaterThanZero(this, FogStart, "Fog Start distance", ", as this represents the Linear Fog Start Distance for the scene")); return(false); } if (FogEnd < FogStart) { Debug.LogError(ExampleErrors.NotGreaterThan(this, FogEnd, "Fog End distance", FogStart, "Fog Start distance")); return(false); } // Verify given Render Distance is positive. if (RenderDistance < 0f) { Debug.LogError(ExampleErrors.NotGreaterThanZero(this, RenderDistance, "Render Distance", ", as this represents the Camera's far Clipping Plane")); return(false); } // If have reached this point then have verified that all required parts are present and // properly setup. return(true); }
/// <summary> /// Use <see cref="CameraController"/>'s OnMove event to detect when the <see cref="Camera"/> has /// moved far enough that the Floating Origin needs to be recentered. /// </summary> private void Awake() { // Verify a Camera Controller has been given. if (CameraController == null) { Debug.LogError(ExampleErrors.MissingParameter(this, CameraController, "Camera Controller", "to tell when the Camera has moved")); return; } // Verify that a valid Floating Origin range was given, i.e. that given distance was not // negative nor zero. Comparison is made to float.Epsilon instead of zero to account for float // rounding errors. if (FloatingOriginRange <= float.Epsilon) { Debug.LogError(ExampleErrors.NotGreaterThanZero(this, FloatingOriginRange, "Floating Origin Range", "to tell how far the Camera should move before the Floating " + "Origin is reset")); return; } // Store the required Dynamic Maps Service on this GameObject. DynamicMapsService = GetComponent <DynamicMapsService>(); // Store the starting position of the Camera. CameraOrigin = Camera.main.transform.position; // If no additional GameObjects have been set (to be moved when the world's Floating Origin is // recentered), set this array to be just Camera.main's GameObject. This is so that, by // default, the scene's Camera is moved when the world is recentered, resulting in a seamless // recentering of the world that should be invisible to the user. if (AdditionalGameObjects == null) { AdditionalGameObjects = new[] { Camera.main.gameObject }; } // Whenever the Camera moves, check to see if it has moved far enough that the world's Floating // Origin needs to be recentered. CameraController.OnMove.AddListener(TryMoveFloatingOrigin); }
/// <summary> /// Use <see cref="CameraController"/>'s OnMove event to detect when the <see cref="Camera"/> /// has moved far enough that the Floating Origin needs to be recentered. /// </summary> private void Awake() { // Verify a Camera Controller has been given. if (CameraController == null) { Debug.LogError(ExampleErrors.MissingParameter( this, CameraController, "Camera Controller", "to tell when the Camera has moved")); return; } // Verify that a valid Floating Origin range was given, i.e. that given distance was not // negative nor zero. Comparison is made to float.Epsilon instead of zero to account for float // rounding errors. if (FloatingOriginRange <= float.Epsilon) { Debug.LogError(ExampleErrors.NotGreaterThanZero( this, FloatingOriginRange, "Floating Origin Range", "to tell how far the Camera should move before the Floating " + "Origin is reset")); return; } // Store the initial position of the Camera on the ground plane. FloatingOrigin = GetCameraPositionOnGroundPlane(); // If no additional GameObjects have been set (to be moved when the world's Floating Origin is // recentered), set this array to be just Camera.main's GameObject. This is so that, by // default, the scene's Camera is moved when the world is recentered, resulting in a seamless // recentering of the world that should be invisible to the user. if (AdditionalGameObjects == null) { AdditionalGameObjects = new[] { Camera.main.gameObject }; } }