コード例 #1
0
    public override void OnInspectorGUI()
    {
        bool dirty = false;
        Sky  sky   = target as Sky;

        //sync GUI from sky
        camExposure     = sky.camExposure;
        masterIntensity = sky.masterIntensity;
        skyIntensity    = sky.skyIntensity;
        diffIntensity   = sky.diffIntensity;
        specIntensity   = sky.specIntensity;

        //sync and sync from CubeGUIs
        dirty |= updateCube(ref sky.skyboxCube, ref sky.hdrSky, refSKY);
        dirty |= updateCube(ref sky.diffuseCube, ref sky.hdrDiff, refDIM);
        dirty |= updateCube(ref sky.specularCube, ref sky.hdrSpec, refSIM);

        bool showSkybox = EditorGUILayout.Toggle(new GUIContent("Show Skybox", "Toggles rendering the background image"), sky.showSkybox);

        if (showSkybox != sky.showSkybox)
        {
            Undo.RegisterUndo(sky, "Skybox Toggle");
            sky.showSkybox = showSkybox;
            // if we're toggling skyboxes off, clear the render settings material
            if (!sky.showSkybox)
            {
                RenderSettings.skybox = null;
            }
            dirty = true;
        }

        bool detect = EditorGUILayout.Toggle(new GUIContent("Auto-Detect Color Space", "If enabled, attempts to detect the project's gamma correction setting and enables/disables the Linear Space option accordingly"), sky.autoDetectColorSpace);

        if (detect != sky.autoDetectColorSpace)
        {
            Undo.RegisterUndo(sky, "Color-Space Detection Change");
            sky.autoDetectColorSpace = detect;
        }

        bool prevLinear = sky.linearSpace;

        if (sky.autoDetectColorSpace)
        {
            sky.linearSpace = PlayerSettings.colorSpace == ColorSpace.Linear;
        }
        EditorGUI.BeginDisabledGroup(sky.autoDetectColorSpace);
        bool userLinearSpace = EditorGUILayout.Toggle(new GUIContent("Linear Space", "Enable if gamma correction is enabled for this project (Edit -> Project Settings -> Player -> Color Space: Linear)"), sky.linearSpace);

        if (userLinearSpace != sky.linearSpace)
        {
            Undo.RegisterUndo(sky, "Color-Space Change");
            sky.linearSpace = userLinearSpace;
        }
        EditorGUI.EndDisabledGroup();
        if (prevLinear != sky.linearSpace)
        {
            dirty = true;
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        //sync sky from GUI
        EditorGUILayout.LabelField(new GUIContent("Master Intensity", "Multiplier on the Sky, Diffuse, and Specular cube intensities"));
        masterIntensity = EditorGUILayout.Slider(masterIntensity, 0f, 10f);
        if (sky.masterIntensity != masterIntensity)
        {
            Undo.RegisterUndo(sky, "Intensity Change");
            sky.masterIntensity = masterIntensity;
            dirty = true;
        }

        EditorGUILayout.LabelField(new GUIContent("Skybox Intensity", "Brightness of the skybox"));
        skyIntensity = EditorGUILayout.Slider(skyIntensity, 0f, 10f);
        if (sky.skyIntensity != skyIntensity)
        {
            Undo.RegisterUndo(sky, "Intensity Change");
            sky.skyIntensity = skyIntensity;
            dirty            = true;
        }

        EditorGUILayout.LabelField(new GUIContent("Diffuse Intensity", "Multiplier on the diffuse light put out by this sky"));
        diffIntensity = EditorGUILayout.Slider(diffIntensity, 0f, 10f);
        if (sky.diffIntensity != diffIntensity)
        {
            Undo.RegisterUndo(sky, "Intensity Change");
            sky.diffIntensity = diffIntensity;
            dirty             = true;
        }

        EditorGUILayout.LabelField(new GUIContent("Specular Intensity", "Multiplier on the specular light put out by this sky"));
        specIntensity = EditorGUILayout.Slider(specIntensity, 0f, 10f);
        if (sky.specIntensity != specIntensity)
        {
            Undo.RegisterUndo(sky, "Intensity Change");
            sky.specIntensity = specIntensity;
            dirty             = true;
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.LabelField(new GUIContent("Camera Exposure", "Multiplier on all light coming into the camera, including IBL, direct light, and glow maps"));
        camExposure = EditorGUILayout.Slider(camExposure, 0f, 10f);
        if (sky.camExposure != camExposure)
        {
            Undo.RegisterUndo(sky, "Exposure Change");
            sky.camExposure = camExposure;
            dirty           = true;
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        dirty |= GUI.changed;

        if (forceDirty)
        {
            forceDirty = false;
            dirty      = true;
        }

        //guess input path
        if (dirty)
        {
            string inPath = refSKY.fullPath;
            if (inPath.Length == 0)
            {
                inPath = refDIM.fullPath;
            }
            if (inPath.Length == 0)
            {
                inPath = refSIM.fullPath;
            }
            if (inPath.Length > 0)
            {
                int uscore = inPath.LastIndexOf("_");
                if (uscore > -1)
                {
                    inPath = inPath.Substring(0, uscore);
                }
                else
                {
                    inPath = Path.GetDirectoryName(inPath) + "/" + Path.GetFileNameWithoutExtension(inPath);
                }
                refSKY.inputPath         =
                    refDIM.inputPath     =
                        refSIM.inputPath = inPath;
            }
            else
            {
                refSKY.inputPath         =
                    refDIM.inputPath     =
                        refSIM.inputPath = "";
            }
        }

        //if the active sky is not whats selected, see whats up with that and try rebinding (catches re-activating disabled skies)
        if (Sky.activeSky != sky)
        {
            dirty = true;
        }

        if (!Application.isPlaying)
        {
            //if any of the cubemaps have changed, refresh the viewport
            if (dirty)
            {
                sky.Apply();                 //SkyInspector dirty
                SceneView.RepaintAll();
            }
            else
            {
                sky.ApplySkyTransform();
            }
        }
    }