void Initialise() { if (mode == LoopMode.SingleClip) { clip = AAE_Clip.GetComponent <AAEClip> (); if (clip == null) { Debug.LogError("AAE MusicLooper: ERROR! It seems you've forgotten to drag in your clip of choice in the 'AAE_File' slot!"); } } else if (mode == LoopMode.Playlist) { origName = Playlist.name; Playlist = (GameObject)Instantiate(Playlist, transform.position, Quaternion.identity); Playlist.name = origName; Playlist.transform.parent = this.transform; playlist = Playlist.GetComponent <AAEMusicPlaylist> (); if (playlist == null) { Debug.LogError("AAE MusicLooper: ERROR! It seems you've forgotten to drag in your playlist of choice in the 'Playlist' slot!"); } } oldVolume = 1; if (startOnPlay) { Play(); } }
void Start() { origName = transform.name; audioSource = gameObject.GetComponent <AudioSource> (); if (audioSource == null) { audioSource = gameObject.AddComponent <AudioSource> (); } if (file == null) { Debug.LogWarning("AAEInstance: ERROR! No file! ARRGGHHHH!"); } else { clip = file.GetComponent <AAEClip> (); } // audioSource.playOnAwake = true; audioSource.clip = clip.clip; if (clip.playPreEntry) { audioSource.Play(); } else { audioSource.timeSamples = (int)clip.preEntry; audioSource.Play(); } looper.BPM = clip.BPM; }
void Save() { GameObject go = new GameObject(saveName); //create a new gameobject with the chosen name AAEClip a = go.AddComponent <AAEClip>(); //add the AAE Clip component a.clip = currentFile.clip; //from here we just save the values as the user has edited them in the editor window a.preEntry = currentFile.preEntry; a.postExit = currentFile.postExit; a.preview = currentFile.preview; a.BPM = currentFile.BPM; a.Step = currentFile.Step; a.Base = currentFile.Base; PrefabUtility.CreatePrefab(userSavePath + "/" + saveName + ".prefab", go); //this line creates the prefab AssetDatabase.SaveAssets(); // actually save what we've created AssetDatabase.Refresh(); // refresh to update the project view DestroyImmediate(go); //destroy the temporary object so it's not added to the current scene userSavePath = oldSavePath; //revert the save path }
public override void OnInspectorGUI() { AAEClip clip = (AAEClip)target; clip.clip = (AudioClip)EditorGUILayout.ObjectField("Clip", clip.clip, typeof(AudioClip), true); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("BPM: ", EditorStyles.boldLabel, GUILayout.MaxWidth(Screen.width / 2)); EditorGUILayout.LabelField(clip.BPM.ToString(), GUILayout.MaxWidth(50)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Time Signature: ", EditorStyles.boldLabel, GUILayout.MaxWidth(Screen.width / 2)); EditorGUILayout.LabelField(clip.Step.ToString() + "/" + clip.Base.ToString(), GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); clip.playPreEntry = EditorGUILayout.Toggle("Play Pre-Entry", clip.playPreEntry); clip.playPostExit = EditorGUILayout.Toggle("Play Post-Exit", clip.playPostExit); }
private void DropAreaGUI() //this is the 'opening' screen that is displayed when the user has not yet dropped an audio or AAE clip into the window { Repaint(); var e = Event.current; //I used var here because this part was the first that I made, and I took inspiration from a tutorial i found online, and cared more about getting something to work rather than having full code consistensy var dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); //define the area that the user can drop stuff in //GUI.Box (dropArea, "DROP AUDIO HERE", EditorStyles.centeredGreyMiniLabel); GUI.DrawTexture(new Rect(position.width / 4, position.height / 10, position.width / 2, Mathf.Clamp(position.width / 2, 0, 200)), AssetDatabase.LoadAssetAtPath <Texture> ("Assets/AAE/DROP.png"), ScaleMode.ScaleToFit); //load and display the graphics I made //LOGO Texture logo = AssetDatabase.LoadAssetAtPath <Texture> ("Assets/AAE/MFYGSticker.png"); //this is my logo! Wuhu! // float xPlace = position.width/2 - logo.width / 2; Rect logoRect = new Rect((position.width / 6) * 1.5f, (position.height / 3) * 1.7f, position.width / 2, 200); //where the logo will be placed GUI.DrawTexture(logoRect, logo, ScaleMode.ScaleToFit); if (Event.current.type == EventType.mouseDown && logoRect.Contains(Event.current.mousePosition)) //if the logo is pressed I'll let the sweet user have a look at my website :b { Application.OpenURL("http://musicforyourgame.com"); //this just opens their default browser and directs it to the webpage } GUIStyle link = GUI.skin.GetStyle("Label"); //make a GIVE FEEDBACK link because if people use it I'd like to have some feedback if they have any to share! link.normal.textColor = Color.blue; link.fontSize = 12; link.fontStyle = FontStyle.Bold; Rect feedbackRect = new Rect(position.width - 100, position.height - 20, 100, 50); EditorGUI.LabelField(feedbackRect, "GIVE FEEDBACK", link); if (feedbackRect.Contains(Event.current.mousePosition)) { EditorGUI.DrawRect(new Rect(feedbackRect.x, feedbackRect.y + 15, feedbackRect.width - 3, 1), Color.blue); } if (Event.current.type == EventType.mouseDown && feedbackRect.Contains(Event.current.mousePosition)) { Application.OpenURL("http://goo.gl/forms/KZH7Lq9ibQExSUbq1"); //LINK TO FEEDBACK DOCUMENT GOES HERE } //handle all the drag & drop events switch (e.type) //a switch between the type of drag actions { case EventType.dragUpdated: case EventType.dragPerform: //if the user is holding the object over the drag zone if (!dropArea.Contains(e.mousePosition)) //check if the mouse is not in the drop area { break; //in that case do nothing } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; //change the cursor to the one with the plus to indicate that they can actually drop something if (e.type == EventType.dragPerform) //so if they release { DragAndDrop.AcceptDrag(); loop = false; if (DragAndDrop.objectReferences [0].GetType() == typeof(AudioClip)) //AUDIO CLIP FOUND! { foreach (AudioClip draggedObject in DragAndDrop.objectReferences) { //This is where you add the audioclip! string objPath = AssetDatabase.GetAssetPath(draggedObject); currentFile = new AAEFile(); //make a new AAEFile as the temporary file currentFile.clip = (AudioClip)AssetDatabase.LoadAssetAtPath <AudioClip> (objPath); //do a lot of initialisation from here currentFile.postExit = currentFile.clip.samples; currentFile.preEntry = 0; ////AssetPreview.SetPreviewTextureCacheSize (2); while (currentFile.preview == null) //attempt loading the preview for a while as it can fail the first time without giving any warning { currentFile.preview = AssetPreview.GetAssetPreview(currentFile.clip); System.Threading.Thread.Sleep(15); } if (currentFile.preview != null) //if it's successfully loaded then change the filtering mode since we don't want a blurry ass image { currentFile.preview.filterMode = FilterMode.Point; // } saveName = currentFile.clip.name + "_AAE"; } } else if (DragAndDrop.objectReferences [0].GetType() == typeof(GameObject)) //GAMEOBJECT FOUND { foreach (GameObject draggedObject in DragAndDrop.objectReferences) { if (draggedObject.GetComponent <AAEClip> () != null) //check if the gameobject contains an AAE Clip component (which means it was previously saved) { AAEClip a = draggedObject.GetComponent <AAEClip>(); //if it does, then initialise the temporary AAE File with the saved information currentFile = new AAEFile(); currentFile.clip = a.clip; currentFile.postExit = a.postExit; currentFile.preEntry = a.preEntry; currentFile.BPM = a.BPM; currentFile.Step = a.Step; currentFile.Base = a.Base; while (currentFile.preview == null) //and load the according preview { currentFile.preview = AssetPreview.GetAssetPreview(currentFile.clip); System.Threading.Thread.Sleep(15); } if (currentFile.preview != null) { currentFile.preview.filterMode = FilterMode.Point; //pls no blur } saveName = currentFile.clip.name + "_AAE"; } else { Debug.LogError("AAE error: Please drop a previously saved AAE Clip or an AudioClip!"); //throw a logerror if the user has dropped something that is not an audioclip or contains an AAE Clip component } } } DragAndDrop.activeControlID = 0; } Event.current.Use(); //actually use the event so we don't do the same thing a lot of times break; } }