Exemplo n.º 1
0
        /// <summary>
        /// Same as SerializedProperty.FindPropertyRelative but without the use of magic strings.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="property"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static SerializedProperty GetMemberProperty <T>(this SerializedProperty property, Expression <System.Func <T, object> > expression)
        {
            string             memberName     = StaticReflectionHelper.GetMemberName(expression).UnwrapOr("");
            SerializedProperty memberProperty = property.FindPropertyRelative(memberName);

            if (memberProperty == null)
            {
                memberProperty = property.Copy();
                if (!memberProperty.Next(true))
                {
                    return(null);
                }

                string niceMemberName = ObjectNames.NicifyVariableName(memberName);

                do
                {
                    string currentMemberNiceName = ObjectNames.NicifyVariableName(memberProperty.name);
                    if (string.Equals(niceMemberName, currentMemberNiceName))
                    {
                        return(memberProperty);
                    }
                } while(!memberProperty.Next(false));
            }

            return(memberProperty);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Same as SerializedProperty.FindProperty but without the use of magic strings.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="property"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static SerializedProperty GetMemberProperty <T>(this SerializedObject obj, Expression <System.Func <T, object> > expression)
        {
            string             memberName     = StaticReflectionHelper.GetMemberName(expression).UnwrapOr("");
            SerializedProperty memberProperty = obj.FindProperty(memberName);

            if (memberProperty == null)
            {
                memberProperty = obj.FindProperty("m_" + memberName);
                return(memberProperty);
            }

            return(memberProperty);
        }