private PropertyEditorState DrawPropertyEditor(IEnumerable<UTConfigurableProperty> properties, PropertyEditorState state,
		DoAdd doAdd, PropertyExists propertyExists, DoDelete doDelete, UObject undoTarget)
    {
        EditorGUILayout.BeginVertical ();

        EditorGUILayout.BeginHorizontal ();

        state.newPropertyName = EditorGUILayout.TextField ("Name", state.newPropertyName);
        GUI.enabled = !string.IsNullOrEmpty (state.newPropertyName) && UTContext.IsValidPropertyName (state.newPropertyName) && !propertyExists (state.newPropertyName);
        if (GUILayout.Button ("Add", UTEditorResources.ExpressionButtonStyle)) {
            if (undoTarget != null) {
                CUUndoUtility.RegisterUndo (undoTarget, "Add Property");
            }
            doAdd (state.newPropertyName);
            state.newPropertyName = "";
        }

        GUI.enabled = true;
        EditorGUILayout.EndHorizontal ();
        EditorGUILayout.Space ();
        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
        var index = 0;
        foreach (var property in properties) {
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal ();

            if (!property.UseExpression) {
                if (property.IsPrivate) {
                    property.Value = EditorGUILayout.PasswordField (property.Name, property.Value);
                } else {
                    property.Value = EditorGUILayout.TextField (property.Name, property.Value);
                }
                if (property.SupportsPrivate) {
                    if (GUILayout.Button (property.IsPrivate ? UTEditorResources.PrivateIcon : UTEditorResources.PublicIcon, UTEditorResources.DeleteButtonStyle)) {
                        property.IsPrivate = !property.IsPrivate;
                        GUIUtility.keyboardControl = 0; // make textfield update.
                    }
                }
            } else {
                property.Expression = EditorGUILayout.TextField (property.Name, property.Expression);
            }

            if (GUILayout.Button (UTEditorResources.DeleteIcon, UTEditorResources.DeleteButtonStyle)) {
                if (undoTarget != null) {
                    CUUndoUtility.RegisterUndo (undoTarget, "Remove property");
                }
                doDelete (property);
                GUIUtility.ExitGUI ();
            }

            var oldExpression = property.UseExpression;
            property.UseExpression = GUILayout.Toggle (oldExpression, UTEditorResources.ExpressionButton, UTEditorResources.ExpressionButtonStyle);

            if (oldExpression != property.UseExpression) {
                GUIUtility.keyboardControl = 0; // make textfield update.
            }

            EditorGUILayout.EndHorizontal ();

            if (!property.UseExpression && property.Value.Contains ("$")) {
                EditorGUILayout.HelpBox (UTEditorResources.VariableWarningText, MessageType.Warning);
            }
            EditorGUILayout.EndVertical();
            index++;
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical ();
        return state;
    }
예제 #2
0
    private PropertyEditorState DrawPropertyEditor(IEnumerable <UTConfigurableProperty> properties, PropertyEditorState state,
                                                   DoAdd doAdd, PropertyExists propertyExists, DoDelete doDelete, UObject undoTarget)
    {
        EditorGUILayout.BeginVertical();

        EditorGUILayout.BeginHorizontal();

        state.newPropertyName = EditorGUILayout.TextField("Name", state.newPropertyName);
        GUI.enabled           = !string.IsNullOrEmpty(state.newPropertyName) && UTContext.IsValidPropertyName(state.newPropertyName) && !propertyExists(state.newPropertyName);
        if (GUILayout.Button("Add", UTEditorResources.ExpressionButtonStyle))
        {
            if (undoTarget != null)
            {
                CUUndoUtility.RegisterUndo(undoTarget, "Add Property");
            }
            doAdd(state.newPropertyName);
            state.newPropertyName = "";
        }

        GUI.enabled = true;
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();
        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
        var index = 0;

        foreach (var property in properties)
        {
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();

            if (!property.UseExpression)
            {
                if (property.IsPrivate)
                {
                    property.Value = EditorGUILayout.PasswordField(property.Name, property.Value);
                }
                else
                {
                    property.Value = EditorGUILayout.TextField(property.Name, property.Value);
                }
                if (property.SupportsPrivate)
                {
                    if (GUILayout.Button(property.IsPrivate ? UTEditorResources.PrivateIcon : UTEditorResources.PublicIcon, UTEditorResources.DeleteButtonStyle))
                    {
                        property.IsPrivate         = !property.IsPrivate;
                        GUIUtility.keyboardControl = 0;                         // make textfield update.
                    }
                }
            }
            else
            {
                property.Expression = EditorGUILayout.TextField(property.Name, property.Expression);
            }

            if (GUILayout.Button(UTEditorResources.DeleteIcon, UTEditorResources.DeleteButtonStyle))
            {
                if (undoTarget != null)
                {
                    CUUndoUtility.RegisterUndo(undoTarget, "Remove property");
                }
                doDelete(property);
                GUIUtility.ExitGUI();
            }

            var oldExpression = property.UseExpression;
            property.UseExpression = GUILayout.Toggle(oldExpression, UTEditorResources.ExpressionButton, UTEditorResources.ExpressionButtonStyle);

            if (oldExpression != property.UseExpression)
            {
                GUIUtility.keyboardControl = 0;                 // make textfield update.
            }

            EditorGUILayout.EndHorizontal();

            if (!property.UseExpression && property.Value.Contains("$"))
            {
                EditorGUILayout.HelpBox(UTEditorResources.VariableWarningText, MessageType.Warning);
            }
            EditorGUILayout.EndVertical();
            index++;
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
        return(state);
    }