Question by
Tbjang · Sep 08, 2017 at 12:32 AM ·
spritemanager
SpriteAtlasManager.atlasRequested is not triggerd.
Hi. I tried to write a late-binding sprite altas example, but failed. (Unity Editor version is "2017.1.0f3".)
I placed sprite renderer without sprite and maked a script that
subscribe SpriteAtlasManager.atlasRequested
assigns "a sprite unbound to sprite atlas".
But the subscribed callback seemed to be triggered.
Following is my source
public class AtlasSelector : MonoBehaviour { [SerializeField] private SpriteRenderer spriteRenderer = null; [SerializeField] private U2D.SpriteAtlas[] atlases = null; private U2D.SpriteAtlas refAtlas = null; private U2D.SpriteAtlas activeAtlas = null;
void OnEnable()
{
U2D.SpriteAtlasManager.atlasRequested += OnAtlasRequested;
}
void OnDisable()
{
U2D.SpriteAtlasManager.atlasRequested -= OnAtlasRequested;
}
private void Start()
{
Invoke("OnLowBg",1f);
}
void OnAtlasRequested(string tag, System.Action<U2D.SpriteAtlas> callback)
{
Debug.Log("AltasRequested:" + tag);
//if (tag.Equals("bg"))
{
callback(activeAtlas);
}
}
public void OnHighBg()
{
activeAtlas = atlases[0];
refAtlas = Resources.Load<U2D.SpriteAtlas>("bg");
spriteRenderer.sprite = refAtlas.GetSprite("BG");
spriteRenderer.gameObject.SetActive(true);
}
public void OnLowBg()
{
activeAtlas = atlases[1];
refAtlas = Resources.Load<U2D.SpriteAtlas>("bg");
var sprite = refAtlas.GetSprite("BG");
spriteRenderer.sprite = refAtlas.GetSprite("BG");
spriteRenderer.gameObject.SetActive(true);
}
}
It is noted that the field "Include in Build" of "refAtlas" is not checked.
So, how can "SpriteAtlasManager.atlasRequested" is trigged?
Comment