protected void LoadClipData(int type, string name, System.Action <AudioClip> completeAction) { string dataPath = "audio/"; AudioBeanDictionary dicData = new AudioBeanDictionary(); AudioClip audioClip = null; switch (type) { case 1: dicData = listMusicData; dataPath += "music"; break; case 2: dicData = listSoundData; dataPath += "sound"; break; case 3: dicData = listEnvironmentData; dataPath += "environment"; break; } if (dicData.TryGetValue(name, out audioClip)) { completeAction?.Invoke(audioClip); return; } audioClip = LoadAssetUtil.SyncLoadAsset <AudioClip>(dataPath, name); if (audioClip != null) { dicData.Add(name, audioClip); } completeAction?.Invoke(audioClip); }
protected T GetModel <T>(Dictionary <string, T> listModel, string assetBundlePath, string name, string remarkResourcesPath) where T : UnityEngine.Object { if (name == null) { return(null); } if (listModel.TryGetValue(name, out T value)) { return(value); } T model = null; #if UNITY_EDITOR //编辑器模式下直接加载资源 if (!remarkResourcesPath.IsNull()) { model = LoadAssetUtil.LoadAssetAtPathForEditor <T>(remarkResourcesPath); } else { model = LoadAssetUtil.SyncLoadAsset <T>(assetBundlePath, name); } #else model = LoadAssetUtil.SyncLoadAsset <T>(assetBundlePath, name); #endif if (model != null) { listModel.Add(name, model); } return(model); }
protected Sprite GetSpriteByName(Dictionary <string, Sprite> dicIcon, ref SpriteAtlas spriteAtlas, string atlasName, string assetBundlePath, string name) { if (name == null) { return(null); } //从字典获取sprite if (dicIcon.TryGetValue(name, out Sprite value)) { return(value); } //如果字典没有 尝试从atlas获取sprite if (spriteAtlas != null) { Sprite itemSprite = GetSpriteByName(name, spriteAtlas); if (itemSprite != null) { dicIcon.Add(name, itemSprite); } return(itemSprite); } //如果没有atlas 先加载atlas spriteAtlas = LoadAssetUtil.SyncLoadAsset <SpriteAtlas>(assetBundlePath, atlasName); //加载成功后在读取一次 if (spriteAtlas != null) { return(GetSpriteByName(dicIcon, ref spriteAtlas, atlasName, assetBundlePath, name)); } return(null); }
public static void RequestAtlas(string tag, System.Action <SpriteAtlas> callback) { SpriteAtlas sa = LoadAssetUtil.SyncLoadAsset <SpriteAtlas>(ProjectConfigInfo.ASSETBUNDLE_SPRITEATLAS, tag); if (sa != null) { callback?.Invoke(sa); } }
private GameObject CreatEffictModel(string name) { //GameObject objEffictModel = Resources.Load<GameObject>(resUrl + name); GameObject objEffictModel = LoadAssetUtil.SyncLoadAsset <GameObject>("effect/effect", name); objEffictModel.name = name; listEffect.Add(name, objEffictModel); return(objEffictModel); }
protected virtual void Awake() { GameObject objModel = LoadAssetUtil.SyncLoadAsset <GameObject>("builder/minigame", builderName); if (objModel == null) { return; } GameObject objItem = Instantiate(gameObject, objModel); DestroyImmediate(objModel, true); miniGameBuilder = objItem.GetComponent <B>(); }
/// <summary> /// 获取OBJ模型 /// </summary> /// <param name="listObjModel"></param> /// <param name="assetBundlePath"></param> /// <param name="objName"></param> /// <returns></returns> public GameObject GetGameObjectModel(Dictionary <string, GameObject> listObjModel, string assetBundlePath, string objName) { if (listObjModel.TryGetValue(objName, out GameObject valueObj)) { return(valueObj); } GameObject objModel = LoadAssetUtil.SyncLoadAsset <GameObject>(assetBundlePath, objName); if (objModel != null) { listObjModel.Add(objName, objModel); return(objModel); } return(null); }
protected Sprite GetSpriteByName(IconBeanDictionary dicIcon, ref SpriteAtlas spriteAtlas, string atlasName, string assetBundlePath, string name, string remarkResourcesPath) { if (name == null) { return(null); } //从字典获取sprite if (dicIcon.TryGetValue(name, out Sprite value)) { return(value); } //如果字典没有 尝试从atlas获取sprite if (spriteAtlas != null) { Sprite itemSprite = GetSpriteByName(name, spriteAtlas); if (itemSprite != null) { dicIcon.Add(name, itemSprite); } return(itemSprite); } #if UNITY_EDITOR //编辑器模式下直接加载资源 if (!remarkResourcesPath.IsNull()) { spriteAtlas = LoadAssetUtil.LoadAssetAtPathForEditor <SpriteAtlas>(remarkResourcesPath); } else { //如果没有atlas 先加载atlas spriteAtlas = LoadAssetUtil.SyncLoadAsset <SpriteAtlas>(assetBundlePath, atlasName); //spriteAtlas = LoadResourcesUtil.SyncLoadData<SpriteAtlas>(assetBundlePath+ atlasName); } #else //如果没有atlas 先加载atlas spriteAtlas = LoadAssetUtil.SyncLoadAsset <SpriteAtlas>(assetBundlePath, atlasName); //spriteAtlas = LoadResourcesUtil.SyncLoadData<SpriteAtlas>(assetBundlePath + atlasName); #endif //加载成功后在读取一次 if (spriteAtlas != null) { return(GetSpriteByName(dicIcon, ref spriteAtlas, atlasName, assetBundlePath, name, remarkResourcesPath)); } return(null); }
protected List <T> GetAllModel <T>(string assetBundlePath, string remarkResourcesPath) where T : UnityEngine.Object { List <T> models = null; #if UNITY_EDITOR //编辑器模式下直接加载资源 if (!remarkResourcesPath.IsNull()) { models = LoadAssetUtil.LoadAllAssetAtPathForEditor <T>(remarkResourcesPath); } else { models = LoadAssetUtil.SyncLoadAllAsset <T>(assetBundlePath); } #else models = LoadAssetUtil.SyncLoadAllAsset <T>(assetBundlePath); #endif return(models); }
protected T GetModel <T>(Dictionary <string, T> listModel, string assetBundlePath, string name) where T : Object { if (name == null) { return(null); } if (listModel.TryGetValue(name, out T value)) { return(value); } T anim = LoadAssetUtil.SyncLoadAsset <T>(assetBundlePath, name); if (anim != null) { listModel.Add(name, anim); } return(anim); }
/// <summary> /// 创建UI /// </summary> /// <typeparam name="T"></typeparam> /// <param name="uiName"></param> /// <returns></returns> protected T CreateUI <T>(string uiName) where T : BaseUIComponent { GameObject uiModel = LoadAssetUtil.SyncLoadAsset <GameObject>("ui/ui", uiName); //BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData<BaseUIComponent>("UI/"+ uiName); if (uiModel) { GameObject objUIComponent = Instantiate(gameObject, uiModel.gameObject); objUIComponent.SetActive(false); objUIComponent.name = objUIComponent.name.Replace("(Clone)", ""); T uiComponent = objUIComponent.GetComponent <T>(); uiList.Add(uiComponent); return(uiComponent); } else { LogUtil.LogError("没有找到指定UI:" + "ui/ui " + uiName); return(null); } }
/// <summary> /// 通过UI的名字开启UI /// </summary> /// <param name="uiName"></param> public T OpenUIByName <T>(string uiName) where T : BaseUIComponent { BaseUIComponent uiComponent = null; if (CheckUtil.StringIsNull(uiName)) { return(uiComponent as T); } bool hasData = false; for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI.name.Contains(uiName)) { uiComponent = itemUI; itemUI.OpenUI(); hasData = true; } } if (!hasData) { GameObject uiModel = LoadAssetUtil.SyncLoadAsset <GameObject>("ui/ui", uiName); //BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData<BaseUIComponent>("UI/"+ uiName); if (uiModel) { GameObject objUIComponent = Instantiate(gameObject, uiModel.gameObject); uiComponent = objUIComponent.GetComponent <BaseUIComponent>(); uiComponent.OpenUI(); uiList.Add(uiComponent); } else { LogUtil.LogError("没有找到指定UI:" + "ui/ui " + uiName); } } return(uiComponent as T); }
protected T GetModel <T>(string assetBundlePath, string name, string remarkResourcesPath) where T : UnityEngine.Object { if (name == null) { return(null); } T model = null; #if UNITY_EDITOR //编辑器模式下直接加载资源 if (!remarkResourcesPath.IsNull()) { model = LoadAssetUtil.LoadAssetAtPathForEditor <T>(remarkResourcesPath); } else { model = LoadAssetUtil.SyncLoadAsset <T>(assetBundlePath, name); } #else model = LoadAssetUtil.SyncLoadAsset <T>(assetBundlePath, name); #endif return(model); }
/// <summary> /// 加载资源 /// </summary> /// <param name="buildType"></param> /// <param name="resName"></param> public void LoadBuildBaseRes(BuildTypeEnum buildType, string resName) { if (dicBuildBaseForBuilding.ContainsKey(resName)) { return; } string path = "build/"; switch (buildType) { case BuildTypeEnum.Building: path += "building/"; break; } GameObject obj = LoadAssetUtil.SyncLoadAsset <GameObject>(path + resName, resName); BuildBaseManager buildBaseManager = obj.GetComponent <BuildBaseManager>(); buildBaseManager.InitData(); if (buildBaseManager) { dicBuildBaseForBuilding.Add(resName, buildBaseManager); } }
public void Awake() { objNpcModel = LoadAssetUtil.SyncLoadAsset <GameObject>("character/character", "CharacterForStory"); storyInfoController = new StoryInfoController(this, this); storyInfoController.GetAllStoryInfo(null); }