函数的调用顺序:
这段代码进入ShowMask()中, 再调用 t.OnComplete(ExitSceneComplete);,进行了currentSceneState.EnterScene()操作 ,为何currentSceneState 此时已经变为了baseSceneState ,我认为现在 应该还没执行完ShowMask()函数,请老师解释一哈这个回调方法OnComplete()为何是在 currentSceneState = baseSceneState;后面执行的
public void ChanegSceneState(IBaseSceneState baseSceneState)
{
lastSceneState = currentSceneState;
ShowMask();
currentSceneState = baseSceneState;
}
//显示遮罩
public void ShowMask()
{
Tween t = DOTween.To(() => maskImage.color, toColor => maskImage.color = toColor, new Color(0, 0, 0, 1), 2f);
t.OnComplete(ExitSceneComplete);//在tween动画完成时回调ExitSceneComplete()函数
}
//离开当前场景
private void ExitSceneComplete()
{
lastSceneState.ExitScene();
currentSceneState.EnterScene();
HideMask();
}
//隐藏遮罩
public void HideMask()
{
DOTween.To(() => maskImage.color, toColor => maskImage.color = toColor, new Color(0, 0, 0,0), 2f);
}
同学你好,它是先执行完毕ShowMask里的所有方法之后再去做回调的,没有在OnComplete这里挂起。