public static bool TryGetMemberAccessorInfo(object target, string name, out CustomAccessorData data)
        {
            if (target == null)
            {
                data = default(CustomAccessorData);
                return(false);
            }
            if (_targetToCustomAccessor == null)
            {
                BuildAccessorDictionary();
            }

            IList <CustomAccessorData> lst;

            if (_targetToCustomAccessor.Lists.TryGetList(name, out lst))
            {
                var tp = target.GetType();
                CustomAccessorData d2;
                int cnt = lst.Count;
                for (int i = 0; i < cnt; i++)
                {
                    d2 = lst[i];
                    if (d2.TargetType.IsAssignableFrom(tp))
                    {
                        try
                        {
                            data = d2;
                            return(true);
                        }
                        catch
                        {
                            Debug.LogWarning("Failed to create Custom MemberAccessor of type '" + tp.FullName + "'.");
                            break;
                        }
                    }
                }
            }

            data = default(CustomAccessorData);
            return(false);
        }
コード例 #2
0
        private static void BuildAccessorDictionary()
        {
            _targetToCustomAccessor = new ListDictionary <string, CustomAccessorData>();
            foreach (var tp in TypeUtil.GetTypesAssignableFrom(typeof(ITweenMemberAccessor)))
            {
                var attribs = tp.GetCustomAttributes(typeof(CustomTweenMemberAccessorAttribute), false).Cast <CustomTweenMemberAccessorAttribute>().ToArray();
                foreach (var attrib in attribs)
                {
                    var data = new CustomAccessorData()
                    {
                        priority     = attrib.priority,
                        TargetType   = attrib.HandledTargetType,
                        AccessorType = tp
                    };
                    _targetToCustomAccessor.Add(attrib.HandledPropName, data);
                }
            }

            foreach (var lst in _targetToCustomAccessor.Lists)
            {
                (lst as List <CustomAccessorData>).Sort((a, b) => b.priority.CompareTo(a.priority)); //sort descending
            }
        }
コード例 #3
0
        private static void BuildAccessorDictionary()
        {
            _targetToCustomAccessor = new ListDictionary<string, CustomAccessorData>();
            foreach (var tp in TypeUtil.GetTypesAssignableFrom(typeof(ITweenMemberAccessor)))
            {
                var attribs = tp.GetCustomAttributes(typeof(CustomTweenMemberAccessorAttribute), false).Cast<CustomTweenMemberAccessorAttribute>().ToArray();
                foreach (var attrib in attribs)
                {
                    var data = new CustomAccessorData()
                    {
                        priority = attrib.priority,
                        TargetType = attrib.HandledTargetType,
                        AccessorType = tp
                    };
                    _targetToCustomAccessor.Add(attrib.HandledPropName, data);
                }
            }

            foreach (var lst in _targetToCustomAccessor.Lists)
            {
                (lst as List<CustomAccessorData>).Sort((a, b) => b.priority.CompareTo(a.priority)); //sort descending
            }
        }