/// <summary>
        /// Display the current string value setting to the inspector
        /// </summary>
        /// <param name="position">The position within the inspector that the UI elements should be displayed</param>
        /// <param name="parameterCaches">The parameter caches for the currently selected objects that store the current values of this parameter</param>
        /// <param name="label">The label that is attached to this parameter to be displayed</param>
        /// <returns>Returns true if an event occurred that requires the updating of cached values</returns>
        public override bool DisplayParameterValue(Rect position, PersistentParameterCache[] parameterCaches, GUIContent label)
        {
            //Check that this type is a string
            if (Processing != typeof(string))
            {
                return(DrawErrorMessage(position, label, "TextFieldArea Attribute is only usable on string types"));
            }

            //Cast the value to a string
            string val = (string)parameterCaches[0].Value;

            //Check if the contained values are different
            bool isDifferent = false;

            if (parameterCaches.Length > 1)
            {
                for (int i = 1; i < parameterCaches.Length; i++)
                {
                    //Retrieve this entries value
                    object newVal = parameterCaches[i].Value;

                    //If the values are different, flag it
                    if ((string)newVal != val)
                    {
                        isDifferent = true;
                        break;
                    }
                }
            }

            //Check if the element has changed
            bool modified = false;

            //Setup the UI if this is a mixed value
            using (GUIMixer.PushSegment(isDifferent)) {
                //Begin looking for changes
                EditorGUI.BeginChangeCheck();

                //If this type has a flags attribute, show a masking field
                EditorGUI.LabelField(new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight), label);
                string newVal = EditorGUI.TextArea(new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, position.height - EditorGUIUtility.singleLineHeight), val);

                //If the value changed, apply it
                if (EditorGUI.EndChangeCheck())
                {
                    modified = true;
                    for (int i = 0; i < parameterCaches.Length; i++)
                    {
                        parameterCaches[i].SetValue(newVal, Processing);
                    }
                }
            }

            //Return the modified flag
            return(modified);
        }
Пример #2
0
        /// <summary>
        /// Display the current Unity Object value setting to the inspector
        /// </summary>
        /// <param name="position">The position within the inspector that the UI elements should be displayed</param>
        /// <param name="parameterCaches">The parameter caches for the currently selected objects that store the current values of this parameter</param>
        /// <param name="label">The label that is attached to this parameter to be displayed</param>
        /// <returns>Returns true if an event occurred that requires the updating of cached values</returns>
        public override bool DisplayParameterValue(Rect position, PersistentParameterCache[] parameterCaches, GUIContent label)
        {
            //If we are not processing a UnityEngine.Object type, error report it
            if (!typeof(UnityEngine.Object).IsAssignableFrom(Processing))
            {
                return(DrawErrorMessage(position, label, "DisallowSceneObjects Attribute is only usable on UnityEngine.Object types"));
            }

            //Cast the value to a Unity Engine object
            UnityEngine.Object obj = (UnityEngine.Object)parameterCaches[0].Value;

            //Check if the contained values are different
            bool isDifferent = false;

            if (parameterCaches.Length > 1)
            {
                for (int i = 1; i < parameterCaches.Length; i++)
                {
                    //Retrieve this entries value
                    object newVal = parameterCaches[1].Value;

                    //If the values are different, flag it
                    if ((UnityEngine.Object)newVal != obj)
                    {
                        isDifferent = true;
                        break;
                    }
                }
            }

            //Check if the element has changed
            bool modified = false;

            //Setup the UI if this is a mixed value
            using (GUIMixer.PushSegment(isDifferent)) {
                //Begin looking for changes
                EditorGUI.BeginChangeCheck();

                //Show the color field
                UnityEngine.Object newObj = EditorGUI.ObjectField(position, label, obj, Processing, false);

                //If the value changed, apply it
                if (EditorGUI.EndChangeCheck())
                {
                    modified = true;
                    for (int i = 0; i < parameterCaches.Length; i++)
                    {
                        parameterCaches[i].SetValue(newObj, Processing);
                    }
                }
            }

            //Return the modified flag
            return(modified);
        }
Пример #3
0
        /// <summary>
        /// Display the current Quaternion value setting to the inspector
        /// </summary>
        /// <param name="position">The position within the inspector that the UI elements should be displayed</param>
        /// <param name="parameterCaches">The parameter caches for the currently selected objects that store the current values of this parameter</param>
        /// <param name="label">The label that is attached to this parameter to be displayed</param>
        /// <returns>Returns true if an event occurred that requires the updating of cached values</returns>
        public override bool DisplayParameterValue(Rect position, PersistentParameterCache[] parameterCaches, GUIContent label)
        {
            //Cast the value to a Quaternion
            Quaternion quaternion = (Quaternion)parameterCaches[0].Value;

            //Check if the contained values are different
            bool isDifferent = false;

            if (parameterCaches.Length > 1)
            {
                for (int i = 1; i < parameterCaches.Length; i++)
                {
                    //Retrieve this entries value
                    object newVal = parameterCaches[i].Value;

                    //If the values are different, flag it
                    if ((Quaternion)newVal != quaternion)
                    {
                        isDifferent = true;
                        break;
                    }
                }
            }

            //Check if the element has changed
            bool modified = false;

            //Setup the UI if this is a mixed value
            using (GUIMixer.PushSegment(isDifferent)) {
                //Begin looking for changes
                EditorGUI.BeginChangeCheck();

                //Show the Quaternion as a Vector field
                Vector4 newVector = EditorGUI.Vector4Field(position, label, new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w));

                //If the value changed, apply it
                if (EditorGUI.EndChangeCheck())
                {
                    //Create a quaternion from the vector value
                    quaternion = new Quaternion(newVector.x, newVector.y, newVector.z, newVector.w);

                    //Set the new value
                    modified = true;
                    for (int i = 0; i < parameterCaches.Length; i++)
                    {
                        parameterCaches[i].SetValue(quaternion, Processing);
                    }
                }
            }

            //Return the modified flag
            return(modified);
        }
Пример #4
0
        /// <summary>
        /// Display the current enum value setting to the inspector
        /// </summary>
        /// <param name="position">The position within the inspector that the UI elements should be displayed</param>
        /// <param name="parameterCaches">The parameter caches for the currently selected objects that store the current values of this parameter</param>
        /// <param name="label">The label that is attached to this parameter to be displayed</param>
        /// <returns>Returns true if an event occurred that requires the updating of cached values</returns>
        public override bool DisplayParameterValue(Rect position, PersistentParameterCache[] parameterCaches, GUIContent label)
        {
            //Cast the value to an enum
            Enum enumVal = (Enum)parameterCaches[0].Value;

            //Check if the contained values are different
            bool isDifferent = false;

            if (parameterCaches.Length > 1)
            {
                long rep = Convert.ToInt64(enumVal);
                for (int i = 1; i < parameterCaches.Length; i++)
                {
                    //Retrieve this entries value
                    object newVal = parameterCaches[i].Value;

                    //If the values are different, flag it
                    if (Convert.ToInt64(newVal) != rep)
                    {
                        isDifferent = true;
                        break;
                    }
                }
            }

            //Check if the element has changed
            bool modified = false;

            //Setup the UI if this is a mixed value
            using (GUIMixer.PushSegment(isDifferent)) {
                //Begin looking for changes
                EditorGUI.BeginChangeCheck();

                //Display a popup for the various enum options that can be selected
                Enum newVal = EditorGUI.EnumPopup(position, label, enumVal);

                //If the value changed, apply it
                if (EditorGUI.EndChangeCheck())
                {
                    modified = true;
                    for (int i = 0; i < parameterCaches.Length; i++)
                    {
                        parameterCaches[i].SetValue(newVal, Processing);
                    }
                }
            }

            //Return the modified flag
            return(modified);
        }
Пример #5
0
        /// <summary>
        /// Display the current color value setting to the inspector
        /// </summary>
        /// <param name="position">The position within the inspector that the UI elements should be displayed</param>
        /// <param name="parameterCaches">The parameter caches for the currently selected objects that store the current values of this parameter</param>
        /// <param name="label">The label that is attached to this parameter to be displayed</param>
        /// <returns>Returns true if an event occurred that requires the updating of cached values</returns>
        public override bool DisplayParameterValue(Rect position, PersistentParameterCache[] parameterCaches, GUIContent label)
        {
            //Cast the value to a color
            Color color = (Color)parameterCaches[0].Value;

            //Check if the contained values are different
            bool isDifferent = false;

            if (parameterCaches.Length > 1)
            {
                for (int i = 1; i < parameterCaches.Length; i++)
                {
                    //Retrieve this entries value
                    object newVal = parameterCaches[i].Value;

                    //If the values are different, flag it
                    if ((Color)newVal != color)
                    {
                        isDifferent = true;
                        break;
                    }
                }
            }

            //Check if the element has changed
            bool modified = false;

            //Setup the UI if this is a mixed value
            using (GUIMixer.PushSegment(isDifferent)) {
                //Begin looking for changes
                EditorGUI.BeginChangeCheck();

                //Show the color field
                Color newColor = EditorGUI.ColorField(position, label, color);

                //If the value changed, apply it
                if (EditorGUI.EndChangeCheck())
                {
                    modified = true;
                    for (int i = 0; i < parameterCaches.Length; i++)
                    {
                        parameterCaches[i].SetValue(newColor, Processing);
                    }
                }
            }

            //Return the modified flag
            return(modified);
        }
Пример #6
0
        /// <summary>
        /// Display the current numeric value setting to the inspector
        /// </summary>
        /// <param name="position">The position within the inspector that the UI elements should be displayed</param>
        /// <param name="parameterCaches">The parameter caches for the currently selected objects that store the current values of this parameter</param>
        /// <param name="label">The label that is attached to this parameter to be displayed</param>
        /// <returns>Returns true if an event occurred that requires the updating of cached values</returns>
        public override bool DisplayParameterValue(Rect position, PersistentParameterCache[] parameterCaches, GUIContent label)
        {
            //Check that the type is valid
            if (Processing != typeof(int) && Processing != typeof(float))
            {
                return(DrawErrorMessage(position, label, "NumericRange Attribute is only usable on int/float types"));
            }

            //Get the value of the primary cache object
            object currentObj = parameterCaches[0].Value;

            //Check if the element has changed
            bool modified = false;

            //Get the attribute value
            NumericRangeAttribute att = Attribute as NumericRangeAttribute;

            //Process the value as a float
            if (currentObj is float)
            {
                //Cast the value to a float
                float val = (float)currentObj;

                //Check if the contained values are different
                bool isDifferent = false;
                if (parameterCaches.Length > 1)
                {
                    for (int i = 1; i < parameterCaches.Length; i++)
                    {
                        //Retrieve this entries value
                        object newVal = parameterCaches[i].Value;

                        //If the values are different, flag it
                        if ((float)newVal != val)
                        {
                            isDifferent = true;
                            break;
                        }
                    }
                }

                //Setup the UI if this is a mixed value
                using (GUIMixer.PushSegment(isDifferent)) {
                    //Begin looking for changes
                    EditorGUI.BeginChangeCheck();

                    //If this type has a flags attribute, show a masking field
                    float newVal = EditorGUI.Slider(position, label, val, att.Min, att.Max);

                    //If the value changed, apply it
                    if (EditorGUI.EndChangeCheck())
                    {
                        modified = true;
                        for (int i = 0; i < parameterCaches.Length; i++)
                        {
                            parameterCaches[i].SetValue(newVal, Processing);
                        }
                    }
                }
            }

            //Process the value as an integer
            else
            {
                //Cast the value to a integer
                int val = (int)currentObj;

                //Check if the contained values are different
                bool isDifferent = false;
                if (parameterCaches.Length > 1)
                {
                    for (int i = 1; i < parameterCaches.Length; i++)
                    {
                        //Retrieve this entries value
                        object newVal = parameterCaches[i].Value;

                        //If the values are different, flag it
                        if ((int)newVal != val)
                        {
                            isDifferent = true;
                            break;
                        }
                    }
                }

                //Setup the UI if this is a mixed value
                using (GUIMixer.PushSegment(isDifferent)) {
                    //Begin looking for changes
                    EditorGUI.BeginChangeCheck();

                    //If this type has a flags attribute, show a masking field
                    int newVal = EditorGUI.IntSlider(position, label, val, (int)att.Min, (int)att.Max);

                    //If the value changed, apply it
                    if (EditorGUI.EndChangeCheck())
                    {
                        modified = true;
                        for (int i = 0; i < parameterCaches.Length; i++)
                        {
                            parameterCaches[i].SetValue(newVal, Processing);
                        }
                    }
                }
            }

            //Return the modified flag
            return(modified);
        }
Пример #7
0
        /// <summary>
        /// Display the current enum value setting to the inspector
        /// </summary>
        /// <param name="position">The position within the inspector that the UI elements should be displayed</param>
        /// <param name="parameterCaches">The parameter caches for the currently selected objects that store the current values of this parameter</param>
        /// <param name="label">The label that is attached to this parameter to be displayed</param>
        /// <returns>Returns true if an event occurred that requires the updating of cached values</returns>
        public override bool DisplayParameterValue(Rect position, PersistentParameterCache[] parameterCaches, GUIContent label)
        {
            //Cast the value to an enum
            Enum enumVal = (Enum)parameterCaches[0].Value;

            //Check if the contained values are different
            bool isDifferent = false;

            if (parameterCaches.Length > 1)
            {
                for (int i = 1; i < parameterCaches.Length; i++)
                {
                    //Retrieve this entries value
                    object newObj = parameterCaches[i].Value;

                    //Get the value as an enum
                    Enum newVal = (Enum)newObj;

                    //If the values are different, flag it
                    if ((enumVal == null && newVal != null) ||
                        (enumVal != null && newVal == null) ||
                        (enumVal.GetType() != newVal.GetType()) ||
                        (Convert.ToInt64(enumVal) != Convert.ToInt64(newVal)))
                    {
                        isDifferent = true;
                        break;
                    }
                }
            }

            //Check if the element has changed
            bool modified = false;

            //Setup the UI if this is a mixed value
            using (GUIMixer.PushSegment(isDifferent)) {
                //Begin looking for changes
                EditorGUI.BeginChangeCheck();

                //Convert the current option to an index
                int curIndex = (enumVal != null && ENUM_TO_INDEX.ContainsKey(enumVal) ? ENUM_TO_INDEX[enumVal] : -1);

                //Show the text options for the available selection options
                int newIndex = EditorGUI.Popup(new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight), label, curIndex, GENERIC_OPTION_LABELS);

                //If the value changed, apply it
                if (EditorGUI.EndChangeCheck())
                {
                    //Convert the new index to a usable value
                    Enum convertVal = (INDEX_TO_ENUM.ContainsKey(newIndex) ? INDEX_TO_ENUM[newIndex] : null);

                    //Apply the new value to the options
                    modified = true;
                    for (int i = 0; i < parameterCaches.Length; i++)
                    {
                        parameterCaches[i].SetValue(convertVal, convertVal.GetType());
                    }
                }
            }

            //Display the help box describing how to add options
            EditorGUI.HelpBox(
                new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 1.25f, position.width, EditorGUIUtility.singleLineHeight * 2f),
                "To add enum options to this list, attach a [GenericEnumOption] attribute to the enum type definition",
                MessageType.Info
                );

            //Return the modified flag
            return(modified);
        }