102 lines
2.6 KiB
C#
102 lines
2.6 KiB
C#
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.As<LocalTextRes>().text;
|
|
if (string.IsNullOrEmpty(xmlStr) == false)
|
|
{
|
|
// ¼ÓÔØXML
|
|
XDocument doc = XDocument.Parse(xmlStr);
|
|
// »ñÈ¡¸ùÔªËØ
|
|
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; }
|
|
}
|
|
|
|
|
|
} |