xml配置从ab系统中移除

This commit is contained in:
shenjianxing 2024-12-16 13:25:22 +08:00
parent a58c8fb921
commit 69b9c1cc10
6 changed files with 318 additions and 6 deletions

View File

@ -73,7 +73,8 @@ namespace QFramework
AssetBundleSceneResCreator,
new NetImageResCreator(),
new LocalImageResCreator(),
new LocalAudioResCreator()
new LocalAudioResCreator(),
new LocalTextResCreator()
};
}
@ -114,4 +115,16 @@ namespace QFramework
return LocalAudioRes.Allocate(resSearchKeys.AssetName);
}
}
public class LocalTextResCreator : IResCreator
{
public bool Match(ResSearchKeys resSearchKeys)
{
return resSearchKeys.AssetName.StartsWith("localtext:");
}
public IRes Create(ResSearchKeys resSearchKeys)
{
return LocalTextRes.Allocate(resSearchKeys.AssetName);
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6012cdb558a59ef4db3dd78e36951e0f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,278 @@
using UnityEngine;
namespace QFramework
{
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public static class LocalTextResUtil
{
public static string ToLocalTextResName(this string selfFilePath)
{
return string.Format("localtext:{0}", selfFilePath);
}
}
/// <summary>
/// 本地通用文件加载
/// </summary>
public class LocalTextRes : Res
{
private string mFullPath;
private string mHashCode;
private object mRawAsset;
UnityWebRequest request;
public static LocalTextRes Allocate(string name)
{
var res = SafeObjectPool<LocalTextRes>.Instance.Allocate();
if (res != null)
{
res.AssetName = name;
res.SetUrl(name.Substring(10));
}
return res;
}
public void SetDownloadProgress(int totalSize, int download)
{
}
public string LocalResPath
{
get { return string.Format("{0}{1}", AssetBundlePathHelper.PersistentDataPath4Photo, mHashCode); }
}
public virtual object RawAsset
{
get { return mRawAsset; }
}
public bool NeedDownload
{
get { return RefCount > 0; }
}
public string Url
{
get { return mFullPath; }
}
public int FileSize
{
get { return 1; }
}
public void SetUrl(string url)
{
if (string.IsNullOrEmpty(url))
{
return;
}
mFullPath = url;
mHashCode = string.Format("Photo_{0}", mFullPath.GetHashCode());
}
public override bool UnloadImage(bool flag)
{
return false;
}
public override bool LoadSync()
{
return false;
}
public override void LoadAsync()
{
if (!CheckLoadAble())
{
return;
}
if (string.IsNullOrEmpty(mAssetName))
{
return;
}
DoLoadWork();
}
private void DoLoadWork()
{
State = ResState.Loading;
OnDownLoadResult(true);
//检测本地文件是否存在
/*
if (!File.Exists(LocalResPath))
{
ResDownloader.S.AddDownloadTask(this);
}
else
{
OnDownLoadResult(true);
}
*/
}
protected override void OnReleaseRes()
{
if (mAsset != null)
{
GameObject.Destroy(mAsset);
mAsset = null;
}
mRawAsset = null;
}
public override void Recycle2Cache()
{
SafeObjectPool<LocalTextRes>.Instance.Recycle(this);
}
public override void OnRecycled()
{
}
public void DeleteOldResFile()
{
//throw new NotImplementedException();
}
public void OnDownLoadResult(bool result)
{
if (!result)
{
OnResLoadFaild();
return;
}
if (RefCount <= 0)
{
State = ResState.Waiting;
return;
}
ResMgr.Instance.PushIEnumeratorTask(this);
}
public override IEnumerator DoLoadAsync(System.Action finishCallback)
{
using (UnityWebRequest request = UnityWebRequest.Get(mFullPath))
{
request.downloadHandler = new DownloadHandlerBuffer();
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
Debug.LogError(string.Format("Res:{0}, WWW Errors:{1}", mFullPath, request.error));
OnResLoadFaild();
finishCallback();
yield break;
}
else
{
// Convert the downloaded data to an AudioClip
mAsset = new StringAsset(request.downloadHandler.text);
}
if (RefCount <= 0)
{
OnResLoadFaild();
finishCallback();
yield break;
}
}
State = ResState.Ready;
finishCallback();
}
protected override float CalculateProgress()
{
if (request == null)
{
return 0;
}
return request.downloadProgress;
}
/*
public IEnumerator StartIEnumeratorTask2(Action finishCallback)
{
if (refCount <= 0)
{
OnResLoadFaild();
finishCallback();
yield break;
}
WWW www = new WWW("file://" + LocalResPath);
yield return www;
if (www.error != null)
{
Log.E("WWW Error:" + www.error);
OnResLoadFaild();
finishCallback();
yield break;
}
if (!www.isDone)
{
Log.E("NetImageRes WWW Not Done! Url:" + m_Url);
OnResLoadFaild();
finishCallback();
www.Dispose();
www = null;
yield break;
}
if (refCount <= 0)
{
OnResLoadFaild();
finishCallback();
www.Dispose();
www = null;
yield break;
}
TimeDebugger dt = new TimeDebugger("Tex");
dt.Begin("LoadingTask");
Texture2D tex = www.texture;
tex.Compress(true);
dt.End();
dt.Dump(-1);
m_Asset = tex;
www.Dispose();
www = null;
resState = eResState.kReady;
finishCallback();
}
*/
}
}
public class StringAsset : ScriptableObject
{
public string text;
public StringAsset(string text)
{
this.text = text;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 999be03da3ba22844a61e7af236752c1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,9 +12,10 @@ public class Global : Singleton<Global>
public XMLTool.AppData appData;
public Module curModule;
public static string deviceIconsPath = Application.dataPath + "/../" + "Data/DeviceIcons/";
public static string audioPath = Application.dataPath + "/../" + "Data/Audio/";
public static string dataPath = Application.dataPath + "/../Data";
public static string deviceIconsPath = dataPath + "/DeviceIcons/";
public static string audioPath = dataPath + "/Audio/";
public static string appXmlPath = dataPath + "/App.xml";
public enum AppType
{
UnKnow = 1 << 0,

View File

@ -18,11 +18,12 @@ public class Launch : MonoBehaviour
IEnumerator StartApp()
{
yield return ResKit.InitAsync();
loader.Add2Load<TextAsset>(App_xml.APP, (success, res) =>
loader.Add2Load(Global.appXmlPath.ToLocalTextResName(), (success, res) =>
{
if (success)
{
Global.Instance.appData = XmlParser.ParseXml(res.Asset.As<TextAsset>().text);
Global.Instance.appData = XmlParser.ParseXml(res.Asset.As<StringAsset>().text);
}
});