Ejemplo n.º 1
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽事件监听∽-★-∽--------∽-★-∽------∽-★-∽--------//


        /// <summary>
        /// 添加监听
        /// </summary>
        /// <param name="type_"></param>
        /// <param name="callback_"></param>
        /// <param name="refer_"></param>
        public void Attach(string type_, CALLBACK_1 callback_, object refer_)
        {
            if (callback_ == null)
            {
                return;
            }

            if (HasAttach(type_, callback_))
            {
                //已添加监听
                return;
            }

            List <Observer> arr = CreateObsArr(type_);

            Observer obs = __obsPool.Pop();

            obs.Init(type_, callback_, arr, refer_);

            if (arr.Count > 0 && arr[arr.Count - 1] == null)
            {
                arr[arr.Count - 1] = obs;
            }
            else
            {
                arr.Add(obs);
            }

            m_objNum++;
        }
Ejemplo n.º 2
0
        public bool HasAttach(string type_, CALLBACK_1 callback_)
        {
            List <Observer> arr = GetObsArr(type_);

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

            if (arr.Count == 0)
            {
                return(false);
            }

            Observer obs;

            for (int i = 0, len = arr.Count; i < len; ++i)
            {
                obs = arr[i];
                if (obs != null)
                {
                    if (obs.func == callback_)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
 public void Detach(string type_, CALLBACK_1 callback_)
 {
     if (m_notifier == null)
     {
         return;
     }
     m_notifier.Detach(type_, callback_);
 }
Ejemplo n.º 4
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽数据管理∽-★-∽--------∽-★-∽------∽-★-∽--------//


        //-------∽-★-∽------∽-★-∽--------∽-★-∽观察者∽-★-∽--------∽-★-∽------∽-★-∽--------//



        public void Attach(string type_, CALLBACK_1 callback_, object refer_)
        {
            if (m_notifier == null)
            {
                m_notifier = CCApp.subject;
            }
            m_notifier.Attach(type_, callback_, refer_);
        }
Ejemplo n.º 5
0
        public void CallDelayWithArg(CALLBACK_1 fun_, object arg_, float delay_ = 0, int repeat_ = 1)
        {
            RemoveCallDelay(fun_);

            int obj_id = SetTimeOutWithArg(fun_, arg_, delay_, repeat_);

            m_fun2id[fun_] = obj_id;
        }
Ejemplo n.º 6
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽Subject∽-★-∽--------∽-★-∽------∽-★-∽--------//



        public void Attach(string type_, CALLBACK_1 callback_, object target_ = null)
        {
            if (m_notifier == null)
            {
                m_notifier = new Subject();
            }
            m_notifier.Attach(type_, callback_, target_);
        }
Ejemplo n.º 7
0
        public void RemoveCallDelay(CALLBACK_1 fun_)
        {
            if (!m_fun2id.ContainsKey(fun_))
            {
                return;
            }

            int id = m_fun2id[fun_];

            ClearTimeOut(id);
        }
Ejemplo n.º 8
0
 public void ScheduleUpdateOrNot(CALLBACK_1 callback_, bool b_)
 {
     if (b_)
     {
         ScheduleUpdate(callback_);
     }
     else
     {
         UnscheduleUpdate(callback_);
     }
 }
Ejemplo n.º 9
0
            public void Clear()
            {
                if (refer != null)
                {
                    Refer.DetachDeactive(refer, onDeacive);
                    refer = null;
                }

                type   = null;
                func   = null;
                parent = null;
            }
Ejemplo n.º 10
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽事件监听∽-★-∽--------∽-★-∽------∽-★-∽--------//

        public void Attach(string type_, CALLBACK_1 callback_, object refer_ = null)
        {
            if (callback_ == null)
            {
                return;
            }

            if (!m_id2fun.ContainsKey(type_))
            {
                m_id2fun[type_] = callback_;
            }
            else
            {
                m_id2fun[type_] -= callback_;
                m_id2fun[type_] += callback_;
            }
        }
Ejemplo n.º 11
0
        public void Detach(string type_, CALLBACK_1 callback_)
        {
            if (callback_ == null)
            {
                return;
            }

            if (m_id2fun.ContainsKey(type_))
            {
                m_id2fun[type_] -= callback_;

                if (m_id2fun[type_] == null)
                {
                    m_id2fun.Remove(type_);
                }
            }
        }
Ejemplo n.º 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_);
                //}
            }
Ejemplo n.º 13
0
        /// <summary>
        /// 移除监听
        /// </summary>
        /// <param name="type_"></param>
        /// <param name="callback_"></param>
        /// <returns></returns>
        public void Detach(string type_, CALLBACK_1 callback_)
        {
            List <Observer> arr = GetObsArr(type_);

            if (arr == null)
            {
                return;
            }


            if (arr.Count > 0)
            {
                Observer obs;
                for (int i = arr.Count - 1; i >= 0; --i)
                {
                    obs = arr[i];
                    if (obs != null)
                    {
                        if (obs.func == callback_)
                        {
                            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_);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 异步加载
        /// </summary>
        /// <param name="url_"></param>
        /// <param name="isAdditive"></param>
        /// <param name="onComplete_"></param>
        /// <param name="refer_">只用于onComplete_</param>
        /// <returns></returns>
        public LevelData LoadAsync(string url_, bool isAdditive, CALLBACK_1 onComplete_, object refer_)
        {
            url_ = url_.ToLower();
            LevelData data = GetData(url_);

            if (data != null)
            {
                if (data.isLoading)
                {
                    if (onComplete_ != null)
                    {
                        Attach(url_, onComplete_, refer_);
                    }
                    return(data);
                }

                if (data.isComplete)
                {
                    if (onComplete_ != null)
                    {
                        onComplete_(data);
                    }
                    return(data);
                }
            }


            if (!isAdditive)
            {
                TransSceneBegin();   //转场
            }
            if (onComplete_ != null)
            {
                Attach(url_, onComplete_, refer_);
            }

            data            = CreateData(url_, isAdditive);
            data.isLoading  = true;
            data.isComplete = false;
            data.enumerator = __LoadAsync(data);

            CCApp.StartCoroutine(data.enumerator);

            return(m_url2data[url_]);
        }
Ejemplo n.º 15
0
        public override void StopAsync(CALLBACK_1 onComplete_)
        {
            if (m_url2req.Count == 0)
            {
                return;
            }

            AssetData data;

            foreach (var kvp in m_url2req)
            {
                data = GetData(kvp.Key);
                if (data != null)
                {
                    Detach(data.url, onComplete_);      //无差别全部detach一遍
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 延时调用(带回调参数)
        /// </summary>
        /// <param name="fun_"></param>
        /// <param name="arg_"></param>
        /// <param name="delay_"></param>
        /// <param name="repeat_"></param>
        /// <returns></returns>
        public int SetTimeOutWithArg(CALLBACK_1 fun_, object arg_, float delay_ = 0, int repeat_ = 1)
        {
            int obj_id = AllocObjId();

            if (delay_ <= 0)
            {
                delay_ = 0.001f;
            }

            TimerHandler hdl = new TimerHandler(fun_, arg_);

            hdl.delay  = delay_;
            hdl.time   = delay_;
            hdl.repeat = repeat_;

            m_id2hdl[obj_id] = hdl;
            ++m_hdlNum;

            return(obj_id);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 异步加载
        /// </summary>
        /// <param name="refer_"></param>
        /// <param name="url_"></param>
        /// <param name="onComplete_"></param>
        /// <returns></returns>
        override public AssetData LoadAsync(string url_, CALLBACK_1 onComplete_, object refer_)
        {
            url_ = url_.ToLower();

            AssetData data = CreateData(url_);   //先创建data, 用以记录生命周期等

            data.Retain(refer_);

            if (data.asset != null)
            {
                //加载完成
                if (onComplete_ != null)
                {
                    onComplete_(data);
                }
                return(data);
            }

            if (m_url2req.ContainsKey(data.url))
            {
                //加载中
                if (onComplete_ != null)
                {
                    Attach(data.url, onComplete_, refer_);
                }

                return(data);
            }

            //未启动加载, 至少保持一个引用
            data.Retain(this);

            if (onComplete_ != null)
            {
                Attach(data.url, onComplete_, refer_);
            }

            CCApp.StartCoroutine(__LoadAsync(data.url));

            return(data);
        }
Ejemplo n.º 18
0
 static public void Detach(string type_, CALLBACK_1 callback_)
 {
     m_subject.Detach(type_, callback_);
 }
Ejemplo n.º 19
0
        public void LoadAsync(string resId_, string resName_, CALLBACK_1 onComplete_, object refer)
        {
            string url = ResConfig.GetResUrl(resId_, resName_, ""); //去除后缀名

            AssetCache.me.LoadAsync(url, onComplete_, refer);
        }
Ejemplo n.º 20
0
 public TimerHandler(CALLBACK_1 func_, object arg_ = null)
 {
     func = func_;
     arg  = arg_;
 }
Ejemplo n.º 21
0
        static public void DetachDispose(object refer_, CALLBACK_1 callback_)
        {
            string referId = Format(refer_);

            __subDispose.Detach(referId, callback_);
        }
Ejemplo n.º 22
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽ScheduleUpdate∽-★-∽--------∽-★-∽------∽-★-∽--------//

        /// <summary>
        /// 定时回调
        /// </summary>
        /// <param name="callback_"></param>
        /// <param name="time_">0时:每帧触发</param>
        public void ScheduleUpdate(CALLBACK_1 callback_, float time_ = 0)
        {
            CallDelay(callback_, time_, -1);
        }
Ejemplo n.º 23
0
        static public void AttachDeactive(object refer_, CALLBACK_1 callback_)
        {
            string referId = Format(refer_);

            __subDeactive.Attach(referId, callback_, null);
        }
Ejemplo n.º 24
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽数据操作∽-★-∽--------∽-★-∽------∽-★-∽--------//


        //-------∽-★-∽------∽-★-∽--------∽-★-∽SetTimeOut∽-★-∽--------∽-★-∽------∽-★-∽--------//

        /// <summary>
        /// 延时调用
        /// </summary>
        /// <param name="fun_"></param>
        /// <param name="delay_"></param>
        /// <param name="repeat_">-1时无限循环</param>
        /// <returns>唯一序号</returns>
        public int SetTimeOut(CALLBACK_1 fun_, float delay_ = 0, int repeat_ = 1)
        {
            return(SetTimeOutWithArg(fun_, null, delay_, repeat_));
        }
Ejemplo n.º 25
0
 static public void DetachDispose(CALLBACK_1 callback_)
 {
     __subDeactive.Detach(GL_EVENT.REFER_DISPOSE, callback_);
 }
Ejemplo n.º 26
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽事件相关∽-★-∽--------∽-★-∽------∽-★-∽--------//

        static public void Attach(string type_, CALLBACK_1 callback_, object refer_)
        {
            m_subject.Attach(type_, callback_, refer_);
        }
Ejemplo n.º 27
0
 public void UnscheduleUpdate(CALLBACK_1 callback_)
 {
     RemoveCallDelay(callback_);
 }
Ejemplo n.º 28
0
 static public void DetachDeactive(CALLBACK_1 callback_)
 {
     __subDeactive.Detach(GL_EVENT.REFER_DEACTIVE, callback_);
 }
Ejemplo n.º 29
0
 public override void StopAsync(CALLBACK_1 onComplete_)
 {
 }
Ejemplo n.º 30
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽CallDelay∽-★-∽--------∽-★-∽------∽-★-∽--------//

        public void CallDelay(CALLBACK_1 fun_, float delay_ = 0, int repeat_ = 1)
        {
            CallDelayWithArg(fun_, null, delay_, repeat_);
        }