Exemplo n.º 1
0
        /// <summary>
        /// Find a serialized parameter override using an expression instead of a string. This is
        /// safer as it helps avoiding typos and make code refactoring easier.
        /// </summary>
        /// <typeparam name="TValue">The serialized value type</typeparam>
        /// <param name="expr">The expression to parse to reach the parameter override</param>
        /// <returns>A <see cref="SerializedParameterOverride"/> or <c>null</c> if none was
        /// found</returns>
        /// <example>
        /// <code>
        /// [Serializable]
        /// public class MyEffect : PostProcessEffectSettings
        /// {
        ///     public FloatParameter myParameter = new FloatParameter { value = 1f };
        /// }
        ///
        /// [PostProcessEditor(typeof(MyEffect))]
        /// public class MyEffectEditor : PostProcessEffectEditor&lt;MyEffect&gt;
        /// {
        ///     SerializedParameterOverride m_MyParameter;
        ///
        ///     public override void OnEnable()
        ///     {
        ///         m_MyParameter = FindParameterOverride(x => x.myParameter);
        ///     }
        /// }
        /// </code>
        /// </example>
        /// <seealso cref="SerializedParameterOverride"/>
        protected SerializedParameterOverride FindParameterOverride <TValue>(Expression <Func <T, TValue> > expr)
        {
            var property   = serializedObject.FindProperty(RuntimeUtilities.GetFieldPath(expr));
            var attributes = RuntimeUtilities.GetMemberAttributes(expr);

            return(new SerializedParameterOverride(property, attributes));
        }