1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System;
- using System.Linq.Expressions;
- namespace UnityEditor.Recorder
- {
- static class SerializableObjHelper
- {
- public static SerializedProperty FindPropertyRelative(this SerializedProperty obj, Expression<Func<object>> exp)
- {
- var body = exp.Body as MemberExpression;
- if (body == null)
- {
- var ubody = (UnaryExpression)exp.Body;
- body = ubody.Operand as MemberExpression;
- }
- var name = body.Member.Name;
- return obj.FindPropertyRelative(name);
- }
- }
- class PropertyFinder<TType> where TType : class
- {
- SerializedObject m_Obj;
- public PropertyFinder(SerializedObject obj)
- {
- m_Obj = obj;
- }
- public delegate TResult FuncX<TResult>(TType x);
- public SerializedProperty Find( Expression<FuncX<object>> exp)
- {
- var body = exp.Body as MemberExpression;
- if (body == null)
- {
- var ubody = (UnaryExpression)exp.Body;
- body = ubody.Operand as MemberExpression;
- }
- var name = body.Member.Name;
- return m_Obj.FindProperty(name);
- }
- }
- }
|