示例#1
0
void FLiveEditorManager::RegisterEventListener( UObject *Target, FName EventName )
{
	if ( !Target )
		return;

	UFunction *Function = Target->FindFunction( EventName );
	if ( Function == NULL )
		return;

	ULiveEditorBlueprint *Blueprint = Cast<ULiveEditorBlueprint>(Target);
	check( Blueprint != NULL );
	
	FString BlueprintName = Blueprint->GetName();
	int32 chopIndex = BlueprintName.Find( TEXT("_C"), ESearchCase::CaseSensitive, ESearchDir::FromEnd );
	if ( chopIndex != INDEX_NONE )
	{
		BlueprintName = BlueprintName.LeftChop( BlueprintName.Len() - chopIndex );
	}

	const FLiveEditBinding* Binding = LiveEditorUserData->GetBinding( BlueprintName, EventName.ToString() );
	if ( Binding != NULL )
	{
		ILiveEditListener *Listener = new ILiveEditListener(EventName, *Binding, Target);
		int ID = LISTENER_ID(Listener->Binding.Channel,Listener->Binding.ControlID); //needs to remain int (instead of int32) since numbers are derived from TPL that uses int
		EventListeners.Add(ID,Listener);
	}
	else
	{
		FString Message = FString::Printf( TEXT("A LiveEditor Event (%s) is not bound and will not work. Please Re-bind this LiveEditorBlueprint in the LiveEditor Control Panel"), *EventName.ToString() );
		FPlatformMisc::MessageBoxExt( EAppMsgType::Ok, *Message, *NSLOCTEXT("MessageDialog", "DefaultDebugMessageTitle", "ShowDebugMessagef").ToString() );
	}
}
	FString GetSafeBlueprintName( const ULiveEditorBlueprint &Instance )
	{
		FString BlueprintName = Instance.GetName();
		int32 chopIndex = BlueprintName.Find( TEXT("_C"), ESearchCase::CaseSensitive, ESearchDir::FromEnd );
		if ( chopIndex != INDEX_NONE )
		{
			BlueprintName = BlueprintName.LeftChop( BlueprintName.Len() - chopIndex );
		}
		return BlueprintName;
	}