Example #1
0
        /// <summary>
        /// Applies the texture data in the <c>XRTextureDescriptor</c> to the reflection probe settings.
        /// </summary>
        /// <param name="textureDescriptor">The environment texture data to apply to the reflection probe baked
        /// texture.</param>
        void UpdateEnvironmentTexture(XRTextureDescriptor textureDescriptor)
        {
            // If the current environment texture equals the given environment texture, the texture does not need to be
            // updated.
            if (m_CurrentTextureDescriptor.Equals(textureDescriptor))
            {
                return;
            }

            // Get the current baked texture as a cubemap, if any.
            Cubemap cubemapTexture = m_ReflectionProbe.customBakedTexture as Cubemap;

#if UNITY_2019_1_OR_NEWER
            const bool k_NoCubemapUpdate = false;
#else
            const bool k_NoCubemapUpdate = true;
#endif

            // If there is no current reflection probe texture or if the current environment texture data is not
            // identical to the given environment texture metadata, then we need to create a new environment texture
            // object.
            if (k_NoCubemapUpdate || (cubemapTexture == null) ||
                !m_CurrentTextureDescriptor.hasIdenticalTextureMetadata(textureDescriptor))
            {
                // Destroy any previous texture object.
                if (m_ReflectionProbe.customBakedTexture != null)
                {
                    Object.Destroy(m_ReflectionProbe.customBakedTexture);
                }

                // Create a new environment texture object.
                m_ReflectionProbe.customBakedTexture = CreateEnvironmentTexture(textureDescriptor);
            }
#if UNITY_2019_1_OR_NEWER
            else
            {
                // Else, we have a current texture object with identical metadata, we simply update the external
                // texture with the native texture.
                cubemapTexture.UpdateExternalTexture(textureDescriptor.nativeTexture);
            }
#endif

            // Update the current environment texture metadata.
            m_CurrentTextureDescriptor = textureDescriptor;
        }