private void InitFromCache(RegisterCachedTypes cachedTypes) { int i = (int)RegisterType.None; int end = (int)RegisterType.END; for (; i < end; ++i) { CachedListStringWrapper tuples = cachedTypes.getTypes(i); if (tuples != null) { if (this._attributeHandlers.ContainsKey(i)) { var list = this._attributeHandlers[i]; for (int j = 0; j < list.Count; ++j) { KeyValuePair <Type, GameAttriHandler> typedata = list[j]; for (int m = 0; m < tuples.TypeList.Count; m++) { if (tuples.TypeList[m].attributename.Equals(typedata.Key.FullName)) { cachedTypes.Analyze(this, i, tuples.TypeList[m], typedata.Key, typedata.Value); } } } } else { LogMgr.LogError("缓存数据不匹配可能导致异常"); } } } }
public void LoadFromCache(RegisterCachedTypes types) { try { AttributeRegister.Register(this); this.StartFromCache(types); this.End(); } catch (Exception ex) { LogMgr.LogException(ex); } }
private void InitFromCache(string path) { string[] sparray = path.Split('.'); if (sparray.Length == 1) { path += ".asset"; } RegisterCachedTypes cachedTypes = Resources.Load <RegisterCachedTypes>(sparray[0]); if (cachedTypes == null) { throw new Exception("Missing Cache : " + path); } InitFromCache(cachedTypes); }
private RegisterCachedTypes InitAttributesToCache(Type passtp, string path) { string[] sparray = path.Split('.'); if (sparray.Length == 1) { path += ".asset"; } RegisterCachedTypes cachedTypes = ScriptableObject.CreateInstance <RegisterCachedTypes>(); Assembly asm = passtp.Assembly; Type[] types = asm.GetTypes(); SortTypes(types); int i = (int)RegisterType.None; int end = (int)RegisterType.END; for (; i < end; ++i) { RegisterType registerTp = (RegisterType)i; if (this._attributeHandlers.ContainsKey(i)) { var list = this._attributeHandlers[i]; for (int j = 0; j < list.Count; ++j) { for (int m = 0; m < types.Length; ++m) { ReadType(cachedTypes, types[m], list[j], registerTp); } } } } AssetDatabase.CreateAsset(cachedTypes, "Assets/Resources/" + path); AssetDatabase.Refresh(); return(cachedTypes); }
private void ReadType(RegisterCachedTypes cachedTypes, Type tp, KeyValuePair <Type, GameAttriHandler> tupledata, RegisterType registerTp) { if (registerTp == RegisterType.ClassAttr) { object[] att = tp.GetCustomAttributes(tupledata.Key, false); if (att != null && att.Length == 1) { cachedTypes.LoadTypes(registerTp, tp, tupledata.Key); } } else if (registerTp == RegisterType.MethodAtt || registerTp == RegisterType.Register) { MethodInfo[] methods = tp.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); List <MethodInfo> methodList = new List <MethodInfo>(); for (int j = 0; j < methods.Length; ++j) { object[] att = methods[j].GetCustomAttributes(tupledata.Key, false); if (att != null && att.Length > 0 && methods[j].IsStatic) { methodList.Add(methods[j]); if (registerTp == RegisterType.Register) { methods[j].Invoke(null, new object[] { this }); } } else if (att != null && att.Length > 0 && !methods[j].IsStatic) { LogMgr.LogError("虽然注册了,但是不是静态函数 =>" + methods[j].Name); } } if (methodList.Count > 0) { cachedTypes.LoadTypes(registerTp, tp, tupledata.Key, methodList); } } }
void Awake() { #if !UNITY_EDITOR OpenABMode = true; #endif LogMgr.OpenLog = this.AwakeLogMode; GameObject fkObject = GameObject.Find("KFrameWork"); if (fkObject == null) { this.gameObject.name = "KFrameWork"; } if (Application.isPlaying) { DontDestroyOnLoad(gameObject); } _mIns = this; initwatch = new Stopwatch(); initwatch.Start(); FrameWorkConfig.LoadConfig(this); if (AsyncInit) { cached = Resources.Load <RegisterCachedTypes>(MainLoopAsset); thread = new Thread(AsyncWork); thread.Start(); //ThreadPool.QueueUserWorkItem(AsyncWork); } else { _Init(); CheckEvents(); } }
protected virtual void StartFromCache(RegisterCachedTypes types) { InitFromCache(types); }