Hi, this is our hook event code. Any suggestions how to hook the AnimationState before any event is fired?
The only way how it can be handled as I see it is that iAnimationState will have call back OnAnimationStateInitialized or similar approach?
Thank you, Marek.
private void Awake()
{
skeletonAnimation = GetComponent<SkeletonAnimation>();
if (skeletonAnimation)
{
iSkeletonAnimation = skeletonAnimation as ISkeletonAnimation;
iAnimationState = skeletonAnimation as IAnimationStateComponent;
}
skeletonGraphics = GetComponent<SkeletonGraphic>();
if (skeletonGraphics)
{
iSkeletonAnimation = skeletonGraphics as ISkeletonAnimation;
iAnimationState = skeletonGraphics as IAnimationStateComponent;
}
}
IEnumerator Start()
{
yield return null;
iAnimationState.AnimationState.Event += OnEvent;
}
I changed the code to wait one frame since we were not sure if AnimationState was already initialised. Likely we can use here yiled return WaitWhile(()=> iAnimationState.AnimationState == null);
Like this.
private void Awake()
{
skeletonAnimation = GetComponent<SkeletonAnimation>();
if (skeletonAnimation)
{
iSkeletonAnimation = skeletonAnimation as ISkeletonAnimation;
iAnimationState = skeletonAnimation as IAnimationStateComponent;
}
skeletonGraphics = GetComponent<SkeletonGraphic>();
if (skeletonGraphics)
{
iSkeletonAnimation = skeletonGraphics as ISkeletonAnimation;
iAnimationState = skeletonGraphics as IAnimationStateComponent;
}
}
IEnumerator Start()
{
yield return new WaitWhile(() => iAnimationState.AnimationState == null);
iAnimationState.AnimationState.Event += OnEvent;
}
Will this secure that we will hook before any event is fired?
What I feel we need is below otherwise we will be never able to assure that we are hooked the right time. Right?
iAnimationState.OnInitialized(HookEvents());
Likely we need the same for iSkeletonAnimation!
iSkeletonAnimation.OnInitialized(DoSomething());