Game Development Reference
In-Depth Information
An appropriate Inspector property for this data type would be a slider control as
with the Range attribute, which controls the interpolated color between 0 and 1 ,
as shown here:
Lerping between two colors
In essence then, we need to customize the editor such that whenever an object is
selected in the scene, which has a public member of a custom type we specify, we'll
want to customize how the member is rendered inside the Object Inspector. This lets us
present custom controls and inputs in the Object Inspector, which validates data entry
for that member as opposed to simply accepting its defaults. To begin this process,
let's create a custom class and define all data for a total color blend. A color blend
requires four variables, namely the SourceColor and DestColor marking the limits of
the blend. Next, the BlendFactor is a normalized float between 0 and 1 (start and end)
which determines which intermediary color should be generated through Lerping.
And then, finally, the output color itself ( BlendedColor ). The complete class definition
for this process is included in the following code sample 8-5:
[System.Serializable]
public class ColorBlend : System.Object
{
public Color SourceColor = Color.white;
public Color DestColor = Color.white;
public Color BlendedColor = Color.white;
public float BlendFactor = 0f;
}
 
Search WWH ::




Custom Search