Example #1
0
        /// <summary>
        /// Get the tooltip of the property, return <c>string.Empty</c> if none.
        /// </summary>
        ///
        /// <remarks>
        /// The built-in <c>SerializedProperty.tooltip</c> never works with unknown reason.
        /// This uses <c>EditorGUI.BeginProperty()</c> to fetch the tooltip, must be called in <c>OnGUI()</c>.
        /// </remarks>
        ///
        /// <returns>The tooltip.</returns>
        /// <param name="property">Property.</param>
        ///
        public static string GetTooltip(this SerializedProperty property)
        {
            property.CheckValid();

            var _result = EditorGUI.BeginProperty(new Rect(), GUIContent.none, property).tooltip;

            EditorGUI.EndProperty();

            return(_result ?? "");
        }
Example #2
0
        /// <summary>
        /// Check if the property is a valid array property.
        /// </summary>
        /// <param name="property">Property.</param>
        public static void CheckArray(this SerializedProperty property)
        {
            property.CheckValid();
            if (property.isArray && SerializedPropertyType.String != property.propertyType)
            {
                return;
            }

            var _format = "SerializedProperty '{0}' isn't an array.";

            throw new NotSupportedException(string.Format(_format, property.propertyPath));
        }
Example #3
0
        /// <summary>
        /// Get the parent <c>UnityEditor.SerializedProperty</c> contains this.
        /// </summary>
        ///
        /// <remarks>
        /// Return <c>null</c> if this is a root within target object.
        /// </remarks>
        ///
        /// <returns>The parent.</returns>
        /// <param name="property">Property.</param>
        ///
        public static SerializedProperty GetParent(this SerializedProperty property)
        {
            property.CheckValid();

            var _path = property.propertyPath;

            if (!_path.Contains("."))
            {
                return(null);
            }

            _path = _path.Remove(_path.LastIndexOf(_path.EndsWith("]") ? ".Array.data[" : "."));
            return(property.serializedObject.FindProperty(_path));
        }