102 lines
2.6 KiB
C#
Raw Normal View History

2024-12-18 16:20:06 +08:00
using System;
using System.Xml.Linq;
using UnityEngine;
using XMLTool;
namespace QFramework
{
internal class LoadResAction : IAction
{
public System.Action OnFinished { get; set; }
private LoadResAction()
{
}
private static readonly SimpleObjectPool<LoadResAction> mPool =
new SimpleObjectPool<LoadResAction>(() => new LoadResAction(), null, 10);
string fileName;
string type;
public static LoadResAction Allocate(string fileName, string type, System.Action OnFinished = null)
{
var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false;
retNode.Reset();
retNode.fileName = fileName;
retNode.type = type;
retNode.OnFinished = OnFinished;
return retNode;
}
public ulong ActionID { get; set; }
public ActionStatus Status { get; set; }
public void OnStart()
{
ResLoader resLoader = ResLoader.Allocate();
string path = Global.xmlPath + fileName;
switch (type)
{
case "xml":
resLoader.Add2Load(path.ToLocalTextResName(), (success, res) =>
{
if (success)
{
string xmlStr = res.Asset.As<StringAsset>().text;
if (string.IsNullOrEmpty(xmlStr) == false)
{
// <20><><EFBFBD><EFBFBD>XML
XDocument doc = XDocument.Parse(xmlStr);
// <20><>ȡ<EFBFBD><C8A1>Ԫ<EFBFBD><D4AA>
XElement moduleXml = doc.Root;
XmlParser.LoadModule(moduleXml, Global.Instance.appData);
}
}
});
break;
}
resLoader.LoadAsync(() =>
{
resLoader.Recycle2Cache();
this.Finish();
});
}
public void OnExecute(float dt)
{
}
public void OnFinish()
{
}
public void Reset()
{
Status = ActionStatus.NotStart;
Paused = false;
}
public bool Paused { get; set; }
public void Deinit()
{
if (!Deinited)
{
OnFinished = null;
Deinited = true;
mPool.Recycle(this);
}
}
public bool Deinited { get; set; }
}
}