예제 #1
0
        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("缓存数据不匹配可能导致异常");
                    }
                }
            }
        }
예제 #2
0
 public void LoadFromCache(RegisterCachedTypes types)
 {
     try
     {
         AttributeRegister.Register(this);
         this.StartFromCache(types);
         this.End();
     }
     catch (Exception ex)
     {
         LogMgr.LogException(ex);
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
                }
            }
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
 protected virtual void StartFromCache(RegisterCachedTypes types)
 {
     InitFromCache(types);
 }