void FMovieSceneSequenceInstance::UpdateObjectBinding(const FGuid& ObjectId, IMovieScenePlayer& Player)
{
	if(MovieSceneSequence.IsValid())
	{
		UMovieSceneSequence* Sequence = MovieSceneSequence.Get();
		auto* BindingInstance = ObjectBindingInstances.Find(ObjectId);

		if (!BindingInstance || !Sequence)
		{
			return;
		}

		// Update the runtime objects
		BindingInstance->RuntimeObjects.Reset();

		TWeakObjectPtr<UObject>* WeakSpawnedObject = SpawnedObjects.Find(ObjectId);
		if (WeakSpawnedObject)
		{
			UObject* SpawnedObject = WeakSpawnedObject->Get();
			if (SpawnedObject)
			{
				BindingInstance->RuntimeObjects.Add(SpawnedObject);
			}
		}
		else
		{
			Player.GetRuntimeObjects(SharedThis(this), BindingInstance->ObjectGuid, BindingInstance->RuntimeObjects);
		}

		const FMovieSceneBinding* ObjectBinding = Sequence->GetMovieScene()->GetBindings().FindByPredicate([&](const FMovieSceneBinding& In){
			return In.GetObjectGuid() == ObjectId;
		});

		// Refresh the instance map, if we found the binding itself
		if (ObjectBinding)
		{
			RefreshInstanceMap(ObjectBinding->GetTracks(), BindingInstance->RuntimeObjects, BindingInstance->TrackInstances, Player);
		}
	}
}
コード例 #2
0
void FMovieSceneShotTrackInstance::RefreshInstance( const TArray<UObject*>& RuntimeObjects, IMovieScenePlayer& Player )
{
    const TArray<UMovieSceneSection*>& ShotSections = SubMovieSceneTrack->GetAllSections();

    RuntimeCameraObjects.Empty( ShotSections.Num() );

    for( UMovieSceneSection* Section : ShotSections )
    {
        // @todo Sequencer - Sub-moviescenes: Get the cameras from the root movie scene instance.  We should support adding cameras for sub-moviescenes as shots
        TArray<UObject*> CameraObjects;
        Player.GetRuntimeObjects(Player.GetRootMovieSceneSequenceInstance(), CastChecked<UMovieSceneShotSection>( Section )->GetCameraGuid(), CameraObjects );
        if( CameraObjects.Num() == 1 )
        {
            RuntimeCameraObjects.Add( CameraObjects[0] );
        }
        else
        {
            // No valid camera object was found, take up space.  There should be one entry per section
            RuntimeCameraObjects.Add( nullptr );
        }
    }

    FSubMovieSceneTrackInstance::RefreshInstance( RuntimeObjects, Player );
}
void FMovieSceneSequenceInstance::RefreshInstance( IMovieScenePlayer& Player )
{
	if(MovieSceneSequence.IsValid())
	{
		UMovieScene* MovieScene = MovieSceneSequence->GetMovieScene();
		TimeRange = MovieScene->GetPlaybackRange();

		UMovieSceneTrack* CameraCutTrack = MovieScene->GetCameraCutTrack();

		if (CameraCutTrack != nullptr)
		{
			FMovieSceneInstanceMap CameraCutTrackInstanceMap;

			if (CameraCutTrackInstance.IsValid())
			{
				CameraCutTrackInstanceMap.Add(CameraCutTrack, CameraCutTrackInstance);
			}

			TArray<TWeakObjectPtr<UObject>> Objects;
			TArray<UMovieSceneTrack*> Tracks;
			Tracks.Add(CameraCutTrack);
			RefreshInstanceMap(Tracks, Objects, CameraCutTrackInstanceMap, Player);

			CameraCutTrackInstance = CameraCutTrackInstanceMap.FindRef(CameraCutTrack);
		}
		else if(CameraCutTrackInstance.IsValid())
		{
			CameraCutTrackInstance->ClearInstance(Player, *this);
			CameraCutTrackInstance.Reset();
		}

		// Get all the master tracks and create instances for them if needed
		const TArray<UMovieSceneTrack*>& MasterTracks = MovieScene->GetMasterTracks();
		TArray<TWeakObjectPtr<UObject>> Objects;
		RefreshInstanceMap( MasterTracks, Objects, MasterTrackInstances, Player );

		TSet< FGuid > FoundObjectBindings;
		// Get all tracks for each object binding and create instances for them if needed
		const TArray<FMovieSceneBinding>& ObjectBindings = MovieScene->GetBindings();
		for( int32 BindingIndex = 0; BindingIndex < ObjectBindings.Num(); ++BindingIndex )
		{
			const FMovieSceneBinding& ObjectBinding = ObjectBindings[BindingIndex];

			// Create an instance for this object binding
			FMovieSceneObjectBindingInstance& BindingInstance = ObjectBindingInstances.FindOrAdd( ObjectBinding.GetObjectGuid() );
			BindingInstance.ObjectGuid = ObjectBinding.GetObjectGuid();

			FoundObjectBindings.Add( ObjectBinding.GetObjectGuid() );

			// Populate the runtime objects for this instance of the binding.
			// @todo sequencer: SubSequences: We need to know which actors were removed and which actors were added so we know which saved actor state to restore/create
			BindingInstance.RuntimeObjects.Empty();
			Player.GetRuntimeObjects( SharedThis( this ), BindingInstance.ObjectGuid, BindingInstance.RuntimeObjects );

			// Refresh the instance's tracks
			const TArray<UMovieSceneTrack*>& Tracks = ObjectBinding.GetTracks();
			RefreshInstanceMap( Tracks, BindingInstance.RuntimeObjects, BindingInstance.TrackInstances, Player );
		}

		IMovieSceneSpawnRegister& SpawnRegister = Player.GetSpawnRegister();

		// Remove object binding instances which are no longer bound
		TMap<FGuid, FMovieSceneObjectBindingInstance>::TIterator It = ObjectBindingInstances.CreateIterator();
		for( ; It; ++It )
		{
			if( !FoundObjectBindings.Contains( It.Key() ) )
			{
				SpawnRegister.DestroySpawnedObject(It.Key(), *this, Player);

				// The instance no longer is bound to an existing guid
				It.RemoveCurrent();
			}
		}
	}
}