Skip to content

Commit

Permalink
Added a custom editor for ProbeMixer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keijiro Takahashi authored and Keijiro Takahashi committed Feb 11, 2014
1 parent 6288332 commit efa816d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 10 deletions.
66 changes: 66 additions & 0 deletions Assets/ProbePolisher/Editor/PolishableProbeMixerEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// ProbePolisher - Light Probe Editor Plugin for Unity
//
// Copyright (C) 2014 Keijiro Takahashi
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using UnityEngine;
using UnityEditor;
using System.Collections;

// Custom editor for the probe mixer.
[CustomEditor(typeof(PolishableProbeMixer))]
class PolishableProbeMixerEditor : Editor
{
SerializedProperty propSourceProbes;
SerializedProperty propMix;
SerializedProperty propIntensity;
SerializedProperty propUpdateSkybox;
SerializedProperty propSkyboxIntensity;

void OnEnable()
{
propSourceProbes = serializedObject.FindProperty("sourceProbes");
propMix = serializedObject.FindProperty("mix");
propIntensity = serializedObject.FindProperty("intensity");
propUpdateSkybox = serializedObject.FindProperty("updateSkybox");
propSkyboxIntensity = serializedObject.FindProperty("skyboxIntensity");
}

override public void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(propSourceProbes, true);

EditorGUILayout.Space();

EditorGUILayout.Slider(propMix, 0.0f, propSourceProbes.arraySize - 1, "Mix");
EditorGUILayout.Slider(propIntensity, 0.0f, 10.0f);

EditorGUILayout.Space();

EditorGUILayout.PropertyField(propUpdateSkybox);
if (propUpdateSkybox.boolValue)
EditorGUILayout.Slider(propSkyboxIntensity, 0.0f, 10.0f);

serializedObject.ApplyModifiedProperties();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions Assets/ProbePolisher/PolishableProbeMixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public class PolishableProbeMixer : MonoBehaviour
// Input light probes.
public LightProbes[] sourceProbes;

// Updates the skybox?
public bool updateSkybox;
// Mixing parameters.
public float mix = 0.0f;
public float intensity = 1.0f;
float prevMix = -1.0f;
float prevIntensity = -1.0f;

// Intensity of the skybox.
// Skybox parameters.
public bool updateSkybox = false;
public float skyboxIntensity = 1.0f;
float prevSkyboxIntensity;

// Mixing position.
public float mix;
float prevMix = -1.0f;

// Temporary objects.
LightProbes probe;
Material skybox;
Expand All @@ -53,7 +53,7 @@ void Awake ()
void Update ()
{
// Do nothing if nothing was changed.
if (mix == prevMix && skyboxIntensity == prevSkyboxIntensity) return;
if (mix == prevMix && intensity == prevIntensity && skyboxIntensity == prevSkyboxIntensity) return;

if (probe == null)
{
Expand Down Expand Up @@ -83,7 +83,7 @@ void Update ()
var coeffs = new Vector3[9];
var mixRate = mix - mixIndex;
for (var i = 0; i < 9; i++)
coeffs[i] = Vector3.Lerp(source1[i], source2[i], mixRate);
coeffs[i] = Vector3.Lerp(source1[i], source2[i], mixRate) * intensity;

// Update the probe with the mixed coefficients.
var temp = probe.coefficients;
Expand All @@ -98,6 +98,7 @@ void Update ()
}

prevMix = mix;
prevIntensity = intensity;
prevSkyboxIntensity = skyboxIntensity;
}
}
3 changes: 2 additions & 1 deletion Assets/Test.unity
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ MonoBehaviour:
- {fileID: 19700000, guid: cf691805761a4403db8e744c251d192c, type: 2}
- {fileID: 19700000, guid: e2583220faf8d4cd79ffb91a12681b62, type: 2}
- {fileID: 19700000, guid: f48abba2be5ee44b9bcbfc2551cca947, type: 2}
mix: 0
intensity: 1
updateSkybox: 1
skyboxIntensity: 1
mix: 0
--- !u!81 &642751785
AudioListener:
m_ObjectHideFlags: 0
Expand Down

0 comments on commit efa816d

Please sign in to comment.