using UnityEngine;
using System;
using System.Collections;
//using System.Collections.Generic;
using XLua;
namespace LuaFramework
{
[LuaCallCSharp]
public class ResourceManager : Manager
{
public static ResourceManager _instance;
public LuaFunction onDestroy;
private WWW _www;
private LuaFunction onProgress;
void Awake()
{
_instance = this;
}
public static ResourceManager Instance
{
get
{
return _instance;
}
}
public void CreatUIObject(string UIPath, string objname, LuaFunction callBack = null)
{
#if UNITY_EDITOR
if (!AppConst.UpdateMode)
{
string path = "datingui_" + AppConst.UIVersion.ToString() + "/" + UIPath + objname;
UnityEngine.Object prefab = Resources.Load(path, typeof(GameObject));
if (prefab != null)
{
//GameObject obj = Instantiate(Resources.Load<GameObject>(path));
//if (obj != null)
//{
GameObject obj = Instantiate(prefab) as GameObject;
obj.transform.localScale = Vector3.one;
obj.transform.localPosition = Vector3.zero;
if (callBack != null)
{
callBack.Call(obj);
}
//}
}else
{
if (callBack != null)
{
callBack.Call(null);
}
}
}else
{
StartCoroutine(LoadObj(AppConst.FrameworkRoot + "/datingui_" + AppConst.UIVersion + "/" + UIPath + objname + ".u3d", objname, callBack));
}
#else
StartCoroutine(LoadObj(AppConst.FrameworkRoot + "/datingui_" + AppConst.UIVersion + "/" + UIPath + objname + ".u3d", objname, callBack));
#endif
}
public void CreatGameObject(string GameName, string path, string objname, LuaFunction callBack = null)
{
#if UNITY_EDITOR
if (!AppConst.UpdateMode)
{
//try
//{
GameObject obj = Instantiate(Resources.Load<GameObject>("gameui"+AppConst.UIVersion+"/" + GameName + "/" + path + objname));
obj.transform.localScale = Vector3.one;
obj.transform.localPosition = Vector3.zero;
if (callBack != null)
{
callBack.Call(obj);
}
//}catch (Exception ex)
//{
// Debug.LogError(ex.Message);
//}
}
else
{
string path_ = AppConst.FrameworkRoot + "/gameui" + AppConst.UIVersion + "/" + GameName + "/" + path + objname + ".u3d";
StartCoroutine(LoadObj(path_, objname, callBack));
}
#else
string path_ = AppConst.FrameworkRoot + "/gameui"+AppConst.UIVersion +"/" + GameName + "/" + path + objname + ".u3d";
StartCoroutine(LoadObj(path_, objname, callBack));
#endif
}
public void setProgressUpdate(LuaFunction callback)
{
onProgress = callback;
}
public void resetProgressUpdate()
{
onProgress = null;
_www = null;
}
float jindus = 0.0f;
void Update()
{
#if UNITY_ANDROID
if (_www != null && onProgress != null)
{
onProgress.Call(_www.progress);
//Debug.Log(www.progress);
}
#else
//if (jindutiao)
// jindutiao.value = jindus;
if (onProgress != null)
{
onProgress.Call(jindus);
//Debug.Log(www.progress);
}
#endif
}
IEnumerator LoadObj(string bundlePath, string ObjName, LuaFunction callBack = null)
{
AssetBundle built = null;
#if UNITY_ANDROID
string path_2 = "file:///" + bundlePath;
WWW www = new WWW(@path_2);
if (onProgress != null)
{
_www = www;
}
yield return www;
if (www.error == null)
{
yield return built = www.assetBundle;
}
else
{
Debug.Log("www null-------- " + path_2);
}
#else
string path_ = bundlePath;
byte[] data = null;// = OpenFile.GetFileData(path_);
if (System.IO.File.Exists(path_))
{
System.IO.FileStream file_ = new System.IO.FileStream(path_, System.IO.FileMode.Open, System.IO.FileAccess.Read);
data = new byte[file_.Length];
int redline = 0;
int allnum = 0;
while (true)
{
byte[] reddata = new byte[1024000];
redline = file_.Read(reddata, 0, (int)reddata.Length);
if (redline <= 0)
{
jindus = 1.0f;
break;
}
else
{
//Debug.LogError(redline);
System.Array.Copy(reddata, 0, data, allnum, redline);
allnum += redline;
jindus = (float)allnum / (float)data.Length;
}
yield return null;
}
file_.Close();
file_.Dispose();
}
if (data != null)
{
yield return built = AssetBundle.LoadFromMemory(data);
}
#endif
if (built != null)
{
GameObject obj = Instantiate(built.LoadAsset(ObjName)) as GameObject;
obj.transform.localScale = Vector3.one;
obj.transform.localPosition = Vector3.zero;
if (callBack != null)
{
callBack.Call(obj);
}
built.Unload(false);
}else
{
if (callBack != null)
{
callBack.Call(null);
}
}
#if UNITY_ANDROID
www.Dispose();
#endif
}
void OnDestroy()
{
if (onDestroy != null)
{
onDestroy.Call();
}
}
}
}using UnityEngine;
using System;
using System.Collections;
//using System.Collections.Generic;
using XLua;
namespace LuaFramework
{
[LuaCallCSharp]
public class ResourceManager : Manager
{
public static ResourceManager _instance;
public LuaFunction onDestroy;
private WWW _www;
private LuaFunction onProgress;
void Awake()
{
_instance = this;
}
public static ResourceManager Instance
{
get
{
return _instance;
}
}
public void CreatUIObject(string UIPath, string objname, LuaFunction callBack = null)
{
#if UNITY_EDITOR
if (!AppConst.UpdateMode)
{
string path = "datingui_" + AppConst.UIVersion.ToString() + "/" + UIPath + objname;
UnityEngine.Object prefab = Resources.Load(path, typeof(GameObject));
if (prefab != null)
{
//GameObject obj = Instantiate(Resources.Load<GameObject>(path));
//if (obj != null)
//{
GameObject obj = Instantiate(prefab) as GameObject;
obj.transform.localScale = Vector3.one;
obj.transform.localPosition = Vector3.zero;
if (callBack != null)
{
callBack.Call(obj);
}
//}
}else
{
if (callBack != null)
{
callBack.Call(null);
}
}
}else
{
StartCoroutine(LoadObj(AppConst.FrameworkRoot + "/datingui_" + AppConst.UIVersion + "/" + UIPath + objname + ".u3d", objname, callBack));
}
#else
StartCoroutine(LoadObj(AppConst.FrameworkRoot + "/datingui_" + AppConst.UIVersion + "/" + UIPath + objname + ".u3d", objname, callBack));
#endif
}
public void CreatGameObject(string GameName, string path, string objname, LuaFunction callBack = null)
{
#if UNITY_EDITOR
if (!AppConst.UpdateMode)
{
//try
//{
GameObject obj = Instantiate(Resources.Load<GameObject>("gameui"+AppConst.UIVersion+"/" + GameName + "/" + path + objname));
obj.transform.localScale = Vector3.one;
obj.transform.localPosition = Vector3.zero;
if (callBack != null)
{
callBack.Call(obj);
}
//}catch (Exception ex)
//{
// Debug.LogError(ex.Message);
//}
}
else
{
string path_ = AppConst.FrameworkRoot + "/gameui" + AppConst.UIVersion + "/" + GameName + "/" + path + objname + ".u3d";
StartCoroutine(LoadObj(path_, objname, callBack));
}
#else
string path_ = AppConst.FrameworkRoot + "/gameui"+AppConst.UIVersion +"/" + GameName + "/" + path + objname + ".u3d";
StartCoroutine(LoadObj(path_, objname, callBack));
#endif
}
public void setProgressUpdate(LuaFunction callback)
{
onProgress = callback;
}
public void resetProgressUpdate()
{
onProgress = null;
_www = null;
}
float jindus = 0.0f;
void Update()
{
#if UNITY_ANDROID
if (_www != null && onProgress != null)
{
onProgress.Call(_www.progress);
//Debug.Log(www.progress);
}
#else
//if (jindutiao)
// jindutiao.value = jindus;
if (onProgress != null)
{
onProgress.Call(jindus);
//Debug.Log(www.progress);
}
#endif
}
IEnumerator LoadObj(string bundlePath, string ObjName, LuaFunction callBack = null)
{
AssetBundle built = null;
#if UNITY_ANDROID
string path_2 = "file:///" + bundlePath;
WWW www = new WWW(@path_2);
if (onProgress != null)
{
_www = www;
}
yield return www;
if (www.error == null)
{
yield return built = www.assetBundle;
}
else
{
Debug.Log("www null-------- " + path_2);
}
#else
string path_ = bundlePath;
byte[] data = null;// = OpenFile.GetFileData(path_);
if (System.IO.File.Exists(path_))
{
System.IO.FileStream file_ = new System.IO.FileStream(path_, System.IO.FileMode.Open, System.IO.FileAccess.Read);
data = new byte[file_.Length];
int redline = 0;
int allnum = 0;
while (true)
{
byte[] reddata = new byte[1024000];
redline = file_.Read(reddata, 0, (int)reddata.Length);
if (redline <= 0)
{
jindus = 1.0f;
break;
}
else
{
//Debug.LogError(redline);
System.Array.Copy(reddata, 0, data, allnum, redline);
allnum += redline;
jindus = (float)allnum / (float)data.Length;
}
yield return null;
}
file_.Close();
file_.Dispose();
}
if (data != null)
{
yield return built = AssetBundle.LoadFromMemory(data);
}
#endif
if (built != null)
{
GameObject obj = Instantiate(built.LoadAsset(ObjName)) as GameObject;
obj.transform.localScale = Vector3.one;
obj.transform.localPosition = Vector3.zero;
if (callBack != null)
{
callBack.Call(obj);
}
built.Unload(false);
}else
{
if (callBack != null)
{
callBack.Call(null);
}
}
#if UNITY_ANDROID
www.Dispose();
#endif
}
void OnDestroy()
{
if (onDestroy != null)
{
onDestroy.Call();
}
}
}
}The referenced script on this Behaviour is missing!
UnityEngine.Resources:Load(String, Type)
LuaFramework.ResourceManager:CreatUIObject(String, String, LuaFunction) (at Assets/Scripts/Manager/ResourceManager.cs:36)
CSObjectWrap.LuaFrameworkResourceManagerWrap:CreatUIObject(IntPtr) (at Assets/XLua/Gen/LuaFrameworkResourceManagerWrap.cs:98)
XLua.LuaDLL.Lua:lua_pcall(IntPtr, Int32, Int32, Int32)
XLua.DelegateBridge:SystemVoid() (at Assets/XLua/Gen/DelegatesGensBridge.cs:32)
LuaFramework.LuaManager:Update() (at Assets/Scripts/Manager/LuaManager.cs:111)
最新发布