/// <summary> /// 异步释放资源内部实现 /// </summary> /// <returns></returns> IEnumerator InternalUnloadAsync() { if (APP_CONFIG.DEBUG) { QPrint.FrameworkWarn("Unload in ResMgr"); } AsyncOperation opt = Resources.UnloadUnusedAssets(); yield return(opt); }
/// <summary> /// 注册消息, /// 注意第一个参数,使用了C# this的扩展, /// 所以只有实现IMsgReceiver的对象才能调用此方法 /// </summary> public static void RegisterLogicMsg(this IMsgReceiver self, string msgName, VoidDelegate.WithParams callback) { // 略过 if (string.IsNullOrEmpty(msgName)) { QPrint.FrameworkWarn("RegisterMsg:" + msgName + " is Null or Empty"); return; } // 略过 if (null == callback) { QPrint.FrameworkWarn("RegisterMsg:" + msgName + " callback is Null"); return; } // 略过 if (!mMsgHandlerDict.ContainsKey(msgName)) { mMsgHandlerDict [msgName] = new List <LogicMsgHandler> (); } // 看下这里 var handlers = mMsgHandlerDict [msgName]; // 略过 // 防止重复注册 foreach (var handler in handlers) { if (handler.receiver == self && handler.callback == callback) { QPrint.FrameworkWarn("RegisterMsg:" + msgName + " ayready Register"); return; } } // 再看下这里 handlers.Add(new LogicMsgHandler(self, callback)); }
/// <summary> /// 发送消息 /// 注意第一个参数 /// </summary> public static void SendLogicMsg(this IMsgSender sender, string msgName, params object[] paramList) { // 略过,不用看 if (string.IsNullOrEmpty(msgName)) { QPrint.FrameworkError("SendMsg is Null or Empty"); return; } // 略过,不用看 if (!mMsgHandlerDict.ContainsKey(msgName)) { QPrint.FrameworkWarn("SendMsg is UnRegister"); return; } // 开始看!!!! var handlers = mMsgHandlerDict[msgName]; var handlerCount = handlers.Count; // 之所以是从后向前遍历,是因为 从前向后遍历删除后索引值会不断变化 // 参考文章,http://www.2cto.com/kf/201312/266723.html for (int index = handlerCount - 1; index >= 0; index--) { var handler = handlers[index]; if (handler.receiver != null) { QPrint.FrameworkLog("SendLogicMsg:" + msgName + " Succeed"); handler.callback(paramList); } else { handlers.Remove(handler); } } }
public GameObject LoadUIPrefabSync(string uiName) { QPrint.FrameworkWarn("Prefab/UI/" + uiName); return(Resources.Load <GameObject>("Prefab/UI/" + uiName)); }