void OnTableThread(object state)
        {
#if UNITY_EDITOR
            RTLog.LogFormat(LogCat.Table, "Begin Thread[{0}]", mThreadState.name);
#endif
            try
            {
                while (mThreadState.isAlive)
                {
                    ITableLoader loader = null;
                    lock (mLock)
                    {
                        IsLoading = mLoaders.Count > 0;
                        if (!IsLoading)
                        {
                            //mThread = null;
                            mThreadState.isAlive = false;
                            break;
                        }
                        loader = mLoaders.Dequeue();
                        mTaskQueue.Remove(loader.Identify);
                    }
                    if (mThreadState.isAlive)
                    {
                        MainThread.RunOnMainThread(loader.StartLoad);
                    }
                    while (mThreadState.isAlive && !loader.IsReady)
                    {
#if UNITY_EDITOR
                        if (!MainThread.IsInitilized)
                        {
                            mThreadState.isAlive = false;
                        }
                        MainThread.RunOnMainThread((x) => { if (!Application.isPlaying)
                                                            {
                                                                x.isAlive = false;
                                                            }
                                                   }, mThreadState);
#endif
                        Thread.Sleep(200);
                    }
                    if (mThreadState.isAlive)
                    {
                        loader.LoadAsTable();
                    }
                }
            }
            catch (System.Exception e)
            {
                RTLog.LogError(LogCat.Table, e.ToString());
            }
            finally
            {
                Abort();
                MainThread.RunOnMainThread(NotifyComplete);
#if UNITY_EDITOR
                RTLog.LogFormat(LogCat.Table, "End Thread[{0}]", mThreadState.name);
#endif
            }
        }
Ejemplo n.º 2
0
 // notify load complete.
 public static void LoadComplete(TableSet <T> table, bool merge)
 {
     if (table != null && table.IsLoading)
     {
         table.IsLoading = false;
         MainThread.RunOnMainThread(table.FireCompleteEvent, merge);
     }
 }
Ejemplo n.º 3
0
        public static void MergeTo(TableSet <T> tables, TableSet <T> mergeTo)
        {
            if (tables == null || tables.Count == 0 || mergeTo == null)
            {
                return;
            }
            mergeTo.IsLoading = true;
            foreach (var tab in tables.mMerged)
            {
                mergeTo.mMerged.Add(tab);
            }
            List <T> list = new List <T>(mergeTo.Count + tables.Count);
            int      a    = 0;
            int      b    = 0;

            while (a < mergeTo.Count || b < tables.Count)
            {
                var ta = a < mergeTo.Count ? mergeTo.m_Datas[a] : null;
                var tb = b < tables.Count ? tables.m_Datas[b] : null;
                if (ta == null && tb == null)
                {
                    continue;
                }
                if (ta != null && tb != null)
                {
                    if (tb.Identify < ta.Identify)
                    {
                        list.Add(tb);
                        b++;
                    }
                    else if (ta.Identify < tb.Identify)
                    {
                        list.Add(ta);
                        a++;
                    }
                    else
                    {
                        list.Add(tb);
                        b++;
                        a++;
                    }
                }
                else if (ta == null)
                {
                    list.Add(tb);
                    b++;
                }
                else
                {
                    list.Add(ta);
                    a++;
                }
            }
            mergeTo.m_Datas   = list.ToArray();
            mergeTo.IsLoading = false;
            MainThread.RunOnMainThread(mergeTo.FireCompleteEvent, true);
        }
Ejemplo n.º 4
0
 public static void LoadTo(string tablename, string text, TableSet <T> tab)
 {
     if (!string.IsNullOrEmpty(text) && tab != null)
     {
         tab.IsLoading = true;
         tab.TableName = tablename;
         tab.mMerged.Clear();
         tab.mMerged.Add(HashTable(tablename));
         JsonData arr = JsonMapper.ToObject(text);
         //JArray arr = JsonConvert.DeserializeObject<JArray>(text);
         if (tab.m_Datas == null || tab.m_Datas.Length != arr.Count)
         {
             tab.m_Datas = new T[arr.Count];
         }
         for (int i = 0; i < arr.Count; i++)
         {
             T table = new T();
             table.Init(arr[i]);
             tab.m_Datas[i] = table;
         }
         tab.IsLoading = false;
         MainThread.RunOnMainThread(tab.FireCompleteEvent, false);
     }
 }