public override void OnInspectorGUI()
        {
            RenderCloudCubemap settings = this.target as RenderCloudCubemap;

            Camera cam = settings.GetComponent <Camera>();

            cam.gameObject.transform.position = Vector3.zero;
            cam.gameObject.transform.rotation = Quaternion.identity;

            EditorGUILayout.BeginVertical();
            EditorGUILayout.PropertyField(this.serializedObject.FindProperty("filenamePrefix"));
            EditorGUILayout.PropertyField(this.serializedObject.FindProperty("faceWidth"));
            EditorGUILayout.PropertyField(this.serializedObject.FindProperty("textureFormat"));
            EditorGUILayout.PropertyField(this.serializedObject.FindProperty("exportFaces"));

            if (settings.filenamePrefix == null || settings.filenamePrefix.Length <= 0)
            {
                settings.filenamePrefix = RenderCloudCubemap.kDefaultFilenamePrefix;
            }

            // Stamp the texture format so it's easier for user to select Sky Studio cloud type later.
            string scenePath      = Path.GetDirectoryName(SceneManager.GetActiveScene().path);
            string filenamePrefix = scenePath + "/" + settings.filenamePrefix + "-" + settings.textureFormat;

            if (GUILayout.Button("Render Cubemap"))
            {
                if (settings.textureFormat == RenderCloudCubemap.CubemapTextureFormat.RGBColor)
                {
                    Debug.Log("Rendering RGB color cubemap (additive texture)...");
                    Cubemap cubemap = RenderRGBColor(settings, cam);
                    RenderCubemapToTexture(cubemap, settings.faceWidth, Color.black, TextureFormat.RGB24,
                                           settings.exportFaces, filenamePrefix, false);
                }
                else if (settings.textureFormat == RenderCloudCubemap.CubemapTextureFormat.RGBAColor)
                {
                    Debug.Log("Rendering RGBA color cubemap (alpha texture)...");
                    Cubemap cubemap = RenderRGBAColor(settings, cam);
                    RenderCubemapToTexture(cubemap, settings.faceWidth, Color.clear, TextureFormat.RGBA32,
                                           settings.exportFaces, filenamePrefix, true);
                }
                else if (settings.textureFormat == RenderCloudCubemap.CubemapTextureFormat.RGBALit)
                {
                    Debug.Log("Rendering RGBA normal lit cubemap (normals encoded)...");
                    Cubemap cubemap = RenderRGBANormal(settings, cam);
                    RenderCubemapToTexture(cubemap, settings.faceWidth, Color.clear, TextureFormat.RGBA32,
                                           settings.exportFaces, filenamePrefix, false);
                }
                else
                {
                    Debug.LogError("Invalid texture format, can't render cubemap.");
                    return;
                }
            }
            EditorGUILayout.EndVertical();

            this.serializedObject.ApplyModifiedProperties();
        }
        private Cubemap RenderRGBAColor(RenderCloudCubemap settings, Camera cam)
        {
            Cubemap cubemap = new Cubemap(settings.faceWidth, TextureFormat.RGBA32, false);

            cam.ResetReplacementShader();
            cam.backgroundColor = Color.clear;
            cam.RenderToCubemap(cubemap);
            cam.targetTexture = null;

            return(cubemap);
        }
        private Cubemap RenderRGBANormal(RenderCloudCubemap settings, Camera cam)
        {
            Cubemap cubemap = new Cubemap(settings.faceWidth, TextureFormat.RGBA32, false);

            Shader normalShader = Shader.Find("Funly/Sky Studio/Utility/World Normal");

            cam.backgroundColor = Color.clear;
            cam.SetReplacementShader(normalShader, "");
            cam.RenderToCubemap(cubemap);
            cam.ResetReplacementShader();
            cam.targetTexture = null;

            return(cubemap);
        }