Scott Hong
New member
I want to do custom processing when the task is terminated by force due to Conditional Abort.
What callback method is called when the task is killed?
What callback method is called when the task is killed?
public abstract class AbortCallback : Action
{
protected abstract TaskStatus AbortCallbackOnUpdate( );
protected abstract void AbortCallbackOnStart( );
protected abstract void OnAbortCallback( );
public override void OnStart( )
{
base.OnStart( );
m_Triggered = true;
AbortCallbackOnStart( );
}
public sealed override TaskStatus OnUpdate( )
{
return AbortCallbackOnUpdate();
}
public void NotifyAbort( )
{
if ( m_Triggered )
{
Debug.Log ( $"Reset Abort task + {NodeData.Comment}" );
OnAbortCallback( );
}
}
public void ResetCallback( )
{
m_Triggered = false;
}
}
public class SelectorWithAbortCallback : Selector
{
public override void OnConditionalAbort(int childIndex)
{
//-- it seems this CurrentChildIndex() value is 1 index some times and zero index some times.
int currentChildIndex = CurrentChildIndex( );
if ( currentChildIndex > 0 )
{
Debug.LogWarning ( $"+++Selector:OnConditionalAbort ({this.gameObject.GetScenePath( )}) -> currentChildIndex={currentChildIndex} childIndex={childIndex} childcount={children.Count}" );
//-- get the active child task and recursively depend looking for any tasks that extend AbortCallback and recursively traversing any children that are themselves parents.
AbortResetNode ( children[ CurrentChildIndex( ) - 1 ] );
//-- call super (yuck)
base.OnConditionalAbort ( childIndex );
}
}
private void AbortResetNode( Task p_Child )
{
if ( p_Child is ParentTask parentTask )
{
var parentTaskChildren = parentTask.Children;
for ( int i = 0; i <parentTaskChildren.Count ; i++ )
{
AbortResetNode ( parentTaskChildren[ i ] );
}
}
if ( p_Child is AbortCallback abortCallback )
{
abortCallback.NotifyAbort( );
}
}
}