Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created December 14, 2018 12:29
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 tsubaki/f3127d81f89841355302b82b69ef671b to your computer and use it in GitHub Desktop.
Save tsubaki/f3127d81f89841355302b82b69ef671b to your computer and use it in GitHub Desktop.
SpriteAtlasのリクエスト
using System;
using UnityEngine;
using UnityEngine.U2D;
public class Rebind : MonoBehaviour
{
Action<SpriteAtlas> atlasAction;
AssetBundle assetbundle;
const string assetBundleName = "atlas";
private void Awake()
{
assetbundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + assetBundleName);
}
private void OnDestroy()
{
assetbundle.Unload(true);
}
private void OnEnable()
{
SpriteAtlasManager.atlasRequested += AtlasRequested;
}
private void OnDisable()
{
SpriteAtlasManager.atlasRequested -= AtlasRequested;
}
void AtlasRequested(string tag, Action<SpriteAtlas> atlasAction)
{
var request = assetbundle.LoadAssetAsync<SpriteAtlas>(tag);
request.completed += (op) =>
{
atlasAction.Invoke((SpriteAtlas)request.asset);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment