Пример #1
0
        private static VariableValue DrawString(Rect rect, VariableValue value, StringVariableConstraint constraint)
        {
            var s = value.String;

            if (constraint != null && constraint.Values.Length > 0)
            {
                var index = Array.IndexOf(constraint.Values, s);
                index = EditorGUI.Popup(rect, index, constraint.Values);
                s     = index >= 0 ? constraint.Values[index] : string.Empty;
            }
            else
            {
                s = EditorGUI.TextField(rect, GUIContent.none, s);
            }

            return(s == null?VariableValue.Create(string.Empty) : VariableValue.Create(s));
        }
Пример #2
0
        private static void DrawStringConstraint(Rect rect, ref VariableConstraint constraint)
        {
            if (!(constraint is StringVariableConstraint stringConstraint))
            {
                stringConstraint = new StringVariableConstraint {
                    Values = new string[] { }
                };
                constraint = stringConstraint;
            }

            var remove = -1;

            for (var i = 0; i < stringConstraint.Values.Length; i++)
            {
                if (i != 0)
                {
                    RectHelper.TakeVerticalSpace(ref rect);
                }

                var item       = stringConstraint.Values[i];
                var itemRect   = RectHelper.TakeLine(ref rect);
                var removeRect = RectHelper.TakeTrailingIcon(ref itemRect);

                stringConstraint.Values[i] = EditorGUI.TextField(itemRect, item);

                if (GUI.Button(removeRect, _removeButton.Content, GUIStyle.none))
                {
                    remove = i;
                }
            }

            var addRect = RectHelper.TakeTrailingIcon(ref rect);

            if (GUI.Button(addRect, _addButton.Content, GUIStyle.none))
            {
                ArrayUtility.Add(ref stringConstraint.Values, string.Empty);
            }

            if (remove >= 0)
            {
                ArrayUtility.RemoveAt(ref stringConstraint.Values, remove);
            }
        }