Created
December 14, 2018 12:29
-
-
Save tsubaki/f3127d81f89841355302b82b69ef671b to your computer and use it in GitHub Desktop.
SpriteAtlasのリクエスト
This file contains 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
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