Skip to content

Instantly share code, notes, and snippets.

@nekomimi-daimao
Last active July 13, 2020 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nekomimi-daimao/b7a27ed713fa694fe732daa08cabe8ad to your computer and use it in GitHub Desktop.
Save nekomimi-daimao/b7a27ed713fa694fe732daa08cabe8ad to your computer and use it in GitHub Desktop.
using System;
using UnityEngine;
public class AssetBundleDisposable : IDisposable
{
public AssetBundle AssetBundle { get; private set; }
private bool _disposed = false;
public AssetBundleDisposable(AssetBundle assetBundle)
{
AssetBundle = assetBundle;
_disposed = false;
}
~AssetBundleDisposable()
{
// Dispose(false);
}
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed || AssetBundle == null)
{
return;
}
AssetBundle.Unload(true);
AssetBundle = null;
_disposed = true;
}
}
static class AssetBundleDisposableExtension
{
public static AssetBundleDisposable AsDisposable(this AssetBundle assetBundle)
{
return new AssetBundleDisposable(assetBundle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment