//-------∽-★-∽------∽-★-∽--------∽-★-∽事件监听∽-★-∽--------∽-★-∽------∽-★-∽--------// /// <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++; }
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); }
public void Detach(string type_, CALLBACK_1 callback_) { if (m_notifier == null) { return; } m_notifier.Detach(type_, callback_); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽数据管理∽-★-∽--------∽-★-∽------∽-★-∽--------// //-------∽-★-∽------∽-★-∽--------∽-★-∽观察者∽-★-∽--------∽-★-∽------∽-★-∽--------// public void Attach(string type_, CALLBACK_1 callback_, object refer_) { if (m_notifier == null) { m_notifier = CCApp.subject; } m_notifier.Attach(type_, callback_, refer_); }
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; }
//-------∽-★-∽------∽-★-∽--------∽-★-∽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_); }
public void RemoveCallDelay(CALLBACK_1 fun_) { if (!m_fun2id.ContainsKey(fun_)) { return; } int id = m_fun2id[fun_]; ClearTimeOut(id); }
public void ScheduleUpdateOrNot(CALLBACK_1 callback_, bool b_) { if (b_) { ScheduleUpdate(callback_); } else { UnscheduleUpdate(callback_); } }
public void Clear() { if (refer != null) { Refer.DetachDeactive(refer, onDeacive); refer = null; } type = null; func = null; parent = null; }
//-------∽-★-∽------∽-★-∽--------∽-★-∽事件监听∽-★-∽--------∽-★-∽------∽-★-∽--------// 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_; } }
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_); } } }
/// <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_); //} }
/// <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_); } }
/// <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_]); }
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一遍 } } }
/// <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); }
/// <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); }
static public void Detach(string type_, CALLBACK_1 callback_) { m_subject.Detach(type_, callback_); }
public void LoadAsync(string resId_, string resName_, CALLBACK_1 onComplete_, object refer) { string url = ResConfig.GetResUrl(resId_, resName_, ""); //去除后缀名 AssetCache.me.LoadAsync(url, onComplete_, refer); }
public TimerHandler(CALLBACK_1 func_, object arg_ = null) { func = func_; arg = arg_; }
static public void DetachDispose(object refer_, CALLBACK_1 callback_) { string referId = Format(refer_); __subDispose.Detach(referId, callback_); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽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); }
static public void AttachDeactive(object refer_, CALLBACK_1 callback_) { string referId = Format(refer_); __subDeactive.Attach(referId, callback_, null); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽数据操作∽-★-∽--------∽-★-∽------∽-★-∽--------// //-------∽-★-∽------∽-★-∽--------∽-★-∽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_)); }
static public void DetachDispose(CALLBACK_1 callback_) { __subDeactive.Detach(GL_EVENT.REFER_DISPOSE, callback_); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽事件相关∽-★-∽--------∽-★-∽------∽-★-∽--------// static public void Attach(string type_, CALLBACK_1 callback_, object refer_) { m_subject.Attach(type_, callback_, refer_); }
public void UnscheduleUpdate(CALLBACK_1 callback_) { RemoveCallDelay(callback_); }
static public void DetachDeactive(CALLBACK_1 callback_) { __subDeactive.Detach(GL_EVENT.REFER_DEACTIVE, callback_); }
public override void StopAsync(CALLBACK_1 onComplete_) { }
//-------∽-★-∽------∽-★-∽--------∽-★-∽CallDelay∽-★-∽--------∽-★-∽------∽-★-∽--------// public void CallDelay(CALLBACK_1 fun_, float delay_ = 0, int repeat_ = 1) { CallDelayWithArg(fun_, null, delay_, repeat_); }