Beispiel #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));
        }
Beispiel #2
0
        public void AssertRegister <T>(Expression <Func <State, T> > exp, T value) where T : struct, IFormattable
        {
            var name     = RuntimeUtilities.GetFieldPath(exp);
            var selector = exp.Compile();
            var val      = selector(state);

            if (value is float)
            {
                Assert.AreEqual($"[{name}] {value}", $"[{name}] {val}");
            }
            else
            {
                Assert.AreEqual($"[{name}] 0x{value:X}", $"[{name}] 0x{val:X}");
            }
        }
Beispiel #3
0
 /// <summary>
 /// Find a serialized property 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 property</param>
 /// <returns>A <see cref="SerializedProperty"/> or <c>null</c> if none was found</returns>
 /// <example>
 /// <code>
 /// [Serializable]
 /// public class MyEffect : PostProcessEffectSettings
 /// {
 ///     public float myParameter = 1f;
 /// }
 ///
 /// [PostProcessEditor(typeof(MyEffect))]
 /// public class MyEffectEditor : PostProcessEffectEditor&lt;MyEffect&gt;
 /// {
 ///     SerializedProperty m_MyParameter;
 ///
 ///     public override void OnEnable()
 ///     {
 ///         m_MyParameter = FindProperty(x => x.myParameter);
 ///     }
 /// }
 /// </code>
 /// </example>
 /// <remarks>
 /// If you're trying to retrieve a <see cref="SerializedParameterOverride"/>, you should
 /// use <seealso cref="FindParameterOverride{TValue}"/> instead.
 /// </remarks>
 /// <seealso cref="SerializedProperty"/>
 /// <seealso cref="FindParameterOverride{TValue}"/>
 protected SerializedProperty FindProperty <TValue>(Expression <Func <T, TValue> > expr)
 {
     return(serializedObject.FindProperty(RuntimeUtilities.GetFieldPath(expr)));
 }
Beispiel #4
0
 SerializedProperty FindProperty <TValue>(Expression <Func <CinemachinePostProcessing, TValue> > expr)
 {
     return(serializedObject.FindProperty(RuntimeUtilities.GetFieldPath(expr)));
 }