private static IMemberAccessor GetAccessor(object target, string propName, out System.Type memberType) { string args = null; if (propName != null) { int fi = propName.IndexOf("("); if (fi >= 0) { int li = propName.LastIndexOf(")"); if (li < fi) { li = propName.Length; } args = propName.Substring(fi + 1, li - fi - 1); propName = propName.Substring(0, fi); } } ITweenMemberAccessor acc; if (CustomTweenMemberAccessorFactory.TryGetMemberAccessor(target, propName, out acc)) { memberType = acc.Init(target, propName, args); return(acc); } //return MemberAccessorPool.GetAccessor(target.GetType(), propName, out memberType); return(MemberAccessorPool.GetDynamicAccessor(target, propName, out memberType)); }
public static string ReflectedPropertyAndCustomTweenAccessorField(Rect position, GUIContent label, object targObj, string selectedMemberName, DynamicMemberAccess access, out System.Type propType) { if (targObj != null) { var members = DynamicUtil.GetEasilySerializedMembers(targObj, System.Reflection.MemberTypes.Field | System.Reflection.MemberTypes.Property, access).ToArray(); var accessors = CustomTweenMemberAccessorFactory.GetCustomAccessorIds(targObj.GetType()); System.Array.Sort(accessors); using (var entries = TempCollection.GetList <GUIContent>(members.Length)) { int index = -1; for (int i = 0; i < members.Length; i++) { var m = members[i]; if ((DynamicUtil.GetMemberAccessLevel(m) & DynamicMemberAccess.Write) != 0) { entries.Add(EditorHelper.TempContent(string.Format("{0} ({1}) -> {2}", m.Name, DynamicUtil.GetReturnType(m).Name, DynamicUtil.GetValueWithMember(m, targObj)))); } else { entries.Add(EditorHelper.TempContent(string.Format("{0} (readonly - {1}) -> {2}", m.Name, DynamicUtil.GetReturnType(m).Name, DynamicUtil.GetValueWithMember(m, targObj)))); } if (index < 0 && m.Name == selectedMemberName) { //index = i; index = entries.Count - 1; } } for (int i = 0; i < accessors.Length; i++) { entries.Add(EditorHelper.TempContent(accessors[i])); if (index < 0 && accessors[i] == selectedMemberName) { index = entries.Count - 1; } } index = EditorGUI.Popup(position, label, index, entries.ToArray()); //selectedMember = (index >= 0) ? members[index] : null; //return (selectedMember != null) ? selectedMember.Name : null; if (index < 0) { propType = null; return(null); } else if (index < members.Length) { propType = DynamicUtil.GetReturnType(members[index]); return(members[index].Name); } else { var nm = accessors[index - members.Length]; ITweenMemberAccessor acc; if (CustomTweenMemberAccessorFactory.TryGetMemberAccessor(targObj, nm, out acc)) { propType = acc.GetMemberType(); if (VariantReference.AcceptableType(propType)) { return(nm); } } } propType = null; return(null); } } else { propType = null; EditorGUI.Popup(position, label, -1, new GUIContent[0]); return(null); } }