コード例 #1
0
        public void Publish(string ev_name, string group, params object[] parameters)
        {
            try
            {
                if (RunInLogicThread)
                {
                    LogSystem.Debug("Publish {0} {1}", ev_name, group);
                }
                else
                {
                    LogicSystem.LogFromLogic("Publish {0} {1}", ev_name, group);
                }

                Delegate d;
                string   key = group + '#' + ev_name;
                if (subscribers_.TryGetValue(key, out d))
                {
                    if (null == d)
                    {
                        if (RunInLogicThread)
                        {
                            LogSystem.Error("Publish {0} {1}, Subscriber is null, Remove it", ev_name, group);
                        }
                        else
                        {
                            LogicSystem.LogErrorFromLogic("Publish {0} {1}, Subscriber is null, Remove it", ev_name, group);
                        }
                        subscribers_.Remove(key);
                    }
                    else
                    {
                        d.DynamicInvoke(parameters);
                    }
                }
            }
            catch (Exception ex)
            {
                if (RunInLogicThread)
                {
                    LogSystem.Error("PublishSubscribe.Publish({0},{1}) exception:{2}\n{3}", ev_name, group, ex.Message, ex.StackTrace);
                }
                else
                {
                    LogicSystem.LogErrorFromLogic("PublishSubscribe.Publish({0},{1}) exception:{2}\n{3}", ev_name, group, ex.Message, ex.StackTrace);
                }
            }
        }
コード例 #2
0
        internal void CleanupResourcePool()
        {
            for (LinkedListNode <UsedResourceInfo> node = m_UsedResources.FirstValue; null != node;)
            {
                UsedResourceInfo resInfo = node.Value;
                if (!m_PreloadResources.Contains(resInfo.m_ResId))
                {
                    node = node.Next;
                    RemoveFromUsedResources(resInfo.m_ObjId);
                    resInfo.Recycle();
                }
                else
                {
                    node = node.Next;
                }
            }

            foreach (KeyValuePair <int, Queue <Object> > pair in m_UnusedResources)
            {
                int key = pair.Key;
                if (m_PreloadResources.Contains(key))
                {
                    continue;
                }
                Queue <Object> queue = pair.Value;
                queue.Clear();
            }

            foreach (KeyValuePair <string, Object> pair in m_LoadedPrefabs)
            {
                string key = pair.Key;
                Object obj = pair.Value;
                if (null != obj)
                {
                    try
                    {
                        int instId = obj.GetInstanceID();
                        if (!m_PreloadResources.Contains(instId))
                        {
                            m_WaitDeleteLoadedPrefabEntrys.Add(key);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        m_WaitDeleteLoadedPrefabEntrys.Add(key);
                        LogicSystem.LogErrorFromLogic("Exception:{0} stack:{1}", ex.Message, ex.StackTrace);
                    }
                }
                else
                {
                    m_WaitDeleteLoadedPrefabEntrys.Add(key);
                }
            }
            for (int i = 0; i < m_WaitDeleteLoadedPrefabEntrys.Count; i++)
            {
                m_LoadedPrefabs.Remove(m_WaitDeleteLoadedPrefabEntrys[i]);
            }

            /*
             * foreach (string key in m_WaitDeleteLoadedPrefabEntrys) {
             * m_LoadedPrefabs.Remove(key);
             * }*/
            m_WaitDeleteLoadedPrefabEntrys.Clear();

            Resources.UnloadUnusedAssets();
        }