Texture2D ILibaryHandle.GetTexture2d(string objName) { string _type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D]; FileStateObj stateObj = GetFileStateObj(_type, objName); if (stateObj != null) { if (stateObj.m_Asset == null) { stateObj.m_Asset = ResLibaryTool.readLocalTexture2d(stateObj.m_Path); stateObj.m_Quote = 0; } Texture2D t = (Texture2D)stateObj.m_Asset; if (t != null && stateObj.m_ExistStatus == AssetExistStatusEnum.Quote) { stateObj.m_Quote++; } if (stateObj.m_ExistStatus == AssetExistStatusEnum.Once) { stateObj.m_Asset = null; } return(t); } return(null); }
Texture2D ILibaryHandle.GetTexture2d(string objName) { string _type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D]; string streamingAssetPath = Application.streamingAssetsPath; if (resourceDict.ContainsKey(_type)) { Dictionary <string, FileStateObj> _Dict = resourceDict[_type]; FileStateObj stateObj; _Dict.TryGetValue(objName, out stateObj); if (stateObj != null) { if (stateObj.m_Asset == null) { stateObj.m_Asset = ResLibaryTool.readLocalTexture2d(Path.Combine(streamingAssetPath, stateObj.m_Path)); stateObj.m_Quote = 0; } Texture2D t = (Texture2D)stateObj.m_Asset; if (t != null && stateObj.m_ExistStatus == AssetExistStatusEnum.Quote) { stateObj.m_Quote++; } if (stateObj.m_ExistStatus == AssetExistStatusEnum.Once) { stateObj.m_Asset = null; } return(t); } } return(null); }
public void UpdateLibary(string localUrl, AssetExistStatusEnum assetStatus = AssetExistStatusEnum.Quote) { FileInfo file = new FileInfo(localUrl); if (file.Exists) { string existension = file.Extension; FileStateObj fileObj = null; if (ResLibaryConfig.ResourceTxtExts.Contains(existension)) { fileObj = new FileStateObj(); fileObj.m_Path = localUrl; fileObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_TextAsset]; if (assetStatus == AssetExistStatusEnum.Globle) { fileObj.m_Asset = ResLibaryTool.LoadFileStr(localUrl); } } else if (ResLibaryConfig.ResourceImgExts.Contains(existension)) { fileObj = new FileStateObj(); fileObj.m_Path = localUrl; fileObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D]; FileStateObj sfObj = new FileStateObj(); sfObj.m_Path = localUrl; sfObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Sprite]; if (assetStatus == AssetExistStatusEnum.Globle) { Texture2D tex2d = ResLibaryTool.readLocalTexture2d(localUrl); fileObj.m_Asset = tex2d; sfObj.m_Asset = Sprite.Create(tex2d, new Rect(0, 0, tex2d.width, tex2d.height), Vector2.zero); } string fullFileName = System.IO.Path.GetFileName(localUrl); //int position = fullFileName.LastIndexOf("."); string fileName = System.IO.Path.GetFileNameWithoutExtension(localUrl);//fullFileName.Substring(0, position - 1); sfObj.m_Name = fileName; if (!resourceDict.ContainsKey(sfObj.m_Type)) { resourceDict[sfObj.m_Type] = new Dictionary <string, FileStateObj>(); } Dictionary <string, FileStateObj> dict = resourceDict[sfObj.m_Type]; dict[sfObj.m_Name] = sfObj; LibaryStateObj libaryObj = new LibaryStateObj(); libaryObj.m_Name = sfObj.m_Name; libaryObj.m_Status = LibaryStatusEnum.DIR_FILE; libaryObj.m_Type = sfObj.m_Type; libaryObj.m_Path = localUrl; if (UpdateAssetCallback != null) { UpdateAssetCallback(libaryObj); } //ResLibaryMgr.Instance.UpdateLibary(libaryObj); } else if (ResLibaryConfig.ResourceVideoExts.Contains(existension)) { fileObj = new FileStateObj(); fileObj.m_Path = localUrl; fileObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_VideoClip]; fileObj.m_Asset = localUrl; } else if (ResLibaryConfig.ResourceAudioExts.Contains(existension)) { fileObj = new FileStateObj(); fileObj.m_Path = localUrl; fileObj.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_AudioClip]; fileObj.m_Asset = localUrl; } if (fileObj != null) { string fullFileName = System.IO.Path.GetFileName(localUrl); //int position = fullFileName.LastIndexOf("."); string fileName = System.IO.Path.GetFileNameWithoutExtension(localUrl);//fullFileName.Substring(0, position - 1); fileObj.m_Name = fileName; if (!resourceDict.ContainsKey(fileObj.m_Type)) { resourceDict[fileObj.m_Type] = new Dictionary <string, FileStateObj>(); } Dictionary <string, FileStateObj> dict = resourceDict[fileObj.m_Type]; dict[fileObj.m_Name] = fileObj; LibaryStateObj libaryObj = new LibaryStateObj(); libaryObj.m_Name = fileObj.m_Name; libaryObj.m_Status = LibaryStatusEnum.DIR_FILE; libaryObj.m_Type = fileObj.m_Type; libaryObj.m_Path = localUrl; if (UpdateAssetCallback != null) { UpdateAssetCallback(libaryObj); } //ResLibaryMgr.Instance.UpdateLibary(libaryObj); } } }