public override void OnPreviewSettings() { //GUILayout.FlexibleSpace(); if (isPlaying) { if (GUILayout.Button(pauseIcon, (GUIStyle)"PreButton", GUILayout.Width(50))) { isPlaying = false; if (lsdTarget.clip) { AudioUtility.PauseClip(lsdTarget.clip); } } } else { if (GUILayout.Button(playIcon, (GUIStyle)"PreButton", GUILayout.Width(50))) { isPlaying = true; if (lsdTarget.clip) { AudioUtility.PlayClip(lsdTarget.clip); } } } if (GUILayout.Button(stopIcon, (GUIStyle)"PreButton", GUILayout.Width(50))) { isPlaying = false; seekPosition = 0; oldSeekPosition = 0; if (lsdTarget.clip) { AudioUtility.StopClip(lsdTarget.clip); } } GUILayout.Space(25); bool newPreviewState = GUILayout.Toggle(visualPreview, new GUIContent(previewIcon, "Preview Animation"), (GUIStyle)"PreButton", GUILayout.Width(50)); if (visualPreview != newPreviewState) { GenericMenu previewMenu = new GenericMenu(); previewMenu.AddDisabledItem(new GUIContent("Choose a target")); LipSync[] targets = GameObject.FindObjectsOfType <LipSync>(); previewMenu.AddItem(new GUIContent("No Preview"), !visualPreview, TargetChosen, null); foreach (LipSync t in targets) { previewMenu.AddItem(new GUIContent(t.name), previewTarget == t ? true : false, TargetChosen, t); } previewMenu.ShowAsContext(); } }
private void DrawTimeLineMenu() { GUILayout.BeginHorizontal(); // Choose file music. GUILayout.Label("File:"); this.m_SoundAudio = (AudioClip)EditorGUILayout.ObjectField(this.m_SoundAudio, typeof(AudioClip)); if (this.m_PreviousAudio != this.m_SoundAudio) { this.m_DictNodeData.Clear(); this.m_PreviousAudio = this.m_SoundAudio; this.m_CurrentSelectedNode = null; } // GUILayout.FlexibleSpace (); // Choose sound file GUILayout.Label(this.m_SoundAudio == null ? "Please choose file audio clip." : "You select file: " + this.m_SoundAudio.name); // Play sound if (GUILayout.Button("Play >>")) { if (this.m_SoundAudio != null) { AudioUtility.PlayClip(this.m_SoundAudio); this.m_PreviousAudio = this.m_SoundAudio; this.m_IsPlaying = true; this.m_IsPause = false; this.m_IsPlayingReview = false; this.m_IsPauseReview = false; } } // Pause or resume sound if (this.m_IsPause == false) { if (GUILayout.Button("Pause ||")) { if (this.m_SoundAudio != null) { AudioUtility.PauseClip(this.m_SoundAudio); this.m_IsPause = true; } } } else { if (GUILayout.Button("Resume ||")) { if (this.m_SoundAudio != null) { AudioUtility.ResumeClip(this.m_SoundAudio); this.m_IsPause = false; } } } GUILayout.EndHorizontal(); }
private bool ToggleClip() { _isPlaying = !_isPlaying; if (_isPlaying) { if (_currentSample == 0) { AudioUtility.PlayClip(audioClip, 0, _isLooping); } else { ResumeClip(); } } else { _currentSample = AudioUtility.GetClipSamplePosition(audioClip); AudioUtility.PauseClip(audioClip); } return(_isPlaying); }
private void DrawKeyframeMenu() { GUILayout.BeginHorizontal(); if (GUILayout.Button("Add keyframe") && this.m_IsPlayingReview == false) { var nodeTimelineIndex = (int)this.m_SoundTimeLine; var keyName = "Keyframe_" + nodeTimelineIndex; // Create new node var nodeData = CreateNewNode(nodeTimelineIndex); if (this.m_DictNodeData.ContainsKey(keyName)) { // Add new key node in key frame this.m_DictNodeData [keyName].Add(nodeData); } else { // Create new key frame this.m_DictNodeData.Add(keyName, new List <CNodeEditorData> ()); // Add new key node in key frame this.m_DictNodeData [keyName].Add(nodeData); } var listNode = this.m_DictNodeData [keyName]; nodeData.editorIndex = listNode.Count - 1; this.m_CurrentSelectKeyframe = keyName; } if (GUILayout.Button("Delete keyframe") && this.m_IsPlayingReview == false) { if (string.IsNullOrEmpty(this.m_CurrentSelectKeyframe) == false) { if (this.m_DictNodeData.ContainsKey(this.m_CurrentSelectKeyframe)) { this.m_DictNodeData [this.m_CurrentSelectKeyframe].Clear(); this.m_DictNodeData.Remove(this.m_CurrentSelectKeyframe); this.m_CurrentSelectKeyframe = string.Empty; this.m_CurrentSelectedNode = null; } } } if (GUILayout.Button("Copy keyframe")) { if (string.IsNullOrEmpty(this.m_CurrentSelectKeyframe) == false) { if (this.m_DictNodeData.ContainsKey(this.m_CurrentSelectKeyframe)) { var keyframes = this.m_DictNodeData [this.m_CurrentSelectKeyframe]; this.m_CurrentTargetKeyframe = keyframes; } } } if (GUILayout.Button("Paste keyframe")) { if (this.m_CurrentTargetKeyframe != null && this.m_CurrentTargetKeyframe.Count > 0) { var nodeTimelineIndex = (int)this.m_SoundTimeLine; var keyName = "Keyframe_" + nodeTimelineIndex; if (this.m_DictNodeData.ContainsKey(keyName)) { // TODO } else { // Create new key frame this.m_DictNodeData.Add(keyName, new List <CNodeEditorData> ()); } for (int i = 0; i < this.m_CurrentTargetKeyframe.Count; i++) { var tmpNode = this.m_CurrentTargetKeyframe [i]; var newNode = new CNodeEditorData(); newNode.audioTime = nodeTimelineIndex; newNode.nodeType = tmpNode.nodeType; newNode.nodePosition = tmpNode.nodePosition; newNode.nodeScale = tmpNode.nodeScale; this.m_DictNodeData [keyName].Add(newNode); newNode.editorIndex = this.m_DictNodeData [keyName].Count - 1; newNode.editorNodePosition = newNode.nodePosition.ToVector2(); } this.m_CurrentSelectKeyframe = keyName; } } GUILayout.FlexibleSpace(); if (GUILayout.Button(this.m_IsPlayingReview == false ? "Play review" : "Stop review")) { this.m_CurrentSelectKeyframe = string.Empty; this.m_CurrentSelectedNode = null; this.m_IsPlaying = false; this.m_IsPause = false; this.m_IsPlayingReview = !this.m_IsPlayingReview; this.m_IsPauseReview = false; if (this.m_IsPlayingReview) { AudioUtility.StopAllClips(); AudioUtility.PlayClip(this.m_SoundAudio); } else { AudioUtility.StopClip(this.m_SoundAudio); } } if (GUILayout.Button(this.m_IsPauseReview == false ? "Pause review" : "Resume review") && this.m_IsPlayingReview) { this.m_IsPauseReview = !this.m_IsPauseReview; if (this.m_IsPauseReview) { AudioUtility.PauseClip(this.m_SoundAudio); } else { AudioUtility.ResumeClip(this.m_SoundAudio); } } GUILayout.EndHorizontal(); }
void Update() { float deltaTime = Time.realtimeSinceStartup - prevTime; prevTime = Time.realtimeSinceStartup; if (seekPosition != oldSeekPosition) { oldSeekPosition = seekPosition; if (!isPlaying) { if (!previewing && lsdTarget.clip != null) { AudioUtility.PlayClip(lsdTarget.clip); } previewing = true; stopTimer = 0.1f; prevTime = Time.realtimeSinceStartup; resetTime = seekPosition; } if (lsdTarget.clip) { AudioUtility.SetClipSamplePosition(lsdTarget.clip, (int)(seekPosition * AudioUtility.GetSampleCount(lsdTarget.clip))); } } if (previewing) { stopTimer -= deltaTime; if (lsdTarget.clip) { seekPosition = AudioUtility.GetClipPosition(lsdTarget.clip) / lsdTarget.length; oldSeekPosition = seekPosition; } if (stopTimer <= 0) { previewing = false; seekPosition = resetTime; oldSeekPosition = seekPosition; if (lsdTarget.clip != null) { AudioUtility.PauseClip(lsdTarget.clip); AudioUtility.SetClipSamplePosition(lsdTarget.clip, (int)(seekPosition * AudioUtility.GetSampleCount(lsdTarget.clip))); } } } if (isPlaying && lsdTarget.clip == null) { seekPosition += deltaTime / lsdTarget.length; oldSeekPosition = seekPosition; if (seekPosition >= 1) { isPlaying = false; seekPosition = 0; } } else if (isPlaying) { seekPosition = AudioUtility.GetClipPosition(lsdTarget.clip) / lsdTarget.length; oldSeekPosition = seekPosition; isPlaying = AudioUtility.IsClipPlaying(lsdTarget.clip); } if (isPlaying && visualPreview || previewing && visualPreview) { UpdatePreview(seekPosition); } }
private void PauseClip() { AudioUtility.PauseClip(audioClip); }