Пример #1
0
    [MenuItem("MUSIC FOR YOUR GAME/Advanced Audio Editor")]                      //make a new tab in the top menu and place it as a subitem!

    static void Init()                                                           //This function is used for initialisation
    {
        AAEWindow window = (AAEWindow)EditorWindow.GetWindow(typeof(AAEWindow)); //get existing open window, or if none, make a new window

        window.Show();
        window.minSize            = new Vector2(400, 510); //set minimum size to prevent the interface f*****g up
        currentFile               = null;                  //Initialise the window without a loaded file
        loopCalled                = false;
        EditorApplication.update += update;                //subscribe the update function in this script to the update function that runs every frame (even outside play mode). This allows us to redraw changes more smoothly
    }
Пример #2
0
    void OnGUI()
    {
        //	MFYG ORANGE BACKGROUND
        texOrange = new Texture2D(1, 1, TextureFormat.RGBA32, false);                                         //convert to 1x1 pixel texture
        texOrange.SetPixel(0, 0, mfygOrange);                                                                 //set the pixel color
        texOrange.Apply();                                                                                    //apply the color change
        GUI.DrawTexture(new Rect(0, 0, position.width, position.height), texOrange, ScaleMode.StretchToFill); //make the texture fill the entire screen

        //  MFYG BLUE BACKGROUND
        if (currentFile != null)
        {
            texBlue = new Texture2D(1, 1, TextureFormat.RGBA32, false);
            texBlue.SetPixel(0, 0, mfygBlue);
            texBlue.Apply();
            GUI.DrawTexture(new Rect(0, 110, position.width, 113), texBlue, ScaleMode.StretchToFill);               //this should only color a certain portion of the screen
        }

        // configure the headline style
        GUIStyle headline = GUI.skin.GetStyle("Label");

        headline.fontSize         = 16;
        headline.alignment        = TextAnchor.UpperCenter;
        headline.fontStyle        = FontStyle.Bold;
        headline.normal.textColor = Color.black;
        // write headline and make some space beneath it
        GUILayout.Label("Advanced Audio Editor", headline);
        EditorGUILayout.Space();

        if (currentFile != null)                         //basically if something has been dragged into the window and a file is succesfully loaded
        {
            clipLength        = currentFile.clip.length; //in seconds
            clipLengthSamples = currentFile.clip.samples;
            beatsPerSec       = (currentFile.BPM / 60f);
            beatsInClip       = clipLength / beatsPerSec * currentFile.Base;

            if (currentFile.preview != null)        //if the preview is succesfully loaded
            {
                GeneralSettings();                  //draw the general settings

                EditorGUILayout.BeginHorizontal();  //start a horizontal section
                //configure settings for the red 'unload' button
                GUI.backgroundColor = new Color(1, 0.5f, 0.5f);
                GUI.contentColor    = Color.white;
                //draw the button and include a tooltip
                if (GUILayout.Button(new GUIContent("Unload music", "Press this button to unload the current clip and return to the drag & drop screen.")))
                {
                    currentFile = null;
                }
                //reset the colors to not affect further things drawn
                GUI.backgroundColor = Color.white;
                GUI.contentColor    = Color.white;

                Saving();                        //draw the saving button and run all the saving code
                EditorGUILayout.EndHorizontal(); //end that section

                GUILayout.Space(20);             //add some space
                MusicDraw();                     //draw the music section
                DrawGrid(beatsInClip);           //draw grid on top of the musicsection (yeah this is perhaps not the best way to lay it out
//				EditCues ();
                GUILayout.Space(10);             //more space. Yay :)
                TransportControls();             //draw the transport controls
                GUILayout.Space(15);             //wow, I can't comprehend all this space
                EditCues();                      //run this function to edit the exit and entry cues
            }

            //control the looping. If the playback marker is apast the loop point and the loop has not yet been called, then the clip is played again.
            if (currentFile != null)
            {
                previewPoint = previewLine.x / position.width * clipLengthSamples;
                if (isLooping && !loopCalled && previewPoint >= currentFile.postExit - currentFile.preEntry)
                {
                    PlayClip(currentFile.clip);
                    loopCalled = true;
                }
                else
                {
                    loopCalled = false;
                }
            }
        }
        else               //If the user has yet to drag in an AAE Clip or audio file
        {
            DropAreaGUI(); //This function takes care of that
        }
        // Repaint / force gui to update if the current clip is playing (this is necessary to draw the progress of the playback marker more smoothly)
        if (currentFile != null && IsClipPlaying(currentFile.clip))
        {
            Repaint();
        }
    }
Пример #3
0
    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;
        }
    }