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 PlayClip(int?samplePosition = null) { if (samplePosition == null) { AudioUtility.PlayClip(audioClip, 0, _isLooping); } else { AudioUtility.PlayClip(audioClip, samplePosition.Value, _isLooping); } }
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 static void Init() { var window = CreateInstance <BURAKURA>(); window.Show(); window.position = new Rect(Random.Range(0, 1000), Random.Range(0, 600), 500, 275); tex1 = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePath1); tex2 = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePath2); audioClip = Resources.Load <AudioClip>("bgm1"); AudioUtility.PlayClip(audioClip, 0, true); }
public static void SwitchEditorSkin() { System.Reflection.Assembly.GetAssembly(typeof(UnityEditorInternal.AssetStore)) .GetType("UnityEditorInternal.InternalEditorUtility", true).GetMethod("SwitchSkinAndRepaintAllViews") ?.Invoke(null, null); EditorPrefs.SetInt(Constant.Constant.EditorPrefsKey.EditorSkin, EditorPrefs.GetInt(Constant.Constant.EditorPrefsKey.EditorSkin) == 0 ? 1 : 0); var switchSkinSound = AssetDatabase.LoadAssetAtPath <AudioClip>(CurrentSkinType == EditorSkinType.Dark ? Constant.Constant.AssetPath.NightOwlDarkAudio : Constant.Constant.AssetPath.NightOwlLightAudio); if (switchSkinSound && !AudioUtility.IsClipPlaying(switchSkinSound)) { AudioUtility.PlayClip(switchSkinSound); } }
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(); }
public override void OnInspectorGUI() { currentWidth = EditorGUIUtility.currentViewWidth; EditorGUILayout.Space(); EditorGUILayout.LabelField("【Volume】"); EditorGUILayout.Slider(m_volumeTotalProp, 0.0f, 1.0f, "Total"); EditorGUILayout.Slider(m_volumeSeProp, 0.0f, 1.0f, "SE"); EditorGUILayout.Slider(m_volumeBgmProp, 0.0f, 1.0f, "BGM"); EditorGUILayout.Space(); EditorGUILayout.LabelField("【AudioMixerGroup】"); EditorGUILayout.PropertyField(m_seAudioMixerGroupProp); EditorGUILayout.PropertyField(m_bgmAudioMixerGroupProp); EditorGUILayout.Space(); EditorGUILayout.LabelField("【Other】"); EditorGUILayout.PropertyField(m_isChangeToSaveProp); EditorGUILayout.PropertyField(m_isChangeSceneToStopSeProp); m_sePlayerNumProp.intValue = EditorGUILayout.IntField("SE PlayerCount", m_sePlayerNumProp.intValue); EditorGUILayout.Space(); EditorGUILayout.LabelField("【SoundList】"); m_editorIsFoldSeListProp.boolValue = EditorGUILayout.Foldout(m_editorIsFoldSeListProp.boolValue, " SE", true); if (!m_editorIsFoldSeListProp.boolValue) { EditorGUILayout.BeginVertical(GUI.skin.box); if (m_audioClipListSeProp.arraySize == 0) { EditorGUILayout.LabelField("None"); } else { for (int i = 0; i < m_audioClipListSeProp.arraySize; i++) { var p = m_audioClipListSeProp.GetArrayElementAtIndex(i); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField((i + 1).ToString("00") + ".", GUILayout.Width(20)); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(p.objectReferenceValue, typeof(AudioClip), false); EditorGUI.EndDisabledGroup(); var clip = (AudioClip)p.objectReferenceValue; var timeSpan = System.TimeSpan.FromSeconds(clip.length); EditorGUILayout.LabelField(timeSpan.Minutes.ToString("00") + ":" + timeSpan.Seconds.ToString("00"), GUILayout.Width(40)); //Editor上で再生できる様に修正 if (GUILayout.Button("Play")) { AudioUtility.StopAllClips(); AudioUtility.PlayClip((AudioClip)p.objectReferenceValue); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); } m_editorIsFoldBgmListProp.boolValue = EditorGUILayout.Foldout(m_editorIsFoldBgmListProp.boolValue, " BGM", true); if (!m_editorIsFoldBgmListProp.boolValue) { EditorGUILayout.BeginVertical(GUI.skin.box); if (m_audioClipListBgmProp.arraySize == 0) { EditorGUILayout.LabelField("None"); } else { for (int i = 0; i < m_audioClipListBgmProp.arraySize; i++) { var p = m_audioClipListBgmProp.GetArrayElementAtIndex(i); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField((i + 1).ToString("00") + ".", GUILayout.Width(20)); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(p.objectReferenceValue, typeof(AudioClip), false); EditorGUI.EndDisabledGroup(); var clip = (AudioClip)p.objectReferenceValue; var timeSpan = System.TimeSpan.FromSeconds(clip.length); EditorGUILayout.LabelField(timeSpan.Minutes.ToString("00") + ":" + timeSpan.Seconds.ToString("00"), GUILayout.Width(40)); //Editor上で再生できる様に修正 if (GUILayout.Button("Play")) { AudioUtility.StopAllClips(); AudioUtility.PlayClip((AudioClip)p.objectReferenceValue); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); } EditorUtility.SetDirty(target); m_serializedObj.ApplyModifiedProperties(); }
private static void Play(SerializedProperty prop, AudioClip clip) { CurrentClip = prop.propertyPath; AudioUtility.PlayClip(clip); }
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); } }