/// <summary> /// 请求资源 /// </summary> /// <param name="caller"></param> /// <param name="resName"></param> /// <param name="callback"></param> public void GetResource(System.Object caller, string resName, ResDataLoadedHandler callback, System.Object userData = null) { string key = resName.ToLower(); ResourceDataObject resDO = null; if (!_dataDict.TryGetValue(key, out resDO)) { throw new Exception(string.Format("名为{0}的资源不存在", resName)); //return; } ResourceData data = null; if (!_resDict.TryGetValue(key, out data)) { string url = GetRootPath(resDO.Type) + resDO.Path; data = new ResourceData(caller, key, resDO.Type, url, callback, userData); _waitToLoadList.Add(data); _resDict[key] = data; } else { data.AddCounter(caller); if (data.IsReady) { if (callback != null) { callback(key, data.Url, data.Data, userData); } } else { data.AddCallback(callback, userData); } } }
void InitInternal() { ResourceDataObject resDO = null; //ui resDO = new ResourceDataObject("ui_logon", ResourceType.UI, "UILogon"); AddDataDict(resDO); resDO = new ResourceDataObject("ui_create_account", ResourceType.UI, "account/UICreateAccount"); AddDataDict(resDO); resDO = new ResourceDataObject("ui_enter_game", ResourceType.UI, "account/UIEnterGame"); AddDataDict(resDO); //ui-world resDO = new ResourceDataObject("ui_main", ResourceType.UI, "world/UIMain"); AddDataDict(resDO); //prefab resDO = new ResourceDataObject("prefab_world", ResourceType.PREFAB, "world_entry"); AddDataDict(resDO); resDO = new ResourceDataObject("prefab_avatar_player", ResourceType.PREFAB, "avatar_player"); AddDataDict(resDO); resDO = new ResourceDataObject("prefab_entity", ResourceType.PREFAB, "entity"); AddDataDict(resDO); resDO = new ResourceDataObject("prefab_terrain", ResourceType.PREFAB, "terrain"); AddDataDict(resDO); InitIconRes(); }
void AddDataDict(ResourceDataObject resDO) { string lowerName = resDO.Name.ToLower(); if (_dataDict.ContainsKey(lowerName)) { throw new Exception(string.Format("已存在名为{0}的资源", lowerName)); } _dataDict.Add(lowerName, resDO); }
void InitIconRes() { ResourceDataObject resDO = null; resDO = new ResourceDataObject("ui_icon_default", ResourceType.UI_ICON, "default"); AddDataDict(resDO); ////头像图标开始 //resDO = new ResourceDataObject("ui_icon_head_cike", ResourceType.UI_ICON, "head/cike"); //AddDataDict(resDO); ////skill图标开始 //resDO = new ResourceDataObject("ui_icon_skill_gongji", ResourceType.UI_ICON, "skill/d_gongji"); //AddDataDict(resDO); ////物品图标开始 //resDO = new ResourceDataObject("ui_icon_item_equip_weapon0", ResourceType.UI_ICON, "item/equip_weapon_0"); //AddDataDict(resDO); //resDO = new ResourceDataObject("ui_icon_item_equip_armor0", ResourceType.UI_ICON, "item/equip_armor_0"); //AddDataDict(resDO); }