/// <summary> /// Builds actors meant to act out the recorded objects and what they did. /// </summary> /// <param name="actorBuilder">What will take the subject data and return us actors for playback.</param> /// <param name="parent">What all created actors will be parented to.</param> /// <returns>Controls for controlling the playback of each individual actor.</returns> /// <remarks> If the actorBuilder is null then cubes will be used to represent the subject. If an actorBuilder is supplied but they supply a null Actor, then that subject will be excluded from the playback. It' generally best to not call this method directly, but use an instance of <a page="EliCDavis.RecordAndPlay.Playback.PlaybackBehavior">PlaybackBehavior</a> to call this method for you and manage all the actors.</remarks> public ActorPlaybackControl[] BuildActors(IActorBuilder actorBuilder, Transform parent) { List <ActorPlaybackControl> actors = new List <ActorPlaybackControl>(); for (int actorIndex = 0; actorIndex < SubjectRecordings.Length; actorIndex++) { SubjectRecording subject = SubjectRecordings[actorIndex]; GameObject actorRepresentation = null; Actor actor = null; if (actorBuilder != null) { actor = actorBuilder.Build(subject.SubjectID, subject.SubjectName, subject.Metadata); actorRepresentation = actor == null ? null : actor.Representation; } else { actorRepresentation = GameObject.CreatePrimitive(PrimitiveType.Cube); } if (actorRepresentation != null) { actorRepresentation.transform.SetParent(parent); actorRepresentation.transform.name = subject.SubjectName; actorRepresentation.transform.position = subject.GetStartingPosition(); actorRepresentation.transform.rotation = subject.GetStartingRotation(); actors.Add(new ActorPlaybackControl(actorRepresentation, actor == null ? null : actor.CustomEventHandler, this, subject)); } } return(actors.ToArray()); }
public PlaybackStateInfo(Recording recording, IActorBuilder actorBuilder, IPlaybackCustomEventHandler eventHandler, Transform actorsParent, bool loop) { this.recording = recording; this.actorBuilder = actorBuilder; this.eventHandler = eventHandler; this.actorsParent = actorsParent; this.loop = loop; playbackSpeed = 1; }
/// <summary> /// Creates an empty GameObject and attatches an instance of the PlaybackBehavior to it. /// </summary> /// <param name="recording">The recording to playback.</param> /// <param name="actorBuilder">What is used to build the actors.</param> /// <param name="onEvent">What to call when an event occurs.</param> /// <param name="loop">Whether or not for the recoding playback to start over when it reaches the end.</param> /// <returns></returns> public static PlaybackBehavior Build(Recording recording, IActorBuilder actorBuilder, IPlaybackCustomEventHandler onEvent, bool loop) { PlaybackBehavior playbackBehavior = new GameObject("PLAYBACK OBJECT").AddComponent <PlaybackBehavior>(); playbackBehavior.stateInfo = new PlaybackStateInfo(recording, actorBuilder, onEvent, playbackBehavior.transform, loop); playbackBehavior.currentPlaybackState = new StoppedPlaybackState(playbackBehavior.stateInfo); return(playbackBehavior); }