public static void PlotPlay(List <CameraInfo> clipsID) { if (isPlaying == false) { plotClips = clipsID; plotClipNum = 0; CutsceneClip first = Cutscene.PlayClip(plotClips[plotClipNum].cameraId); TalkId_cut[plotClips[plotClipNum].talkId] = first; // TalkId_cut.Add(plotClips[plotClipNum].talkId, first); first.onArriveAtEnding.AddListener(PlotNextPlay); isPlaying = true; if (Pathea.PeCreature.Instance.mainPlayer != null) { Pathea.PeCreature.Instance.mainPlayer.motionMgr.DoAction(Pathea.PEActionType.Cutscene); //Pathea.PeEntityExt.PeEntityExt.SetInvincible(Pathea.PeCreature.Instance.mainPlayer, true); Pathea.PESkEntity skentity = Pathea.PeCreature.Instance.mainPlayer.peSkEntity; skentity.SetAttribute(Pathea.AttribType.CampID, 28); skentity.SetAttribute(Pathea.AttribType.DamageID, 28); } } else { plotClips.AddRange(clipsID); } }
public static CutsceneClip PlayClip(int id) { if (paths.ContainsKey(id)) { GameObject res = Resources.Load(paths[id]) as GameObject; GameObject go = GameObject.Instantiate(res) as GameObject; go.name = res.name; go.transform.position = res.transform.position; go.transform.rotation = res.transform.rotation; CutsceneClip clip = go.GetComponent <CutsceneClip>(); clip.isEditMode = false; return(clip); } return(null); }
/// <summary> /// Splits a clip into two separate ones at the specified time. /// </summary> /// <param name="splitPoint">The time at which to split the clip.</param> /// <param name="track">The track the clip is sitting on.</param> /// <param name="clip">The clip to split.</param> /// <returns>The new clip.</returns> public static CutsceneClip SplitClipAtTime(float splitPoint, CutsceneTrack track, CutsceneClip clip) { CutsceneClip newClip = clip.GetCopy(); // Make sure the clip actually spans over the split point if (splitPoint < clip.timelineStart || splitPoint > clip.timelineStart + clip.duration) { EDebug.Log("Cutscene Editor: cannot split clip; clip does not contain the split point"); return null; } clip.SetOutPoint(clip.inPoint + (splitPoint - clip.timelineStart)); newClip.SetInPoint(clip.outPoint); newClip.SetTimelineStart(splitPoint); track.clips.Add(newClip); Event.current.Use(); EDebug.Log("Cutscene Editor: splitting clip at time " + splitPoint); return newClip; }
private static void PlotNextPlay() { plotClipNum++; if (plotClipNum < plotClips.Count) { CutsceneClip notFirst = Cutscene.PlayClip(plotClips[plotClipNum].cameraId); TalkId_cut[plotClips[plotClipNum].talkId] = notFirst; //TalkId_cut.Add(plotClips[plotClipNum].talkId, notFirst); notFirst.onArriveAtEnding.AddListener(PlotNextPlay); } else { if (Pathea.PeCreature.Instance.mainPlayer != null) { Pathea.PeCreature.Instance.mainPlayer.motionMgr.EndAction(Pathea.PEActionType.Cutscene); //Pathea.PeEntityExt.PeEntityExt.SetInvincible(Pathea.PeCreature.Instance.mainPlayer, false); Pathea.PESkEntity skentity = Pathea.PeCreature.Instance.mainPlayer.peSkEntity; skentity.SetAttribute(Pathea.AttribType.CampID, 1); skentity.SetAttribute(Pathea.AttribType.DamageID, 1); } plotClipNum = 0; TalkId_cut.Clear(); isPlaying = false; } }
/// <summary> /// Called when the clip type is unknown. /// </summary> /// <remarks>For debugging only; ideally this will never be called.</remarks> void UnknownFunction(CutsceneClip clip) { EDebug.Log("Cutscene: unknown function call from clip " + clip.name); }
/// <summary> /// Displays the specified subtitle. /// </summary> /// <param name="clip">The subtitle to display.</summary> void PlaySubtitle(CutsceneClip clip) { currentSubtitle = (CutsceneSubtitle)clip.master; EDebug.Log("Displaying subtitle " + clip.name + " at " + animation["master"].time); StartCoroutine(StopSubtitle(clip.duration)); }
/// <summary> /// Shows the specified shot. /// </summary> /// <param name="clip">The shot to show.</summary> void PlayShot(CutsceneClip clip) { Camera cam = ((CutsceneShot)clip.master).camera; cam.enabled = true; StartCoroutine(StopShot(cam, clip.duration)); EDebug.Log("Cutscene: showing camera " + clip.name + " at " + animation["master"].time); }
/// <summary> /// Plays the specified audio. /// </summary> /// <param name="clip">The audio to play.</summary> void PlayAudio(CutsceneClip clip) { AudioSource aud = ((CutsceneAudio)clip.master).audio; aud.Play(); aud.time = clip.inPoint; // Set the point at which the clip plays StartCoroutine(StopAudio(aud, clip.duration)); // Set the point at which the clip stops EDebug.Log("Playing audio " + clip.name + " at " + animation["master"].time); }
/// <summary> /// Plays the specified actor. /// </summary> /// <param name="clip">The actor to play.</summary> void PlayActor(CutsceneClip clip) { CutsceneActor actor = ((CutsceneActor)clip.master); AnimationClip anim = actor.anim; GameObject go = ((CutsceneActor)clip.master).go; go.animation[anim.name].time = clip.inPoint; go.animation.Play(anim.name); StartCoroutine(StopActor(actor, clip.duration)); EDebug.Log("Cutscene: showing actor " + clip.name + " at " + animation["master"].time); }
/// <summary> /// Checks to see if there's a clip at the given time, ignoring the given clip. /// </summary> /// <param name="time">The time to check for.</param> /// <returns>The CutsceneClip that is at the given time.</returns> public CutsceneClip ContainsClipAtTime(float time, CutsceneClip ignoreClip) { CutsceneClip contains = ContainsClipAtTime(time); if (contains != null && contains != ignoreClip) { return contains; } else { return null; } }
/// <summary> /// Gets a clone of the current clip. /// </summary> /// <returns>The clip copy.</returns> public CutsceneClip GetCopy() { CutsceneClip copy = new CutsceneClip(master); copy.timelineStart = timelineStart; copy.SetInPoint(inPoint); copy.outPoint = outPoint; return copy; }
/// <summary> /// Inserts the given cutscene object into the timeline. /// </summary> /// <param name="obj">The cutscene object to insert.</param> void Insert(CutsceneMedia obj) { CutsceneClip newClip = new CutsceneClip(obj); newClip.timelineStart = ed.scene.playhead; // If there are no existing tracks, add a new one if (ed.scene.tracks.Length == 0) { ed.scene.AddTrack(newClip.type); } // Manage overlap with other clips CutsceneClip existingClip = ed.selectedTrack.ContainsClipAtTime(ed.scene.playhead); if (existingClip != null) { CutsceneClip middleOfSplit = CutsceneTimeline.SplitClipAtTime(ed.scene.playhead, ed.selectedTrack, existingClip); CutsceneTimeline.SplitClipAtTime(ed.scene.playhead + newClip.duration, ed.selectedTrack, middleOfSplit); ed.selectedTrack.clips.Remove(middleOfSplit); } ed.selectedTrack.clips.Add(newClip); EDebug.Log("Cutscene Editor: inserting " + newClip.name + " into timeline " + ed.selectedTrack + " at " + ed.scene.playhead); }
/// <summary> /// Splits a clip into two separate ones. /// </summary> /// <param name="track">The track the clip is sitting on.</param> /// <param name="clip">The clip to split.</param> /// <param name="mousePosition">The position of the mouse when the split operation occurred.</param> /// <returns>The new clip.</returns> CutsceneClip SplitClip(CutsceneTrack track, CutsceneClip clip, Vector2 mousePosition) { float splitPoint = mousePosition.x / ed.timelineZoom; return CutsceneTimeline.SplitClipAtTime(splitPoint, track, clip); }
/// <summary> /// Displays a clip. /// </summary> /// <param name="trackRect">The Rect of the track the clip sits on.</param> /// <param name="track">The track the clip sits on.</param> /// <param name="clip">The clip to display.</param> void DisplayClip(Rect trackRect, CutsceneTrack track, CutsceneClip clip) { const float trimWidth = 5f; GUIStyle clipStyle = ed.style.GetStyle("Selected Clip"); // Set the clip style if this isn't the selected clip (selected clips all share the same style) if (clip != ed.selectedClip) { switch (clip.type) { case Cutscene.MediaType.Shots: clipStyle = ed.style.GetStyle("Shot Clip"); break; case Cutscene.MediaType.Actors: clipStyle = ed.style.GetStyle("Actor Clip"); break; case Cutscene.MediaType.Audio: clipStyle = ed.style.GetStyle("Audio Clip"); break; default: // Cutscene.MediaType.Subtitles clipStyle = ed.style.GetStyle("Subtitle Clip"); break; } } Rect rect = new Rect((trackRect.x + clip.timelineStart) * ed.timelineZoom, trackRect.y + 1, clip.duration * ed.timelineZoom, clipStyle.fixedHeight); GUI.BeginGroup(rect, clipStyle); GUIContent clipLabel = new GUIContent(clip.name, "Clip: " + clip.name + "\nDuration: " + clip.duration + "\nTimeline start: " + clip.timelineStart + "\nTimeline end: " + (clip.timelineStart + clip.duration)); Rect clipLabelRect = new Rect(clipStyle.contentOffset.x, 0, rect.width - clipStyle.contentOffset.x, rect.height); GUI.Label(clipLabelRect, clipLabel); GUI.EndGroup(); // Handle mouse clicks Vector2 mousePos = Event.current.mousePosition; if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition)) { switch (Event.current.button) { case 0: // Left mouse button ed.selectedClip = clip; ed.selectedTrack = track; break; case 1: // Right mouse button EditorUtility.DisplayPopupMenu(new Rect(mousePos.x, mousePos.y, 0, 0), "CONTEXT/CutsceneClip/", new MenuCommand(clip)); Event.current.Use(); break; default: break; } } if (clip.setToDelete) { ed.selectedTrack.clips.Remove(clip); return; } // Don't allow actions to be performed on the clip if the track is disabled or locked if (!track.enabled || track.locked) { return; } switch (ed.currentTool) { case Tool.MoveResize: // Define edit areas, adding custom cursors when hovered over // Move Rect move = new Rect(rect.x + trimWidth, rect.y, rect.width - (2 * trimWidth), rect.height); EditorGUIUtility.AddCursorRect(move, MouseCursor.SlideArrow); // Resize left Rect resizeLeft = new Rect(rect.x, rect.y, trimWidth, rect.height); EditorGUIUtility.AddCursorRect(resizeLeft, MouseCursor.ResizeHorizontal); // Resize right Rect resizeRight = new Rect(rect.xMax - trimWidth, rect.y, trimWidth, rect.height); EditorGUIUtility.AddCursorRect(resizeRight, MouseCursor.ResizeHorizontal); if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition)) { ed.dragClip = clip; // Move if (move.Contains(Event.current.mousePosition)) { ed.dragEvent = DragEvent.Move; EDebug.Log("Cutscene Editor: starting clip move"); // Resize left } else if (resizeLeft.Contains(Event.current.mousePosition)) { ed.dragEvent = DragEvent.ResizeLeft; EDebug.Log("Cutscene Editor: starting clip resize left"); // Resize right } else if (resizeRight.Contains(Event.current.mousePosition)) { ed.dragEvent = DragEvent.ResizeRight; EDebug.Log("Cutscene Editor: starting clip resize right"); } Event.current.Use(); } else if (Event.current.type == EventType.MouseDrag && ed.dragClip == clip) { float shift = Event.current.delta.x / ed.timelineZoom; switch (ed.dragEvent) { case DragEvent.Move: float newPos = clip.timelineStart + shift; // Left collisions CutsceneClip leftCollision = track.ContainsClipAtTime(newPos, clip); if (leftCollision != null) { newPos = leftCollision.timelineStart + leftCollision.duration; } // Right collisions CutsceneClip rightCollision = track.ContainsClipAtTime(newPos + clip.duration, clip); if (rightCollision != null) { newPos = rightCollision.timelineStart - clip.duration; } if (newPos + clip.duration > ed.scene.duration) { newPos = ed.scene.duration - clip.duration; } clip.SetTimelineStart(newPos); break; case DragEvent.ResizeLeft: clip.SetTimelineStart(clip.timelineStart + shift); clip.SetInPoint(clip.inPoint + shift); // TODO Improve collision behaviour CutsceneClip leftResizeCollision = track.ContainsClipAtTime(clip.timelineStart, clip); if (leftResizeCollision != null) { clip.SetTimelineStart(leftResizeCollision.timelineStart + leftResizeCollision.duration); } break; case DragEvent.ResizeRight: float newOut = clip.outPoint + shift; // Right collisions CutsceneClip rightResizeCollision = track.ContainsClipAtTime(clip.timelineStart + clip.duration + shift, clip); if (rightResizeCollision != null) { newOut = rightResizeCollision.timelineStart - clip.timelineStart + clip.inPoint; } clip.SetOutPoint(newOut); break; default: break; } Event.current.Use(); } else if (Event.current.type == EventType.MouseUp) { ed.dragClip = null; Event.current.Use(); } break; case Tool.Scissors: // TODO Switch to something better than the text cursor, if possible EditorGUIUtility.AddCursorRect(rect, MouseCursor.Text); if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition)) { SplitClip(track, clip, Event.current.mousePosition); Event.current.Use(); } break; default: break; } }
/// <summary> /// Deletes a clip. /// </summary> /// <param name="clip">The clip to delete.</param> /// <returns>True if the clip was successfully deleted, false otherwise.</returns> static bool DeleteClip(CutsceneClip clip) { bool delete = true; // Display a dialog to prevent accidental deletions if (EditorPrefs.GetBool("Cutscene Warn Before Delete", true)) { delete = EditorUtility.DisplayDialog("Delete Clip", "Are you sure you wish to delete this clip? Changes cannot be undone.", "Delete", "Cancel"); } clip.setToDelete = delete; return delete; }