コード例 #1
0
        /// <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()
        {
            if (MapsService == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(
                                   this, MapsService, "Maps Service", "is required for this script to work."));

                return;
            }

            // 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 };
            }
        }
コード例 #2
0
        /// <summary>
        /// Verify that all required parameters have been correctly defined, returning false if not.
        /// </summary>
        private bool VerifyParameters()
        {
            // TODO(b/149056787): Standardize parameter verification across scripts.
            // Verify that a Ground plane has been given.
            if (Ground == null)
            {
                Debug.LogError(ExampleErrors.MissingParameter(this, Ground, "Ground"));

                return(false);
            }

            // Verify that there is a Camera.main in the scene (i.e. a Camera that is tagged:
            // "MainCamera").
            if (Camera.main == null)
            {
                Debug.LogError(ExampleErrors.NullMainCamera(this));

                return(false);
            }

            // If have reached this point then we have verified all required parameters.
            return(true);
        }