voidFArashiListMeshAction::SnapFoliage(){UWorld*InWorld=GWorld;FScopedTransactionTransaction(NSLOCTEXT("UnrealEd","FoliageMode_Transaction_SnapToGround","Snap Foliage To Ground"));{boolbMovedInstance=false;constint32NumLevels=InWorld->GetNumLevels();for(int32LevelIdx=0;LevelIdx<NumLevels;++LevelIdx){ULevel*Level=InWorld->GetLevel(LevelIdx);AInstancedFoliageActor*IFA=AInstancedFoliageActor::GetInstancedFoliageActorForLevel(Level);if(IFA){boolbFoundSelection=false;for(auto&MeshPair:IFA->FoliageInfos){FFoliageInfo&FoliageInfo=*MeshPair.Value;int32PlacedInstanceCount=FoliageInfo.GetPlacedInstanceCount();//构造一个0到PlacedInstanceCount-1的数组
TArray<int32>SelectedIndices;for(int32i=0;i<PlacedInstanceCount;++i){SelectedIndices.Add(i);}if(PlacedInstanceCount>0){// Mark actor once we found selection
{IFA->Modify();bFoundSelection=true;}FoliageInfo.PreMoveInstances(IFA,SelectedIndices);for(int32InstanceIndex:SelectedIndices){bMovedInstance|=SnapInstanceToGround(IFA,MeshPair.Key->AlignMaxAngle,FoliageInfo,InstanceIndex);}FoliageInfo.PostMoveInstances(IFA,SelectedIndices);}}}}if(bMovedInstance){}}}