safe instance for swf manager

This commit is contained in:
2016-08-25 13:58:59 +07:00
parent cf2e980560
commit 6190dd60f6
2 changed files with 10 additions and 8 deletions

View File

@@ -81,7 +81,7 @@ namespace FlashTools {
}
void BakeFrameMesh(SwfAnimationFrameData frame) {
var swf_manager = SwfManager.Instance;
var swf_manager = SwfManager.GetInstance(true);
for ( var i = 0; i < frame.Instances.Count; ++i ) {
var inst = frame.Instances[i];
var bitmap = inst != null ? FindBitmap(inst.Bitmap) : null;
@@ -245,14 +245,14 @@ namespace FlashTools {
}
void OnEnable() {
var swf_manager = SwfManager.Instance;
var swf_manager = SwfManager.GetInstance(true);
if ( swf_manager ) {
swf_manager.AddSwfAnimation(this);
}
}
void OnDisable() {
var swf_manager = SwfManager.Instance;
var swf_manager = SwfManager.GetInstance(false);
if ( swf_manager ) {
swf_manager.RemoveSwfAnimation(this);
}

View File

@@ -38,13 +38,15 @@ namespace FlashTools {
// ---------------------------------------------------------------------
static SwfManager _instance;
public static SwfManager Instance {
get {
if ( !_instance ) {
_instance = FindObjectOfType<SwfManager>();
public static SwfManager GetInstance(bool allow_create) {
if ( !_instance ) {
_instance = FindObjectOfType<SwfManager>();
if ( allow_create && !_instance ) {
var go = new GameObject("[SwfManager]");
_instance = go.AddComponent<SwfManager>();
}
return _instance;
}
return _instance;
}
// ---------------------------------------------------------------------