private void TextureGUI()
{
data.curve = UGL.CurveField(data.curve);
int?toRemove = null;
for (int i = 0; i < data.textureNames.Count; i++)
{
UGL.BeginHorizontal();
data.textureNames[i] = UGL.DelayedTextField(data.textureNames[i], GUILayout.MaxWidth(Screen.width));
GUILayout.FlexibleSpace();
Texture2D oldVal = i < data.textures.Count ? data.textures[i]: null;
Texture2D newVal = (Texture2D)UGL.ObjectField("", oldVal, typeof(Texture2D), true, GUILayout.Width(100));
UGL.BeginVertical();
if (GUILayout.Button("Set As Curve", GUILayout.Width(100)))
{
Texture2D text = new Texture2D(100, 1);
for (int j = 0; j < text.width; j++)
{
float sample = data.curve.Evaluate((float)j / text.width);
text.SetPixel(j, 0, new Color(sample, sample, sample));
}
text.Apply();
if (text != oldVal)
{
string path = AssetDatabase.GetAssetPath(data);
AssetDatabase.AddObjectToAsset(text, path);
newVal = text;
}
}
GUI.color = Color.red;
if (GUILayout.Button("-", GUILayout.Width(100)))
{
toRemove = i;
}
UGL.EndVertical();
GUI.color = Color.white;
if (oldVal != newVal)
{
if (!data.textures.Contains(oldVal))
{
data.textures.Add(newVal);
}
else
{
data.textures[data.textures.IndexOf(oldVal)] = newVal;
}
}
UGL.EndHorizontal();
}
if (toRemove != null)
{
data.textureNames.RemoveAt((int)toRemove);
}
}