Пример #1
0
        /// <summary>
        /// 引用+1
        /// </summary>
        public bool Retain(object refer_)
        {
            if (IsDisposed(true))
            {
                return(false);
            }


            if (refer_ != null)
            {
                string referId = Refer.Format(refer_);
                if (m_refHash.Contains(referId))
                {
                    //已被它引用
                    return(false);
                }
                m_refHash.Add(referId);
                Refer.AttachDispose(referId, OnReferDispose);   //监听引用者销毁
            }

            m_ref_cnt++;
            if (m_ref_cnt == 1)
            {
            }

            return(true);
        }
Пример #2
0
        public void OnReferDispose(object refer_)
        {
#if UNITY_EDITOR
            Log.Debug("<color=magenta>检测到引用者析构: " + Refer.Format(refer_) + "</color>", this);
#endif
            Release(refer_);
        }
Пример #3
0
        /// <summary>
        /// 释放此引用者的所有引用
        /// </summary>
        /// <param name="referId_"></param>
        public void ReleaseByRefer(object refer_)
        {
            string referId = Refer.Format(refer_);

            if (referId == null)
            {
                return;
            }

            HashSet <string> hash;

            if (m_refer2urls.TryGetValue(referId, out hash))
            {
                foreach (string url in hash)
                {
                    AssetData data = m_url2data[url];
                    if (data.refHash.Remove(referId))
                    {
                        data.active_time = DateUtil.TimeFromStart;  //刷新时间
                    }
                }

                hash.Clear();
                m_hashPool.Push(hash);
                m_refer2urls.Remove(referId);
            }


            //DetachByRefer(refer_)
        }
Пример #4
0
        /// <summary>
        /// 引用-1
        /// </summary>
        public bool Release(object refer_)
        {
            if (IsDisposed(true))
            {
                return(false);
            }

            if (refer_ != null)
            {
                string referId = Refer.Format(refer_);
                if (!m_refHash.Contains(referId))
                {
                    //没被它引用
                    return(false);
                }
                m_refHash.Remove(referId);
                Refer.DetachDispose(referId, OnReferDispose);
            }

            if (m_ref_cnt > 0)
            {
                m_ref_cnt--;
                if (m_ref_cnt == 0)
                {
                    __OnRelease();
                }
            }
            else
            {
                Log.Assert("错误的引用计数", this);
            }
            return(true);
        }
Пример #5
0
        void RemoveLoadItem(LoadItem item_)
        {
            if (item_.referId != null)
            {
                Refer.DetachDeactive(item_.referId, onDeactive);
            }

            item_.Clear();

            m_itemList.Remove(item_);
            m_itemPool.Push(item_);
        }
Пример #6
0
            public void Clear()
            {
                if (refer != null)
                {
                    Refer.DetachDeactive(refer, onDeacive);
                    refer = null;
                }

                type   = null;
                func   = null;
                parent = null;
            }
Пример #7
0
        void ClearAllRefers()
        {
            m_ref_cnt = 0;

            if (m_refHash.Count > 0)
            {
                foreach (string kvp in m_refHash)
                {
                    Refer.DetachDispose(kvp, OnReferDispose);
                }
                m_refHash.Clear();
            }
        }
Пример #8
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽LoadItem∽-★-∽--------∽-★-∽------∽-★-∽--------//

        LoadItem AddLoadItem(string url_, CALLBACK_GO onComplete_, string referId_)
        {
            LoadItem item = m_itemPool.Pop();

            item.Init(url_, onComplete_, referId_);

            m_itemList.Add(item);

            if (referId_ != null)
            {
                Refer.AttachDeactive(referId_, onDeactive); //监听沉默
            }

            return(item);
        }
Пример #9
0
        public bool Release(object refer_)
        {
            string referId = Refer.Format(refer_);

            if (referId == null)
            {
                return(false);
            }

            if (refHash.Remove(referId))
            {
                m_cache.__RemoveRefer(referId, url);
                return(true);
            }
            return(false);
        }
Пример #10
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽引用相关∽-★-∽--------∽-★-∽------∽-★-∽--------//

        public bool Retain(object refer_)
        {
            string referId = Refer.Format(refer_);

            if (referId == null)
            {
                return(false);
            }

            if (refHash.Add(referId))
            {
                m_cache.__AddRefer(referId, url);
                return(true);
            }
            return(false);
        }
Пример #11
0
        public void DetachBy_Type_Refer(string type_, object refer_)
        {
            List <Observer> arr = GetObsArr(type_);

            if (arr == null)
            {
                return;
            }

            Refer.Assert(refer_);

            if (arr.Count > 0)
            {
                Observer obs;
                for (int i = arr.Count - 1; i >= 0; --i)
                {
                    obs = arr[i];
                    if (obs != null)
                    {
                        if (obs.refer == refer_)
                        {
                            obs.Clear();
                            __obsPool.Push(obs);

                            if (m_invalid > 0)
                            {
                                arr[i] = null;
                            }
                            else
                            {
                                arr.RemoveAt(i);
                            }

                            m_objNum--;
                            //break;    可能会有多个
                        }
                    }
                }
            }


            if (arr.Count == 0)
            {
                RemoveObsArr(type_);
            }
        }
Пример #12
0
            /// <param name="type_"></param>
            /// <param name="func_"></param>
            /// <param name="parent_">此obs所在的队列</param>
            /// <param name="refer_"></param>
            public void Init(string type_, CALLBACK_1 func_, List <Observer> parent_, object refer_)
            {
                type   = type_;
                func   = func_;
                parent = parent_;
                refer  = refer_;

                if (refer != null)
                {
                    //监听目标沉默
                    Refer.AttachDeactive(refer_, onDeacive);
                }
                //else
                //{
                // Refer.Assert(refer_);
                //}
            }
Пример #13
0
        /// <summary>
        /// 异步加载
        /// </summary>
        /// <param name="url_"></param>
        /// <param name="onComplete_"></param>
        /// <param name="refer_">只影响onComplete,不会用来持有资源</param>
        public void LoadAsync(string url_, CALLBACK_GO onComplete_, object refer_)
        {
            url_ = url_.ToLower();
            m_assetCache.RetainByUrl(this, url_);
            //m_assetCache.Retain(refer_, url_);    //引用者只用this

            if (m_assetCache.HasAsset(url_))
            {
                CreateGo(url_, onComplete_);
                return;
            }

            string referId = Refer.Format(refer_);

            AddLoadItem(url_, onComplete_, referId);

            m_assetCache.LoadAsync(url_, OnLoaded, this);   //已自己作为引用者,在ReleaseUnused时才有可能释放
        }
Пример #14
0
        /// <summary>
        /// 设置图片(同步加载)
        /// </summary>
        /// <param name="image_">是否需要保持引用,等go失效时设置为移除引用?</param>
        /// <param name="url_"></param>
        /// <param name="spriteName"></param>
        /// <param name="refer_"></param>
        /// <param name="nativeSize_">重置尺寸</param>
        public void SetSprite(object refer_, Image image_, string url_, string spriteName, bool nativeSize_ = false)
        {
            string real_url_ = FormatPath(url_);

            if (m_itemQueue.Count > 0 && m_image2item.ContainsKey(image_))
            {
                //image在加载队列中,从队列移除
                LoadItem item = m_image2item[image_];
                RemoveLoadItem(item);
            }

            Refer.Assert(refer_);
            string referId = Refer.Format(refer_);

            RetainImage(image_, referId);

            __SetSprite(referId, image_, real_url_, spriteName, nativeSize_);
        }
Пример #15
0
        /// <summary>
        /// 移除加载中的引用者
        /// </summary>
        /// <param name="refer_"></param>
        static public void RemoveRefer(object refer_)
        {
            if (m_reqHash.Count == 0)
            {
                //这字典大部分时间应该会空
                return;
            }

            string referId = Refer.Format(refer_);

            foreach (var req in m_reqHash)
            {
                if (req.referId == referId)
                {
                    req.on_complete = null;     //通过移除回调来实现
                }
            }
        }
Пример #16
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽引用者∽-★-∽--------∽-★-∽------∽-★-∽--------//

        public override void SetRefer(object refer_)
        {
            string id = Refer.Format(refer_);

            m_referId = id;

            if (load_reqs != null)
            {
                foreach (var v in load_reqs)
                {
                    if (v.referId == null)
                    {
                        //还没有引用者
                        v.SetRefer(id);
                    }
                }
            }
        }
Пример #17
0
        void ReleaseBy(string referId_)
        {
            if (!m_ref2imgHash.ContainsKey(referId_))
            {
                return;
            }

            HashSet <Image> imageHash = m_ref2imgHash[referId_];

            m_ref2imgHash.Remove(referId_);

            Image image;
            var   enumerator = imageHash.GetEnumerator();

            while (enumerator.MoveNext())
            {
                image        = enumerator.Current;
                image.sprite = null;

                m_image2ref.Remove(image);
            }

            if (m_itemQueue.Count > 0)
            {
                string referId = referId_ as string;
                for (int i = m_itemQueue.Count - 1; i >= 0; --i)
                {
                    if (m_itemQueue[i].referId == referId)
                    {
                        RemoveLoadItem(m_itemQueue[i]);     //移除加载项
                    }
                }
            }


            Refer.DetachDeactive(referId_, OnDeactive);
        }
Пример #18
0
        static void __Clear()
        {
            m_keyboard.Clear();

            m_subject.DetachAll();

            m_autoRelease.Excute();

            m_resMgr.Clear();
            m_soundMgr.Clear();

            //对象池清除
            m_classPools.Clear();
            m_classPools = null;

            //单例清除
            TimerMgr.inst.Clear();
            ActionMgr.inst.Clear();

            UserPrefs.Clear();
            Refer.ClearNotify();


            GameObject.Destroy(m_appBhv);
            m_appBhv = null;

            m_gRoot = null;

            m_onLateUpdate = null;
            m_onUpdate     = null;
            m_onGui        = null;

            if (m_trash)
            {
                m_trash = GameObjUtil.Delete(m_trash);
            }
        }
Пример #19
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽加载操作∽-★-∽--------∽-★-∽------∽-★-∽--------//


        /// <summary>
        /// 加载图片
        /// </summary>
        /// <param name="image_"></param>
        /// <param name="url_"></param>
        /// <param name="spriteName"></param>
        /// <param name="refer_"></param>
        /// <param name="nativeSize_">重置图片尺寸</param>
        public void LoadSprite(object refer_, Image image_, string url_, string spriteName, bool nativeSize_ = false)
        {
            string real_url_ = FormatPath(url_);

            if (m_assetCache.HasAsset(real_url_))
            {
                //资源已加载
                SetSprite(refer_, image_, url_, spriteName, nativeSize_);
                return;
            }

            Refer.Assert(refer_);
            string referId = Refer.Format(refer_);

            RetainImage(image_, referId);

            image_.sprite = null;   //设置为透明图片

            AddLoadItem(referId, image_, real_url_, spriteName, nativeSize_);

            m_assetCache.LoadAsync(real_url_, OnLoaded, refer_); //用refer_作引用者,直到它deactive才释放

            //(这里有bug, 如果先来异步再来同步,异步回来会顶掉正确的那个)
        }
Пример #20
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽引用相关∽-★-∽--------∽-★-∽------∽-★-∽--------//


        void RetainImage(Image image_, string referId_)
        {
            if (m_image2ref.ContainsKey(image_))
            {
                if (m_image2ref[image_] == referId_)    //已经是这个引用者
                {
                    return;
                }
            }

            m_image2ref[image_] = referId_;

            HashSet <Image> imageHash;

            if (!m_ref2imgHash.TryGetValue(referId_, out imageHash))
            {
                imageHash = new HashSet <Image>();
                m_ref2imgHash[referId_] = imageHash;

                Refer.AttachDeactive(referId_, OnDeactive); //监听沉默
            }

            imageHash.Add(image_);
        }
Пример #21
0
        protected override void SetupEvent()
        {
            base.SetupEvent();

            Refer.AttachDeactive(onReferDeactive); //监听所有的deactive
        }
Пример #22
0
        protected override void ClearEvent()
        {
            base.ClearEvent();

            Refer.DetachDeactive(onReferDeactive);
        }
Пример #23
0
 static void ClearEvent()
 {
     m_mainLoader.Detach(LOAD_EVT.COMPLETE, onMainLoadEvt);
     Refer.DetachDeactive(onReferDeactive);
 }
Пример #24
0
 static void SetupEvent()
 {
     m_mainLoader.Attach(LOAD_EVT.COMPLETE, onMainLoadEvt, null);
     Refer.AttachDeactive(onReferDeactive); //监听所有的deactive
 }
Пример #25
0
 public void NotifyDispose()
 {
     Refer.NotifyDispose(this);
 }
Пример #26
0
 public void NotifyDeactive()
 {
     Refer.NotifyDeactive(this);
 }
Пример #27
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽引用者∽-★-∽--------∽-★-∽------∽-★-∽--------//

        //暂时没用??
        public virtual void SetRefer(object refer_)
        {
            m_referId = Refer.Format(refer_);
        }