public void RemoveClip(JSoundClipData clipData) { if (!trackClipList.Contains(clipData)) { throw new Exception("Track doesn't contains Clip"); } trackClipList.Remove(clipData); }
public void AddClip(JSoundClipData clipData) { if (trackClipList.Contains(clipData)) { throw new Exception("Track already contains Clip"); } clipData.Track = this; trackClipList.Add(clipData); }
private void RemoveSoundClip(JClipRenderData clip) { var clipdata = clip.ClipData; if (clipdata is JSoundClipData) { JSoundClipData anidata = (JSoundClipData)clipdata; if (timelineClipRenderDataMap.ContainsKey(anidata.Track)) { if (timelineClipRenderDataMap[anidata.Track].Contains(clip)) { timelineClipRenderDataMap[anidata.Track].Remove(clip); } } anidata.Track.RemoveClip(anidata); } }
private void ProcessDraggingSoundClip(JClipRenderData clip, Vector2 mouseDelta) { if (SourcePositions.ContainsKey(clip)) { ScriptableObject selected = clip.ClipData; if (selected is JSoundClipData) { JSoundClipData soundClipData = selected as JSoundClipData; float mousePosOnTimeline = ContentXToTime(mouseDelta.x + FloatingWidth); float newTime = SourcePositions[clip] + mousePosOnTimeline; newTime = Mathf.Clamp(newTime, 0.0f, CurrentSequence.Duration - soundClipData.PlaybackDuration); soundClipData.StartTime = newTime; if (SelectedObjects.Count == 1) { Selection.activeObject = soundClipData; } } } }
private void PlayClip(JSoundClipData clipToPlay, float sequenceTime) { if (sound == null) { return; } if (Sound != null) { if (Sound.clip != clipToPlay.Clip) { Sound.clip = clipToPlay.Clip; } float normalizedTime = (sequenceTime - clipToPlay.StartTime) / clipToPlay.PlaybackDuration; Sound.pitch = Sound.clip.length / clipToPlay.PlaybackDuration; if (clipToPlay.Looping) { normalizedTime = ((sequenceTime - clipToPlay.StartTime) % clipToPlay.PlaybackDuration) / clipToPlay.PlaybackDuration; } normalizedTime = Mathf.Clamp(normalizedTime * Sound.clip.length, 0, Sound.clip.length); if ((Sound.clip.length - normalizedTime) > 0.0001f) { if (Sequence.IsPlaying) { if (!Sound.isPlaying) { Sound.time = normalizedTime; Sound.Play(); } //Sound.time = normalizedTime; } else { Sound.time = normalizedTime; } } } }
private void AddRenderDataForSound(JTimelineBase timeline) { if (timeline is JTimelineSound) { JTimelineSound Soundline = (JTimelineSound)timeline; List <JClipRenderData> list = new List <JClipRenderData>(); for (int k = 0; k < Soundline.SoundTracks.Count; k++) { JSoundTrack track = Soundline.SoundTracks[k]; for (int l = 0; l < track.TrackClips.Count; l++) { JSoundClipData SoundClipData = track.TrackClips[l]; var cachedData = ScriptableObject.CreateInstance <JClipRenderData>(); cachedData.ClipData = SoundClipData; list.Add(cachedData); } if (!timelineClipRenderDataMap.ContainsKey(track)) { timelineClipRenderDataMap.Add(track, list); } } } }
public override void Process(float sequenceTime, float playbackRate) { // if (sound == null) // return; allClips.Clear(); for (int index = 0; index < SoundTracks.Count; index++) { var track = SoundTracks[index]; if (track.Enable) { for (int trackClipIndex = 0; trackClipIndex < track.TrackClips.Count; trackClipIndex++) { var trackClip = track.TrackClips[trackClipIndex]; allClips.Add(trackClip); } } } var totalDeltaTime = sequenceTime - previousTime; var absDeltaTime = Mathf.Abs(totalDeltaTime); var timelinePlayingInReverse = totalDeltaTime < 0.0f; var runningTime = SequenceUpdateRate; var runningTotalTime = previousTime + runningTime; if (timelinePlayingInReverse) { ResetSound(); previousTime = 0.0f; Process(sequenceTime, playbackRate); } else { while (absDeltaTime > 0.0f) { cachedRunningClips.Clear(); for (int allClipIndex = 0; allClipIndex < allClips.Count; allClipIndex++) { var clip = allClips[allClipIndex]; if (!JSoundClipData.IsClipRunning(runningTotalTime, clip) && !clip.Looping) { if (allEffectSoundDict.ContainsKey(clip)) { allEffectSoundDict[clip].Reset(); allEffectSoundDict.Remove(clip); } continue; } cachedRunningClips.Add(clip); } cachedRunningClips.Sort((x, y) => x.StartTime.CompareTo(y.StartTime)); for (int runningClipIndex = 0; runningClipIndex < cachedRunningClips.Count; runningClipIndex++) { var clip = cachedRunningClips[runningClipIndex]; if (!allEffectSoundDict.ContainsKey(clip)) { allEffectSoundDict.Add(clip, new JEffectSound()); List <object> param = new List <object>(); param.Add(AffectedObject.gameObject); param.Add(clip.Clip); param.Add(clip.PlaybackDuration); allEffectSoundDict[clip].SetData(param.ToArray()); allEffectSoundDict[clip].Init(); allEffectSoundDict[clip].OnUpdate(runningTime); } else { allEffectSoundDict[clip].OnUpdate(runningTime); } //PlayClip(clip, runningTotalTime); } absDeltaTime -= SequenceUpdateRate; if (!Mathf.Approximately(absDeltaTime, Mathf.Epsilon) && absDeltaTime < SequenceUpdateRate) { runningTime = absDeltaTime; } runningTotalTime += runningTime; } } previousTime = sequenceTime; }
public static bool IsClipFinished(float sequencerTime, JSoundClipData clipData) { return(sequencerTime >= clipData.EndTime); }
public static bool IsClipRunning(float sequencerTime, JSoundClipData clipData) { return(sequencerTime > clipData.StartTime && sequencerTime < clipData.EndTime); }
private void SoundGUI(JTimelineSound Soundline, JSoundTrack linetrack, JClipRenderData[] renderDataList) { GenericMenu contextMenu = new GenericMenu(); ///event 右键点击 bool isContext = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1; bool isChoose = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1; bool hasBox = false; Rect DisplayAreaTemp = DisplayArea; DisplayAreaTemp.x = 0; DisplayAreaTemp.y = 0; for (int j = 0; j < renderDataList.Length; j++) { JClipRenderData renderdata = renderDataList[j]; JSoundClipData SoundClipData = (JSoundClipData)renderdata.ClipData; JSoundTrack track = SoundClipData.Track; if (linetrack != track) { continue; } var startX = ConvertTimeToXPos(SoundClipData.StartTime); var endX = ConvertTimeToXPos(SoundClipData.StartTime + SoundClipData.PlaybackDuration); var transitionX = ConvertTimeToXPos(SoundClipData.StartTime + SoundClipData.TransitionDuration); var handleWidth = 2.0f; Rect renderRect = new Rect(startX, DisplayArea.y, endX - startX, DisplayArea.height); Rect transitionRect = new Rect(startX, DisplayArea.y, transitionX - startX, DisplayArea.height); Rect leftHandle = new Rect(startX, DisplayArea.y, handleWidth * 2.0f, DisplayArea.height); Rect rightHandle = new Rect(endX - (handleWidth * 2.0f), DisplayArea.y, handleWidth * 2.0f, DisplayArea.height); Rect labelRect = new Rect(); Rect renderRecttemp = renderRect; renderRecttemp.x -= DisplayArea.x; renderRecttemp.y = 0; Rect transitionRecttemp = transitionRect; transitionRecttemp.y = 0; transitionRecttemp.x -= DisplayArea.x; Rect leftHandletemp = leftHandle; leftHandletemp.y = 0; leftHandletemp.x -= DisplayArea.x; Rect rightHandletemp = rightHandle; rightHandletemp.x -= DisplayArea.x; rightHandletemp.y = 0; //GUI.color = new Color(243 / 255.0f, 154 / 255.0f, 0 / 255.0f, 1f); GUI.color = ColorTools.GetGrandientColor((float)renderdata.index / (float)CountClip); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor; } Texture2D texture = AssetPreview.GetAssetPreview(SoundClipData.Clip); if (texture != null) { GUI.DrawTexture(renderRecttemp, texture, ScaleMode.StretchToFill); } else { GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG); } if (SoundClipData.CrossFade) { GUI.Box(transitionRecttemp, ""); } GUI.Box(leftHandletemp, ""); GUI.Box(rightHandletemp, ""); labelRect = renderRecttemp; labelRect.width = DisplayArea.width; renderdata.renderRect = renderRect; renderdata.labelRect = renderRect; renderdata.renderPosition = new Vector2(startX, DisplayArea.y); renderdata.transitionRect = transitionRect; renderdata.leftHandle = leftHandle; renderdata.rightHandle = rightHandle; renderdata.ClipData = SoundClipData; if (SoundClipData.CrossFade) { labelRect.x = labelRect.x + (transitionX - startX); } else { labelRect.x += 4.0f; // Nudge this along a bit so it isn't flush with the side. } GUI.color = Color.black; GUI.Label(labelRect, SoundClipData.FriendlyName); GUI.color = Color.white; if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteClip"), false, (obj) => RemoveSoundClip(((JClipRenderData)((object[])obj)[0])), new object[] { renderdata }); } if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } } if (!hasBox && isChoose && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command)) { //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command //GameObject go = GameObject.Find(Animationline.gameObject.name); Selection.activeGameObject = Soundline.gameObject; EditorGUIUtility.PingObject(Soundline.gameObject); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForSoundTimeLine(Soundline, linetrack); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } // Handle the case where the object picker has a value selected. if (UnityEngine.Event.current.type == EventType.ExecuteCommand && UnityEngine.Event.current.commandName == "ObjectSelectorClosed") { if (EditorGUIUtility.GetObjectPickerControlID() == controlID) { UnityEngine.Object pickedObject = EditorGUIUtility.GetObjectPickerObject(); if (pickedObject != null) { AudioClip clip = (AudioClip)pickedObject; AddNewSoundState((JTimelineSound)savedData.Line, (JSoundTrack)savedData.Track, savedData.Firetime, clip.name, clip); } UnityEngine.Event.current.Use(); } } }