Ejemplo n.º 1
0
 public override object ToDict(Type rDictType, Type rKeyType, Type rValueType)
 {
     rDictType = ITypeRedirect.GetRedirectType(rDictType);
     if (rDictType.IsGenericType && typeof(IDictionary).IsAssignableFrom(rDictType.GetGenericTypeDefinition()))
     {
         // 特殊处理IDictionary<,>类型
         IDictionary rObject = (IDictionary)ReflectionAssist.CreateInstance(rDictType, BindingFlags.Default);
         foreach (var rItem in this.dict)
         {
             object rKey   = GetKey_ByString(rKeyType, rItem.Key);
             object rValue = rItem.Value.ToObject(rValueType);
             rObject.Add(rKey, rValue);
         }
         return(rObject);
     }
     else if (rDictType.IsGenericType && typeof(IDict).IsAssignableFrom(rDictType.GetGenericTypeDefinition()))
     {
         // 特殊处理IDict<,>的类型
         IDict rObject = (IDict)ReflectionAssist.CreateInstance(rDictType, BindingFlags.Default);
         foreach (var rItem in this.dict)
         {
             object rKey   = GetKey_ByString(rKeyType, rItem.Key);
             object rValue = rItem.Value.ToObject(rValueType);
             rObject.AddObject(rKey, rValue);
         }
         return(rObject);
     }
     return(null);
 }
Ejemplo n.º 2
0
        private void BuildSkills(int nActorSkillID)
        {
            var rSymbolObjs = GPCSkillConfig.Instance.GetActorSkill(nActorSkillID);

            this.Skills = new List <GPCSkill>();
            if (rSymbolObjs == null)
            {
                return;
            }

            for (int i = 0; i < rSymbolObjs.Count; i++)
            {
                List <GamePlayComponent> rComps = new List <GamePlayComponent>();
                for (int j = 0; j < rSymbolObjs[i].Bodies.Count; j++)
                {
                    var rCompType = MainAssemblyExpand.GetType("Game.Knight." + rSymbolObjs[i].Bodies[j].Identifer.Value);
                    var rComp     = ReflectionAssist.Construct(
                        rCompType,
                        new Type[] { typeof(ActorGamePlayManager), typeof(List <string>) },
                        this,
                        rSymbolObjs[i].Bodies[j].ToArgs()) as GamePlayComponent;
                    rComps.Add(rComp);
                }

                GPCSkill rGPCSkill = new GPCSkill(this, rSymbolObjs[i].Head.ToArgs(), rComps);
                this.Skills.Add(rGPCSkill);
            }

            for (int i = 0; i < this.Skills.Count; i++)
            {
                this.Skills[i].Initialize();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 初始化ViewController
        /// </summary>
        private async Task InitializeViewModel()
        {
            this.ViewModelContainer = this.GameObject.GetComponent <ViewModelContainer>();
            if (this.ViewModelContainer == null)
            {
                Debug.LogErrorFormat("Prefab {0} has not ViewContainer Component..", this.ViewName);
                return;
            }

            var rType = TypeResolveManager.Instance.GetType(this.ViewModelContainer.ViewModelClass);

            if (rType == null)
            {
                Debug.LogErrorFormat("Can not find ViewModel Type: {0}", rType);
                return;
            }

            // 构建ViewController
            this.ViewController      = ReflectionAssist.Construct(rType) as ViewController;
            this.ViewController.View = this;
            this.ViewController.BindingViewModels(this.ViewModelContainer);
            await this.ViewController.Initialize();

            this.ViewController.DataBindingConnect(this.ViewModelContainer);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 输入的创建
        /// </summary>
        public static T Create <T>() where T : BaseInput
        {
            Type rType  = typeof(T);
            T    rInput = ReflectionAssist.Construct(rType) as T;

            return(rInput);
        }
Ejemplo n.º 5
0
 public override object ToObject(Type rType)
 {
     rType = ITypeRedirect.GetRedirectType(rType);
     if (rType.IsGenericType && typeof(IDictionary).IsAssignableFrom(rType.GetGenericTypeDefinition()))
     {
         // 特殊处理IDictionary<,>类型
         IDictionary rObject    = (IDictionary)ReflectionAssist.CreateInstance(rType, ReflectionAssist.flags_all);
         Type[]      rArgsTypes = rType.GetGenericArguments();
         foreach (var rItem in this.dict)
         {
             object rKey   = GetKey_ByString(rArgsTypes[0], rItem.Key);
             object rValue = rItem.Value.ToObject(rArgsTypes[1]);
             rObject.Add(rKey, rValue);
         }
         return(rObject);
     }
     else if (rType.IsGenericType && typeof(IDict).IsAssignableFrom(rType.GetGenericTypeDefinition()))
     {
         // 特殊处理IDict<,>的类型
         IDict  rObject    = (IDict)ReflectionAssist.CreateInstance(rType, ReflectionAssist.flags_all);
         Type[] rArgsTypes = rType.GetGenericArguments();
         foreach (var rItem in this.dict)
         {
             object rKey   = GetKey_ByString(rArgsTypes[0], rItem.Key);
             object rValue = rItem.Value.ToObject(rArgsTypes[1]);
             rObject.AddObject(rKey, rValue);
         }
         return(rObject);
     }
     else if (rType.IsClass)
     {
         BindingFlags rBindFlags = ReflectionAssist.flags_all;
         object       rObject    = ReflectionAssist.CreateInstance(rType, rBindFlags);
         foreach (var rItem in this.dict)
         {
             Type      rMemberType = null;
             FieldInfo rFieldInfo  = rType.GetField(rItem.Key, rBindFlags);
             if (rFieldInfo != null)
             {
                 rMemberType = rFieldInfo.FieldType;
                 object rValueObj = rItem.Value.ToObject(rMemberType);
                 rFieldInfo.SetValue(rObject, rValueObj);
                 continue;
             }
             PropertyInfo rPropInfo = rType.GetProperty(rItem.Key, rBindFlags);
             if (rPropInfo != null)
             {
                 rMemberType = rPropInfo.PropertyType;
                 object rValueObj = rItem.Value.ToObject(rMemberType);
                 rPropInfo.SetValue(rObject, rValueObj, null);
                 continue;
             }
         }
         return(rObject);
     }
     return(null);
 }
Ejemplo n.º 6
0
        public override object InvokeParent(HotfixObject rHotfixObj, string rParentType, string rMethodName, params object[] rArgs)
        {
            if (mApp == null)
            {
                return(null);
            }
            Type rObjType = mApp.GetType(rParentType);

            return(ReflectionAssist.MethodMember(rHotfixObj.Object, rMethodName, ReflectionAssist.flags_method_inst, rArgs));
        }
Ejemplo n.º 7
0
        public override object Invoke(object rObj, string rTypeName, string rMethodName, params object[] rArgs)
        {
            if (mApp == null)
            {
                return(null);
            }
            Type rObjType = rObj.GetType();

            return(ReflectionAssist.MethodMember(rObj, rMethodName, ReflectionAssist.flags_method_inst, rArgs));
        }
Ejemplo n.º 8
0
        private unsafe void RegisterCLRMethodRedirection()
        {
            var rCLRBindingType = System.AppDomain.CurrentDomain.GetAssemblies()
                                  .Single(rAssembly => rAssembly.GetName().Name.Equals("Game"))?.GetTypes()
                                  .Single(rType => rType.FullName.Equals("ILRuntime.Runtime.Generated.CLRBindings"));

            if (rCLRBindingType == null)
            {
                return;
            }
            ReflectionAssist.MethodMember(rCLRBindingType, "Initialize", ReflectionAssist.flags_method_static, this.mApp);
        }
Ejemplo n.º 9
0
        public object DeserializeFrom(Type rType, byte[] rBytes)
        {
            var rObj = ReflectionAssist.Construct(rType) as SerializerBinary;

            using (var ms = new MemoryStream(rBytes))
            {
                using (var br = new BinaryReader(ms))
                {
                    rObj.Deserialize(br);
                }
            }
            return(rObj);
        }
Ejemplo n.º 10
0
        public T DeserializeFrom <T>(byte[] bytes, int index, int count) where T : SerializerBinary
        {
            var rObj = ReflectionAssist.Construct(typeof(T)) as T;

            using (var ms = new MemoryStream(bytes, index, count))
            {
                using (var br = new BinaryReader(ms))
                {
                    rObj.Deserialize(br);
                }
            }
            return(rObj as T);
        }
Ejemplo n.º 11
0
        public object DeserializeFrom(Type type, byte[] bytes, int index, int count)
        {
            var rObj = ReflectionAssist.Construct(type) as SerializerBinary;

            using (var ms = new MemoryStream(bytes, index, count))
            {
                using (var br = new BinaryReader(ms))
                {
                    rObj.Deserialize(br);
                }
            }
            return(rObj);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 把ViewModel绑定到ViewController里面
        /// </summary>
        public void BindingViewModels(ViewModelContainer rViewModelContainer)
        {
            for (int i = 0; i < rViewModelContainer.ViewModels.Count; i++)
            {
                var       rViewModelDataSource = rViewModelContainer.ViewModels[i];
                ViewModel rViewModel           = null;
                Type      rViewModelType       = TypeResolveManager.Instance.GetType(rViewModelDataSource.ViewModelPath);
                if (rViewModelType != null)
                {
                    rViewModel = ReflectionAssist.Construct(rViewModelType) as ViewModel;
                }
                if (rViewModel != null)
                {
                    this.AddViewModel(rViewModelDataSource.Key, rViewModel);
                }
                else
                {
                    Debug.LogErrorFormat("Can not find ViewModel {0}.", rViewModelDataSource.ViewModelPath);
                }
            }

            // 指定ViewModel给子类的变量 通过HotfixBinding属性标签绑定
            foreach (var rPair in this.ViewModels)
            {
                ViewModel rViewModel = rPair.Value;

                var rViewModelProp = this.GetType().GetFields(ReflectionAssist.flags_public)
                                     .Where(prop =>
                {
                    var rAttrObjs = prop.GetCustomAttributes(typeof(GameBindingAttribute), false);
                    if (rAttrObjs == null || rAttrObjs.Length == 0)
                    {
                        return(false);
                    }
                    var rBindingAttr = rAttrObjs[0] as GameBindingAttribute;

                    return(prop.FieldType.IsSubclassOf(typeof(ViewModel)) &&
                           rBindingAttr != null &&
                           rBindingAttr.Name.Equals(rPair.Key));
                }).FirstOrDefault();

                if (rViewModelProp != null)
                {
                    rViewModelProp.SetValue(this, rViewModel);
                }
                else
                {
                    Debug.LogErrorFormat("ViewModel {0} is not define in ViewController({1})", rViewModel.GetType(), this.GetType());
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 根据不同的类名构建不同的资源预处理器
        /// </summary>
        public static ABEntryProcessor Create(ABEntry rABEntry)
        {
            ABEntryProcessor rEntryProcessor = null;

            Type rType = Type.GetType(rABEntry.abClassName);

            if (rType == null)
            {
                rEntryProcessor = new ABEntryProcessor();
            }

            rEntryProcessor       = ReflectionAssist.Construct(rType) as ABEntryProcessor;
            rEntryProcessor.Entry = rABEntry;

            return(rEntryProcessor);
        }
Ejemplo n.º 14
0
        public object DeserializeFrom(Type rType, byte[] rBytes, int nIndex, int nCount)
        {
            var rObj = ReflectionAssist.Construct(rType) as SerializerBinary;

            using (MemoryStream ms = mRecyclableMSMgr.GetStream("protobuf", rBytes, nIndex, nCount))
            {
                using (var br = new BinaryReader(ms))
                {
                    rObj.Deserialize(br);
                }
            }
            ISupportInitialize iSupportInitialize = rObj as ISupportInitialize;

            if (iSupportInitialize == null)
            {
                return(rObj);
            }
            iSupportInitialize.EndInit();
            return(rObj);
        }
Ejemplo n.º 15
0
        public virtual void Initialize()
        {
            Type rType = this.GetType();

            if (rType == null)
            {
                return;
            }

            var rBindingFlags = BindingFlags.GetField | BindingFlags.SetField | BindingFlags.Public | BindingFlags.Instance;
            var rFiledInfos   = rType.GetFields(rBindingFlags);

            for (int i = 0; i < rFiledInfos.Length; i++)
            {
                var rFiledType = rFiledInfos[i].FieldType;
                var rValue     = ReflectionAssist.TypeConvert(rFiledType, mArgs[i]);
                rFiledInfos[i].SetValue(this, rValue);
            }
            this.mIsStartTriggered = false;
            this.mIsEndTriggered   = false;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 根据不同的类名构建不同的资源预处理器
        /// </summary>
        public static ABEntryProcessor Create(ABEntry rABEntry)
        {
            ABEntryProcessor rEntryProcessor = null;

            Type rType = Type.GetType(rABEntry.abClassName);

            if (rType == null)
            {
                var rAllAssembies = System.AppDomain.CurrentDomain.GetAssemblies();
                for (int i = 0; i < rAllAssembies.Length; i++)
                {
                    if (rAllAssembies[i].GetName().Name.Equals("Game.Editor"))
                    {
                        var rAllTypes = rAllAssembies[i].GetTypes();
                        for (int j = 0; j < rAllTypes.Length; j++)
                        {
                            if (rAllTypes[j].FullName.Equals(rABEntry.abClassName))
                            {
                                rType = rAllTypes[j];
                            }
                        }
                    }
                }
            }

            if (rType == null)
            {
                rEntryProcessor = new ABEntryProcessor();
            }
            else
            {
                rEntryProcessor = ReflectionAssist.Construct(rType) as ABEntryProcessor;
            }

            rEntryProcessor.Entry = rABEntry;

            return(rEntryProcessor);
        }