Ejemplo n.º 1
0
        /// <summary>
        ///     Draws a Save File field.
        /// </summary>
        /// <returns>The save path.</returns>
        /// <param name="position">Position.</param>
        /// <param name="label">Label.</param>
        /// <param name="path">Path.</param>
        /// <param name="extention">Extention.</param>
        public static string SaveFileField(Rect position, GUIContent label, string path, string extention)
        {
            Rect content = new Rect(position);

            content.width -= BROWSE_BUTTON_WIDTH;
            content.width -= STANDARD_HORIZONTAL_SPACING;

            EditorGUI.TextField(content, label, path);

            Rect buttonRect = new Rect(content);

            buttonRect.x    += content.width + STANDARD_HORIZONTAL_SPACING;
            buttonRect.width = BROWSE_BUTTON_WIDTH;

            Texture2D buttonTexture = EditorResourceCache.GetResource <Texture2D>("HydraCommon", "Textures",
                                                                                  BROWSE_BUTTON_TEXTURE_NAME);
            GUIStyle style = HydraEditorGUIStyles.PictureButtonStyle(buttonRect);

            bool pressed = DrawUnindented(() => GUI.Button(buttonRect, buttonTexture, style));

            if (pressed)
            {
                path = SaveFilePanel(label, path, extention);
            }

            return(path);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Behaves like a boolean field but draws a textured button.
        /// </summary>
        /// <param name="position">Position.</param>
        /// <param name="label">Label.</param>
        /// <param name="prop">Property.</param>
        /// <param name="trueTexture">True texture.</param>
        /// <param name="falseTexture">False texture.</param>
        public static void ToggleTexturesField(Rect position, GUIContent label, SerializedProperty prop, Texture2D trueTexture,
                                               Texture2D falseTexture)
        {
            label = EditorGUI.BeginProperty(position, label, prop);

            Rect contentPosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            contentPosition.width = contentPosition.height;

            GUIStyle  style         = HydraEditorGUIStyles.TextureButtonStyle(contentPosition);
            Texture2D buttonTexture = prop.boolValue ? trueTexture : falseTexture;

            bool pressed = GUI.Button(contentPosition, buttonTexture, style);

            if (pressed)
            {
                prop.boolValue = !prop.boolValue;
                GUI.changed    = true;
            }

            EditorGUI.EndProperty();
        }
        /// <summary>
        ///     Draws an array field contents.
        /// </summary>
        /// <param name="prop">Property.</param>
        /// <param name="elementLabel">Element label.</param>
        /// <param name="elementMethod">Element method.</param>
        public static void ArrayFieldContents(SerializedProperty prop, GUIContent elementLabel,
                                              Action <SerializedProperty, GUIContent> elementMethod = null)
        {
            for (int index = 0; index < prop.arraySize; index++)
            {
                Color oldColor = GUI.backgroundColor;
                if (EditorGUIUtility.isProSkin)
                {
                    GUI.backgroundColor = new Color(oldColor.r, oldColor.g, oldColor.b, 0.5f);
                }

                EditorGUILayout.BeginVertical(HydraEditorGUIStyles.ArrayElementStyle(index));

                GUI.backgroundColor = oldColor;

                s_StringBuilder.Length = 0;
                s_StringBuilder.Append(elementLabel.text);
                s_StringBuilder.Append(" ");
                s_StringBuilder.Append(index);

                SerializedProperty element = prop.GetArrayElementAtIndex(index);
                GUIContent         label   = new GUIContent(s_StringBuilder.ToString(), elementLabel.image, elementLabel.tooltip);

                if (elementMethod != null)
                {
                    elementMethod(element, label);
                }
                else
                {
                    EditorGUILayout.PropertyField(element, label);
                }

                EditorGUILayout.EndVertical();
            }

            ArrayFieldFooter(prop);
        }