DelayedTextField() public static method

Make a delayed text field.

public static DelayedTextField ( GUIContent label, string text ) : string
label UnityEngine.GUIContent Optional label to display in front of the int field.
text string The text to edit.
return string
示例#1
0
        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);
            }
        }
示例#2
0
        private void FloatGUI()
        {
            int?toRemove = null;

            for (int i = 0; i < data.floatNames.Count; i++)
            {
                UGL.BeginHorizontal();
                data.floatNames[i] = UGL.DelayedTextField(data.floatNames[i], GUILayout.MaxWidth(Screen.width));
                GUILayout.FlexibleSpace();
                float oldVal = i < data.floats.Count?data.floats[i]:0;
                float newVal = UGL.FloatField(oldVal);
                GUILayout.FlexibleSpace();
                GUI.color = Color.red;
                if (GUILayout.Button("-", GUILayout.Width(100)))
                {
                    toRemove = i;
                }
                GUI.color = Color.white;
                if (oldVal != newVal)
                {
                    if (!data.floats.Contains(oldVal))
                    {
                        data.floats.Add(newVal);
                    }
                    else
                    {
                        data.floats[data.floats.IndexOf(oldVal)] = newVal;
                    }
                }
                UGL.EndHorizontal();
            }
            if (toRemove != null)
            {
                data.floatNames.RemoveAt((int)toRemove);
            }
        }