148 lines
3.4 KiB
C#
148 lines
3.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Core.Base
|
|
{
|
|
/// <summary>
|
|
/// 使用WWW来请求
|
|
/// </summary>
|
|
public class WWWFileRequest : IFileRequest
|
|
{
|
|
//WWW
|
|
private WWW _www = null;
|
|
//错误信息
|
|
private string _error = string.Empty;
|
|
//路径
|
|
private string _url = string.Empty;
|
|
|
|
public WWWFileRequest(string url)
|
|
{
|
|
bool inAndroidPkg = false;
|
|
RequestPathUtil.IsFileExists(url, out url,out inAndroidPkg);
|
|
_url = url;
|
|
//只有在Android,Iphone,Web下才会读取Cache.
|
|
if (Application.platform == RuntimePlatform.Android
|
|
|| Application.platform == RuntimePlatform.IPhonePlayer
|
|
|| Application.platform == RuntimePlatform.WebGLPlayer
|
|
)
|
|
{
|
|
_www = WWWFactory.GetWWWFileCache(url, inAndroidPkg);
|
|
}
|
|
else
|
|
{
|
|
_www = WWWFactory.GetWWWFile(url, inAndroidPkg);
|
|
}
|
|
if (_www == null)
|
|
{
|
|
_error = string.Format("WWWFileRequest load failed! NOT EXIST File:{0}", url);
|
|
}
|
|
}
|
|
|
|
public float Progress
|
|
{
|
|
get {
|
|
if (_www != null)
|
|
{
|
|
return _www.progress;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public bool IsDone
|
|
{
|
|
get {
|
|
if (_www != null)
|
|
{
|
|
return _www.isDone;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public string Error
|
|
{
|
|
get {
|
|
if (_www != null)
|
|
{
|
|
return _www.error;
|
|
}
|
|
else
|
|
{
|
|
return _error;
|
|
}
|
|
}
|
|
}
|
|
|
|
public AssetBundle Bundle
|
|
{
|
|
get {
|
|
if (_www != null)
|
|
{
|
|
return _www.assetBundle;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_www != null)
|
|
{
|
|
_www.Dispose();
|
|
_www = null;
|
|
}
|
|
}
|
|
|
|
public object Current
|
|
{
|
|
get {
|
|
if (_www != null)
|
|
{
|
|
return _www;
|
|
}
|
|
return _error;
|
|
}
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
if (_www != null)
|
|
{
|
|
return !_www.isDone;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
|
|
}
|
|
|
|
public IEnumerator GetEnumerator()
|
|
{
|
|
while (!IsDone)
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public IAssetRequest GetAssetRequest(string requestPath, Type assetType)
|
|
{
|
|
if (Bundle != null)
|
|
{
|
|
requestPath = RequestPathUtil.FixeRequestPath(requestPath);
|
|
var bRequest = Bundle.LoadAssetAsync(requestPath);
|
|
if (bRequest != null)
|
|
{
|
|
return new BundleAssetRequest(bRequest);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|