Last active
November 15, 2018 06:56
-
-
Save luxuia/98eb171f6970a2185222f749e18edfe9 to your computer and use it in GitHub Desktop.
unity create obb by hand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[MenuItem("Demo/Build Bundle")] | |
static void Build() | |
{ | |
BuildPipeline.BuildAssetBundles("Assets", BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.Android); | |
FileUtil.DeleteFileOrDirectory ("obb.zip"); | |
var obbFile = ZipFile.Create ("obb.zip"); | |
obbFile.BeginUpdate (); | |
obbFile.Add ("Assets/bundle", CompressionMethod.Stored); | |
obbFile.CommitUpdate (); | |
} | |
void Load() | |
{ | |
var zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile ("obb.zip"); | |
var entry = zipFile.GetEntry ("Assets/bundle"); | |
ulong fileOffset; | |
using (var stream = zipFile.GetInputStream(entry)) { | |
fileOffset = (ulong)stream.Seek(0, System.IO.SeekOrigin.Begin); | |
Debug.Log ("entry: " + entry.Size + " " + fileOffset ); | |
} | |
var assetBundle = AssetBundle.LoadFromFile("obb.zip", 0, fileOffset); | |
var myTexture = assetBundle.LoadAsset("Image") as Texture2D; | |
gameObject.GetComponent<Renderer> ().material.mainTexture = myTexture; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment