コード例 #1
0
        public static IMemberAccessor GetAccessor(MemberInfo memberInfo, bool useBasicMemberAccessor)
        {
            if (memberInfo == null)
            {
                throw new System.ArgumentNullException("memberInfo");
            }

            if (_pool != null && _pool.ContainsKey(memberInfo))
            {
                return(_pool[memberInfo]);
            }

            if (_pool == null)
            {
                _pool = new Dictionary <MemberInfo, IMemberAccessor>(new MemberInfoEqualityComparer());
            }

            IMemberAccessor result;

            if (typeof(UnityEngine.Transform).IsAssignableFrom(memberInfo.DeclaringType))
            {
                result = FastTransformMemberAccessor.Create(memberInfo, useBasicMemberAccessor);
            }
            else if (useBasicMemberAccessor)
            {
                if (memberInfo is PropertyInfo || memberInfo is FieldInfo)
                {
                    result = new BasicMemberAccessor(memberInfo);
                }
                else
                {
                    throw new System.ArgumentException("MemberInfo must be either a PropertyInfo or a FieldInfo.");
                }
            }
            else
            {
                if (memberInfo is PropertyInfo)
                {
                    result = new PropertyAccessor(memberInfo as PropertyInfo);
                }
                else if (memberInfo is FieldInfo)
                {
                    result = new FieldAccessor(memberInfo as FieldInfo);
                }
                else
                {
                    throw new System.ArgumentException("MemberInfo must be either a PropertyInfo or a FieldInfo.");
                }
            }

            _pool.Add(memberInfo, result);
            return(result);
        }
コード例 #2
0
        public static FastTransformMemberAccessor Create(MemberInfo info, bool useBasicMemberAccessor = false)
        {
            if(info == null) throw new System.ArgumentNullException("info");
            if(info.MemberType != MemberTypes.Property && info.MemberType != MemberTypes.Field) throw new System.ArgumentException("MemberInfo must be of type FieldInfo or PropertyInfo", "info");

            FastTransformMemberAccessor obj = null;
            switch(info.Name)
            {
                case "position" :
                    obj = new FastTransformMemberAccessor();
                    obj._setter = obj.SetPosition;
                    obj._getter = obj.GetPosition;
                    break;
                case "localPosition":
                    obj = new FastTransformMemberAccessor();
                    obj._setter = obj.SetLocalPosition;
                    obj._getter = obj.GetLocalPosition;
                    break;
                case "localScale":
                    obj = new FastTransformMemberAccessor();
                    obj._setter = obj.SetLocalScale;
                    obj._getter = obj.GetLocalScale;
                    break;
                case "eulerAngles":
                    obj = new FastTransformMemberAccessor();
                    obj._setter = obj.SetEulerAngles;
                    obj._getter = obj.GetEulerAngles;
                    break;
                case "localEulerAngles":
                    obj = new FastTransformMemberAccessor();
                    obj._setter = obj.SetLocalEulerAngles;
                    obj._getter = obj.GetLocalEulerAngles;
                    break;
                case "rotation":
                    obj = new FastTransformMemberAccessor();
                    obj._setter = obj.SetRotation;
                    obj._getter = obj.GetRotation;
                    break;
                case "localRotation":
                    obj = new FastTransformMemberAccessor();
                    obj._setter = obj.SetLocalRotation;
                    obj._getter = obj.GetLocalRotation;
                    break;
                default:
                    obj = new FastTransformMemberAccessor();
                    if (useBasicMemberAccessor)
                    {
                        obj._alternate = new BasicMemberAccessor(info);
                    }
                    else
                    {
                        if (info.MemberType == MemberTypes.Field)
                            obj._alternate = new FieldAccessor(info as FieldInfo);
                        else
                            obj._alternate = new PropertyAccessor(info as PropertyInfo);
                    }
                    break;
            }

            return obj;
        }
コード例 #3
0
        public static FastTransformMemberAccessor Create(MemberInfo info, bool useBasicMemberAccessor = false)
        {
            if (info == null)
            {
                throw new System.ArgumentNullException("info");
            }
            if (info.MemberType != MemberTypes.Property && info.MemberType != MemberTypes.Field)
            {
                throw new System.ArgumentException("MemberInfo must be of type FieldInfo or PropertyInfo", "info");
            }

            FastTransformMemberAccessor obj = null;

            switch (info.Name)
            {
            case "position":
                obj         = new FastTransformMemberAccessor();
                obj._setter = obj.SetPosition;
                obj._getter = obj.GetPosition;
                break;

            case "localPosition":
                obj         = new FastTransformMemberAccessor();
                obj._setter = obj.SetLocalPosition;
                obj._getter = obj.GetLocalPosition;
                break;

            case "localScale":
                obj         = new FastTransformMemberAccessor();
                obj._setter = obj.SetLocalScale;
                obj._getter = obj.GetLocalScale;
                break;

            case "eulerAngles":
                obj         = new FastTransformMemberAccessor();
                obj._setter = obj.SetEulerAngles;
                obj._getter = obj.GetEulerAngles;
                break;

            case "localEulerAngles":
                obj         = new FastTransformMemberAccessor();
                obj._setter = obj.SetLocalEulerAngles;
                obj._getter = obj.GetLocalEulerAngles;
                break;

            case "rotation":
                obj         = new FastTransformMemberAccessor();
                obj._setter = obj.SetRotation;
                obj._getter = obj.GetRotation;
                break;

            case "localRotation":
                obj         = new FastTransformMemberAccessor();
                obj._setter = obj.SetLocalRotation;
                obj._getter = obj.GetLocalRotation;
                break;

            default:
                obj = new FastTransformMemberAccessor();
                if (useBasicMemberAccessor)
                {
                    obj._alternate = new BasicMemberAccessor(info);
                }
                else
                {
                    if (info.MemberType == MemberTypes.Field)
                    {
                        obj._alternate = new FieldAccessor(info as FieldInfo);
                    }
                    else
                    {
                        obj._alternate = new PropertyAccessor(info as PropertyInfo);
                    }
                }
                break;
            }

            return(obj);
        }