public static void Refresh() { for (int i = 0; i < loadedlist.Count; i++) { ResourceInfoEx info = loadedlist[i]; if (info.length > 0) { if (abm.abhs.ContainsKey(info.bundlename)) { AssetBundleEx ab = abm.abhs[info.bundlename]; if (ab.afs.ContainsKey(info.assetfilename)) { AssetFileEx af = ab.afs[info.assetfilename]; Stream fs = af.stream; fs.Position = info.offset; byte[] data = new byte[info.length]; int ret = fs.Read(data, (int)0, (int)info.length); if (ret == info.length) { UpdateByType(info, data); } } } } } }
private static void LoadResourceInfoFromAssetFile(AssetBundleEx ab, AssetFileEx af, string classname) { List <ObjectData> odlist = af.extractlist[classname]; Dictionary <string, ResourceInfoEx> resourcetableoftype = resourcetable[classname]; foreach (ObjectData od in odlist) { ResourceInfoEx currentinfo = new ResourceInfoEx(); currentinfo.bundlename = ab.name; currentinfo.assetfilename = af.sourceFile; currentinfo.objectname = od.objectname; currentinfo.classname = od.classname; currentinfo.typename = od.typename; currentinfo.propertyfield = od.propertyfield; currentinfo.path = od.path; object data = od.data; if (data is StreamBlock) { StreamBlock sdi = (StreamBlock)od.data; if (sdi != null) { currentinfo.offset = sdi.offset; currentinfo.length = sdi.length; } } if (currentinfo.objectname == null || currentinfo.objectname == "") { continue; } //if (currentinfo.path == null || currentinfo.path == "") //{ // continue; //} if (resourcetableoftype.ContainsKey(currentinfo.objectname)) { ResourceInfoEx otherinfo = resourcetableoftype[od.objectname]; //Logger.Log("current=" + currentinfo.objectname + "<" + currentinfo.typename + ">,other=" + otherinfo.objectname + "<" + otherinfo.typename + ">"); } else { resourcetableoftype.Add(currentinfo.objectname, currentinfo); } } }
public static void LoadAsyn(string relpath, Type t, ResourceAsynHandlerEx handler) { if (relpath == null || relpath.Length <= 0) { return; } if (!bEnable) //editor case { //return Resources.Load(relpath, t); return; } else { string classname = t.Name; if (resourcetable.ContainsKey(classname) == false) { return; } Dictionary <string, ResourceInfoEx> infolist = resourcetable[classname]; if (infolist == null) { return; } string resname = Path.GetFileNameWithoutExtension(relpath); if (infolist.ContainsKey(resname) == false) { return; } ResourceInfoEx info = infolist[resname]; //if (info.path == null || info.path.Length <= 0) return; //UnityEngine.Object retobj = Resources.Load(info.path, t); //if (retobj == null) //{ // retobj = Resources.Load(info.path); //} //if (!t.IsInstanceOfType(retobj)) //{ // UnityEngine.Object extractobj = GetObjectFromDependent(retobj, resname, t); // if (extractobj != null) retobj = extractobj; //} //if (t == null || !t.IsInstanceOfType(retobj)) //{ // Debug.Log("resname=" + resname + ",respath=" + info.path); // Debug.Log(retobj); //} //if (handler != null) //{ // handler(relpath, retobj); //} if (info.obj != null)//已经加载过的直接回调 { info.refcount++; if (handler != null) { handler(relpath, info.obj); } return; } if (info.length > 0) { if (abm.abhs.ContainsKey(info.bundlename)) { AssetBundleEx ab = abm.abhs[info.bundlename]; if (ab.afs.ContainsKey(info.assetfilename)) { AssetFileEx af = ab.afs[info.assetfilename]; Stream fs = af.stream; fs.Position = info.offset; byte[] data = new byte[info.length]; AsyncResourceState asyncState = new AsyncResourceState { FS = fs, Buffer = data, Info = info, T = t, Handler = handler, ResourcePath = relpath }; IAsyncResult asyncResult = fs.BeginRead(data, (int)0, (int)info.length, new AsyncCallback(AsyncReadCallback), asyncState); } } } return; } }
public static UnityEngine.Object Load(string relpath, Type t) { if (relpath == null || relpath.Length <= 0) { return(null); } if (!bEnable) { UnityEngine.Object retobj = null; try { if (LoadResourceEvent != null) { retobj = LoadResourceEvent(relpath, t); } } catch { } return(retobj); } else { string classname = t.Name; if (resourcetable.ContainsKey(classname) == false) { return(null); } Dictionary <string, ResourceInfoEx> infolist = resourcetable[classname]; if (infolist == null) { return(null); } string resname = Path.GetFileNameWithoutExtension(relpath); if (infolist.ContainsKey(resname) == false) { return(null); } ResourceInfoEx info = infolist[resname]; //if (info.path == null || info.path.Length <= 0) return null; //UnityEngine.Object retobj = Resources.Load(info.path, t); //if (retobj == null) //{ // retobj = Resources.Load(info.path); //} //if (!t.IsInstanceOfType(retobj)) //{ // UnityEngine.Object extractobj = GetObjectFromDependent(retobj, resname, t); // if (extractobj != null) retobj = extractobj; //} //if (t == null || !t.IsInstanceOfType(retobj)) //{ //} //Debug.Log("resname=" + resname + ",respath=" + info.path); //Debug.Log(retobj); //return retobj; if (info.obj != null) { info.refcount++; return(info.obj); //已经有直接返回 } UnityEngine.Object retobj = null; if (info.length > 0) { if (abm.abhs.ContainsKey(info.bundlename)) { AssetBundleEx ab = abm.abhs[info.bundlename]; if (ab.afs.ContainsKey(info.assetfilename)) { AssetFileEx af = ab.afs[info.assetfilename]; Stream fs = af.stream; fs.Position = info.offset; byte[] data = new byte[info.length]; int ret = fs.Read(data, (int)0, (int)info.length); if (ret == info.length) { retobj = LoadByType(info, data, t); loadedlist.Add(info); } } } } return(retobj); } }