We use an extension method on Awake to get the SkeletonAnimation comp. and set the Complete callback.
public static void InitializeSkeletalAnimation(this GameObject game_object) {
SkeletonAnimation animation = game_object.GetComponent<SkeletonAnimation>();
ConDevGameObject cd_gobj = game_object.GetComponent<ConDevGameObject>();
if (animation != null && cd_gobj != null) {
animation.state.Complete += cd_gobj.AnimationComplete;
}
}
We then use it here
public class ConDevGameObject : MonoBehaviour {
public int GameObjectType;
public int GameObjectTypeIndex;
public bool DisableAfterInitialization;
protected Transform _transform;
protected GameController _controller;
protected SkeletonAnimation _animation;
protected void Awake() {
_transform = gameObject.transform;
_controller = ConDevTools.GetGameController();
_animation = gameObject.GetComponent<SkeletonAnimation>();
Initialize();
}
protected virtual void AnimationCompleteCallback(Spine.AnimationState state, int trackIndex, int loopCount) { }
public void AnimationComplete(Spine.AnimationState state, int trackIndex, int loopCount) {
AnimationCompleteCallback(state, trackIndex, loopCount);
_controller.SkeletalAnimationComplete(GameObjectType, GameObjectTypeIndex, trackIndex, state.GetCurrent(trackIndex).animation.Name);
}
protected virtual void Initialize() {
gameObject.InitializeSkeletalAnimation();
if (DisableAfterInitialization == true)
enabled = false;
}
public virtual void Spawn() {
gameObject.SetActive(true);
_controller.ObjectSpawned(this);
}
public virtual void Spawn(Vector3 position) {
_transform.position = position;
gameObject.SetActive(true);
_controller.ObjectSpawned(this);
}
public virtual void Despawn() {
gameObject.SetActive(false);
_controller.ObjectDespawned(this);
}
public void Destory() {
GameObject.Destroy(this.gameObject);
}
}
and then wait for something to happen here in the game controller so it can do it thing to the game objects
public void SkeletalAnimationComplete(int type, int index, int track_index, string animation_name) {
if(type == GAMEOBJECT_TYPE_CITIZEN) {
CitizenAnimationComplete(index, track_index, animation_name);
} else if(type == GAMEOBJECT_TYPE_THREAT) {
ThreatAnimationComplete(index, track_index, animation_name);
}
else if(type == GAMEOBJECT_TYPE_BUILDING) {
BuildingAnimationComplete(index, track_index, animation_name);
}
}
I'm going to try to simplify a project to see if I can see what you guys are seeing, but all objects use ConDevGameObject and not one of them fires animation complete.