-
how to AssetBundle Assets To single bytes asset(A.gamepack) ?
-
build all unity assets to AssetBundle Assets then compress to one bytes asset(A.gamepack)
use AssetBundle.LoadFromStream from A.gamepack, self calculate byte offset.
-
now i can get AssetBundle,
but call AssetBundle.LoadFromStream unity crash ("Size overflow in allocator.")
unity(2018.2.8) tips error > Cancelling DisplayDialog because it was run from a thread that is not the main thread: Opening file failed Opening file E:/I/Git/FateDefence/Program/Client/Unity/archive:/CAB-6e4f272b42d7f042dbb7f17aeee3610b/CAB-6e4f272b42d7f042dbb7f17aeee3610b.resS:
- > Could not open file archive:/CAB-6e4f272b42d7f042dbb7f17aeee3610b/CAB-6e4f272b42d7f042dbb7f17aeee3610b.resS for read
- > async texture load: failed to load 3 from archive:/CAB-6e4f272b42d7f042dbb7f17aeee3610b/CAB-6e4f272b42d7f042dbb7f17aeee3610b.resS
-
thank
_
class AssetDB
{
public AssetBundle LoadBundle(string lineKey)
{
// move position to current asset bundle begin postion
int len = GetTableFieldLength(AssetsTable, lineKey, (byte)EAssetFields.Asset);
if (len <= 0)
{
Debug.LogError("not found asset:" + lineKey);
return null;
}
// AssetBundle.LoadFromStream force from zero position reading, record now position then revert
mContentFs.ReadOffsetPosition = (int)mContentFs.Position;
// mContentFs is AssetDB.Stream
AssetBundle bundle = AssetBundle.LoadFromStream(mContentFs);
return bundle;
}
public class Stream : FileStream
{
public int ReadOffsetPosition = -1;
public override int Read(byte[] array, int offset, int count)
{
// revert position
if (ReadOffsetPosition > 0)
{
Position = ReadOffsetPosition;
ReadOffsetPosition = -1;
}
int v = base.Read(array, offset, count);
return v;
}
}
}
use:
// get all deps asset bundle
foreach (var item in db.GetDepsArray("effects/a"))
{
db.LoadBundle(item);
}
// get need assetbundle
var ab = db.LoadBundle("effects/a");
// load gameobject from assetbundle (there unity(2018.1.9) editor crush "Size overflow in allocator" or other error message)
var gameObj = ab.LoadAsset("effects/a");
↧