本文整理汇总了C++中TArray::IsValidIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ TArray::IsValidIndex方法的具体用法?C++ TArray::IsValidIndex怎么用?C++ TArray::IsValidIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TArray
的用法示例。
在下文中一共展示了TArray::IsValidIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitializeInjectedNodes
void InitializeInjectedNodes(UBehaviorTreeGraphNode* GraphNode, UBTCompositeNode* RootNode, uint16 ExecutionIndex, uint8 TreeDepth, int32 ChildIdx)
{
TMap<UBehaviorTreeGraphNode_CompositeDecorator*, FIntIntPair> CompositeMap;
TArray<UBTDecorator*> DecoratorInstances;
TArray<FBTDecoratorLogic> DecoratorOperations;
for (int32 i = 0; i < GraphNode->Decorators.Num(); i++)
{
UBehaviorTreeGraphNode* MyNode = GraphNode->Decorators[i];
if (MyNode == NULL || !MyNode->bInjectedNode)
{
continue;
}
UBehaviorTreeGraphNode_Decorator* MyDecoratorNode = Cast<UBehaviorTreeGraphNode_Decorator>(MyNode);
UBehaviorTreeGraphNode_CompositeDecorator* MyCompositeNode = Cast<UBehaviorTreeGraphNode_CompositeDecorator>(MyNode);
if (MyDecoratorNode)
{
MyDecoratorNode->CollectDecoratorData(DecoratorInstances, DecoratorOperations);
}
else if (MyCompositeNode)
{
MyCompositeNode->SetDecoratorData(RootNode, ChildIdx);
FIntIntPair RangeData;
RangeData.FirstIdx = DecoratorInstances.Num();
MyCompositeNode->CollectDecoratorData(DecoratorInstances, DecoratorOperations);
RangeData.LastIdx = DecoratorInstances.Num() - 1;
CompositeMap.Add(MyCompositeNode, RangeData);
}
}
for (int32 i = 0; i < DecoratorInstances.Num(); i++)
{
DecoratorInstances[i]->InitializeNode(RootNode, ExecutionIndex, 0, TreeDepth);
DecoratorInstances[i]->InitializeDecorator(ChildIdx);
ExecutionIndex++;
}
// initialize composite decorators
for (TMap<UBehaviorTreeGraphNode_CompositeDecorator*, FIntIntPair>::TIterator It(CompositeMap); It; ++It)
{
UBehaviorTreeGraphNode_CompositeDecorator* Node = It.Key();
const FIntIntPair& PairInfo = It.Value();
if (DecoratorInstances.IsValidIndex(PairInfo.FirstIdx) &&
DecoratorInstances.IsValidIndex(PairInfo.LastIdx))
{
Node->FirstExecutionIndex = DecoratorInstances[PairInfo.FirstIdx]->GetExecutionIndex();
Node->LastExecutionIndex = DecoratorInstances[PairInfo.LastIdx]->GetExecutionIndex();
}
}
}
示例2: Possess
void AZombieController::Possess(APawn* Pawn)
{
Super::Possess(Pawn);
AZombieCharacter* Zombie = Cast<AZombieCharacter>(Pawn);
if (Zombie)
{
//Initialize blackboard
if (Zombie->BehaviorTree->BlackboardAsset)
{
BlackboardComp->InitializeBlackboard(*(Zombie->BehaviorTree->BlackboardAsset));
}
//Get player and hold a reference of it
TArray<AActor*> ActorsArray;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ARoguelikeChar::StaticClass(), ActorsArray);
if (ActorsArray.IsValidIndex(0))
{
ARoguelikeChar* Player = Cast<ARoguelikeChar>(ActorsArray[0]);
if (Player)
{
BlackboardComp->SetValueAsObject(PlayerBlackboardKey, Player);
}
}
//Start the tree
BehaviorComp->StartTree(*Zombie->BehaviorTree);
}
}
示例3: AppendPathPointsHelper
void AppendPathPointsHelper(TArray<FNavPathPoint>& PathPoints, const TArray<FPathPointInfo>& SourcePoints, int32 Index)
{
if (SourcePoints.IsValidIndex(Index) && SourcePoints[Index].Point.NodeRef != 0)
{
PathPoints.Add(SourcePoints[Index].Point);
}
}
示例4: PreLootAction
void UGISInventoryBaseComponent::PreLootAction(TArray<class AGISPickupActor*> PickupsIn)
{
TArray<FGISPickupActorDistanceHelper> HelperStruct;
FVector PawmLocation = PCOwner->GetPawn()->GetActorLocation();
for (AGISPickupActor* Pickup : PickupsIn)
{
if (Pickup)
{
if (Pickup->ItemToLoot.Num() > 0)
{
float Distance = FVector::Dist(PawmLocation, Pickup->GetActorLocation());
FGISPickupActorDistanceHelper helper(Distance, Pickup);
HelperStruct.Add(helper);
}
}
}
HelperStruct.Sort();
if (HelperStruct.IsValidIndex(0))
{
//don't need to check everything. If closest actor is to far, rest is as well.
if (HelperStruct[0].Distance > MaxLootingDistance)
StartLooting(HelperStruct[0].PickupActor.Get());
}
}
示例5: FindPropertyRecursive
FTrackInstancePropertyBindings::FPropertyAddress FTrackInstancePropertyBindings::FindPropertyRecursive( const UObject* Object, void* BasePointer, UStruct* InStruct, TArray<FString>& InPropertyNames, uint32 Index ) const
{
UProperty* Property = FindField<UProperty>(InStruct, *InPropertyNames[Index]);
FTrackInstancePropertyBindings::FPropertyAddress NewAddress;
UStructProperty* StructProp = Cast<UStructProperty>( Property );
if( StructProp )
{
NewAddress.Property = StructProp;
NewAddress.Address = BasePointer;
if( InPropertyNames.IsValidIndex(Index+1) )
{
void* StructContainer = StructProp->ContainerPtrToValuePtr<void>(BasePointer);
return FindPropertyRecursive( Object, StructContainer, StructProp->Struct, InPropertyNames, Index+1 );
}
else
{
check( StructProp->GetName() == InPropertyNames[Index] );
}
}
else if( Property )
{
NewAddress.Property = Property;
NewAddress.Address = BasePointer;
}
return NewAddress;
}
示例6: Format_NoLock
FString FTextFormatData::Format_NoLock(const FPrivateTextFormatArguments& InFormatArgs)
{
ConditionalCompile_NoLock();
if (LexedExpression.Num() == 0)
{
return SourceExpression;
}
FString ResultString;
ResultString.Reserve(BaseFormatStringLength + (InFormatArgs.EstimatedArgumentValuesLength * FormatArgumentEstimateMultiplier));
int32 ArgumentIndex = 0;
for (int32 TokenIndex = 0; TokenIndex < LexedExpression.Num(); ++TokenIndex)
{
const FExpressionToken& Token = LexedExpression[TokenIndex];
if (const auto* Literal = Token.Node.Cast<TextFormatTokens::FStringLiteral>())
{
ResultString.AppendChars(Literal->StringStartPos, Literal->StringLen);
}
else if (auto* Escaped = Token.Node.Cast<TextFormatTokens::FEscapedCharacter>())
{
ResultString.AppendChar(Escaped->Character);
}
else if (const auto* ArgumentToken = Token.Node.Cast<TextFormatTokens::FArgumentTokenSpecifier>())
{
const FFormatArgumentValue* const PossibleArgumentValue = InFormatArgs.GetArgumentValue(*ArgumentToken, ArgumentIndex++);
if (PossibleArgumentValue)
{
if (LexedExpression.IsValidIndex(TokenIndex + 1))
{
const FExpressionToken& NextToken = LexedExpression[TokenIndex + 1];
// Peek to see if the next token is an argument modifier
if (const auto* ArgumentModifierToken = NextToken.Node.Cast<TextFormatTokens::FArgumentModifierTokenSpecifier>())
{
ArgumentModifierToken->TextFormatArgumentModifier->Evaluate(*PossibleArgumentValue, InFormatArgs, ResultString);
++TokenIndex; // walk over the argument token so that the next iteration will skip over the argument modifier
continue;
}
}
PossibleArgumentValue->ToFormattedString(InFormatArgs.bRebuildText, InFormatArgs.bRebuildAsSource, ResultString);
}
else
{
ResultString.AppendChar(TextFormatTokens::ArgStartChar);
ResultString.AppendChars(ArgumentToken->ArgumentNameStartPos, ArgumentToken->ArgumentNameLen);
ResultString.AppendChar(TextFormatTokens::ArgEndChar);
}
}
}
return ResultString;
}
示例7: FVector
TArray<FVector> ULeapImage::LocateBlobs(TArray<FVector> blobArray1, TArray<FVector> blobArray2)
{
TArray<FVector> BlobVectors;
uint8 matchBlobs[200];
FVector blobLocation, blob1, blob2, cameraOffset;;
cameraOffset = FVector(-0.02f, 0.0f, 0.0f);
//MATCH THE LEFT RAYS TO THE RIGHT RAYS
//MAKE SURE RAYS ARE AT LEAST WITHIN 0.05 OF EACHOTHER
//PICK PAIR THAT RESULTS IN LONGER DISTANCE TO AVOID ENTANGLEMENT
for (int i = 0; blobArray1.IsValidIndex(i); i++) {
matchBlobs[i] = 255;
}
float farthest;
for (int i = 0; blobArray1.IsValidIndex(i); i++){
farthest = 0.05f; //MUST BE FARTHER THAN THIS TO COUNT AT ALL
for (int j = 0; blobArray2.IsValidIndex(j); j++){
//TEST ALL FOR FARTHEST WORKING BLOB
float intersectiondistance = _private->ClosestDistOfApproach(-cameraOffset, blobArray1[i], cameraOffset, blobArray2[j]);
float distancefromleap = _private->ClosestTimeOfApproach(-cameraOffset, blobArray1[i], cameraOffset, blobArray2[j]);
if (distancefromleap > farthest) {
if (intersectiondistance < 0.02f) {
farthest = distancefromleap;
matchBlobs[i] = j;
}
}
}
}
//ADD BLOB POSITIONS (RELATIVE TO PARENT) ONLY AT THE INTERSECTION OF THE MATCHED RAYS
for (int i = 0; blobArray1.IsValidIndex(i); i++){
if (matchBlobs[i] != 255){
blobLocation = _private->ClosestPointOfApproach(-cameraOffset, blobArray1[i], cameraOffset, blobArray2[matchBlobs[i]]);
BlobVectors.Add(blobLocation);
}
}
return BlobVectors;
}
示例8: ExtractLocation
FVector ExtractLocation(TSubclassOf<UEnvQueryItemType> ItemType, const TArray<uint8>& RawData, const TArray<FEnvQueryItem>& Items, int32 Index)
{
if (Items.IsValidIndex(Index) &&
ItemType->IsChildOf(UEnvQueryItemType_VectorBase::StaticClass()))
{
UEnvQueryItemType_VectorBase* DefTypeOb = ItemType->GetDefaultObject<UEnvQueryItemType_VectorBase>();
return DefTypeOb->GetItemLocation(RawData.GetData() + Items[Index].DataOffset);
}
return FVector::ZeroVector;
}
示例9: LoadFile
void ASignDialogueHandler::LoadFile(FString fileName) {
FXmlFile file(fileName);
FXmlNode* root = file.GetRootNode();
if (root != NULL) {
TArray<FXmlNode*> rootChildren = root->GetChildrenNodes();
// Run through the root's children
for (int i = 0; i < rootChildren.Num(); i++) {
if (rootChildren.IsValidIndex(i)) {
TArray<FXmlNode*> children = rootChildren[i]->GetChildrenNodes();
if (children.IsValidIndex(0) && children.IsValidIndex(1)
&& SignArray.IsValidIndex(i)) {
SignArray[i]->signInfo.signID = FCString::Atoi(*children[0]->GetContent());
SignArray[i]->signInfo.line = children[1]->GetContent();
}
}
}
}
}
示例10: MakeError
TValueOrError<FString, FExpressionError> FStringFormatter::FormatInternal(const TCHAR* InExpression, const TArray<FStringFormatArg>& Args, bool bStrict) const
{
TValueOrError<TArray<FExpressionToken>, FExpressionError> Result = ExpressionParser::Lex(InExpression, bStrict ? StrictOrderedDefinitions : OrderedDefinitions);
if (!Result.IsValid())
{
return MakeError(Result.StealError());
}
TArray<FExpressionToken>& Tokens = Result.GetValue();
if (Tokens.Num() == 0)
{
return MakeValue(InExpression);
}
// This code deliberately tries to reallocate as little as possible
FString Formatted;
Formatted.Reserve(Tokens.Last().Context.GetTokenEndPos() - InExpression);
for (auto& Token : Tokens)
{
if (const auto* Literal = Token.Node.Cast<FStringLiteral>())
{
Formatted.AppendChars(Literal->String.GetTokenStartPos(), Literal->Len);
}
else if (auto* Escaped = Token.Node.Cast<FEscapedCharacter>())
{
Formatted.AppendChar(Escaped->Character);
}
else if (const auto* IndexToken = Token.Node.Cast<FIndexSpecifier>())
{
if (Args.IsValidIndex(IndexToken->Index))
{
AppendToString(Args[IndexToken->Index], Formatted);
}
else if (bStrict)
{
return MakeError(FText::Format(LOCTEXT("InvalidArgumentIndex", "Invalid argument index: {0}"), FText::AsNumber(IndexToken->Index)));
}
else
{
// No replacement found, so just add the original token string
const int32 Length = IndexToken->EntireToken.GetTokenEndPos() - IndexToken->EntireToken.GetTokenStartPos();
Formatted.AppendChars(IndexToken->EntireToken.GetTokenStartPos(), Length);
}
}
}
return MakeValue(Formatted);
}
示例11: SetCompositeDecoratorRuntimeDescription
void FBehaviorTreeDebugger::SetCompositeDecoratorRuntimeDescription(const TArray<FString>& RuntimeDescriptions, class UBehaviorTreeGraphNode_CompositeDecorator* Node)
{
Node->DebuggerRuntimeDescription.Empty();
for (int32 i = Node->FirstExecutionIndex; i <= Node->LastExecutionIndex; i++)
{
if (RuntimeDescriptions.IsValidIndex(i) && RuntimeDescriptions[i].Len())
{
if (Node->DebuggerRuntimeDescription.Len())
{
Node->DebuggerRuntimeDescription.AppendChar(TEXT('\n'));
}
Node->DebuggerRuntimeDescription += FString::Printf(TEXT("[%d] %s"), i, *RuntimeDescriptions[i].Replace(TEXT("\n"), TEXT(", ")));
}
}
}
示例12: ClearControl
/**
* Called when a Controller is logout from the game or changes teams. If there is
* atleast one teammate left on the team, then the team will continue to be in controll
* of the leaving Controllers ControlPoints.If there is no other teammates left on the
* team after the player changes teams/logout, then any ControlPoints controlled by the
* Controller is set back to Neutral.
* @param PS The Controller who is changing teams or is logout.
*/
void AUTDomGameMode::ClearControl(AUTPlayerState* PS)
{
TArray<AUTPlayerState*> Pick;
uint8 Num, i;
// find a teammate
if (PS == NULL)
{
return;
}
for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
{
AUTPlayerController* NextPlayer = Cast<AUTPlayerController>(*Iterator);
AUTPlayerState* TestPS = NextPlayer ? Cast<AUTPlayerState>(NextPlayer->PlayerState) : NULL;
if (TestPS != NULL && TestPS != PS && (PS->GetTeamNum() == TestPS->GetTeamNum()))
{
Pick.AddUnique(TestPS);
}
}
if (Pick.Num() > 0)
{
Num = FMath::RandHelper(Pick.Num());
if (Pick.IsValidIndex(Num) && Pick[Num] != NULL)
{
// Give random team mate control over leaving players control points
for (i = 0; i < CDomPoints.Num(); i++)
{
if (CDomPoints[i]->TeamNum != 255 && CDomPoints[i]->ControllingPawn == PS)
{
CDomPoints[i]->ControllingPawn = Pick[Num];
CDomPoints[i]->UpdateStatus();
}
}
return;
}
}
// No teammate found, so reset the point to X
for (i = 0; i < CDomPoints.Num(); i++)
{
if (CDomPoints[i]->ControllingPawn == PS)
{
CDomPoints[i]->ResetPoint(true);
}
}
}
示例13: AssignStringToProperty
FString DataTableUtils::AssignStringToProperty(const FString& InString, const UProperty* InProp, uint8* InData)
{
FStringOutputDevice ImportError;
if(InProp && IsSupportedTableProperty(InProp))
{
if(InProp->ArrayDim == 1)
{
DataTableUtilsImpl::AssignStringToProperty(InString, InProp, InData, 0, PPF_None, ImportError);
}
else
{
if(InString.Len() >= 2 && InString[0] == '(' && InString[InString.Len() - 1] == ')')
{
// Trim the ( and )
FString StringToSplit = InString.Mid(1, InString.Len() - 2);
TArray<FString> Values;
StringToSplit.ParseIntoArray(Values, TEXT(","), 1);
if (InProp->ArrayDim != Values.Num())
{
UE_LOG(LogDataTable, Warning, TEXT("%s - Array is %d elements large, but we have %d values to import"), *InProp->GetName(), InProp->ArrayDim, Values.Num());
}
for (int32 Index = 0; Index < InProp->ArrayDim; ++Index)
{
if (Values.IsValidIndex(Index))
{
DataTableUtilsImpl::AssignStringToProperty(Values[Index], InProp, InData, Index, PPF_Delimited, ImportError);
}
}
}
else
{
UE_LOG(LogDataTable, Warning, TEXT("%s - Malformed array string. It must start with '(' and end with ')'"), *InProp->GetName());
}
}
}
FString Error = ImportError;
return Error;
}
示例14: DetermineIfPlayerOverlaps
bool UColorPadActivator::DetermineIfPlayerOverlaps()
{
TArray<AActor*> OverlappingActors;
GetOwner()->GetOverlappingActors(
OUT OverlappingActors,
ADefaultPawn::StaticClass()
);
if (OverlappingActors.IsValidIndex(0))
{
//player is overlapping
return true;
}
else
{
//player is not overlapping
return false;
}
}
示例15: ChooseTeam
int32 AHeliGameModeLobby::ChooseTeam(AHeliPlayerState* ForPlayerState) const
{
// choose one of the teams that are least populated
TArray<int32> TeamBalance;
TeamBalance.AddZeroed(NumTeams);
// get current team balance
for (int32 i = 0; i < GameState->PlayerArray.Num(); i++)
{
AHeliPlayerState const* const TestPlayerState = Cast<AHeliPlayerState>(GameState->PlayerArray[i]);
if (TestPlayerState && TestPlayerState != ForPlayerState && TeamBalance.IsValidIndex(TestPlayerState->GetTeamNumber()))
{
TeamBalance[TestPlayerState->GetTeamNumber()]++;
}
}
// find least populated one
int32 BestTeamScore = TeamBalance[0];
for (int32 i = 1; i < TeamBalance.Num(); i++)
{
if (BestTeamScore > TeamBalance[i])
{
BestTeamScore = TeamBalance[i];
}
}
// there could be more than one...
TArray<int32> BestTeams;
for (int32 i = 0; i < TeamBalance.Num(); i++)
{
if (TeamBalance[i] == BestTeamScore)
{
BestTeams.Add(i);
}
}
// get random from best list
const int32 RandomBestTeam = BestTeams[FMath::RandHelper(BestTeams.Num())];
return RandomBestTeam;
}