예제 #1
0
        public override void OnInspectorGUI()
        {
            var songItem = (SongItem)target;

            // EditorGUI.indentLevel--;

            if (dropdownButtonStyles == null)
            {
                dropdownButtonStyles           = new GUIStyle("DropDownButton");
                dropdownButtonStyles.alignment = TextAnchor.MiddleCenter;
                dropdownButtonStyles.margin    = new RectOffset(3, 3, 0, 0);
            }

            serializedObject.Update();

            songVisibleAnim.target = EditorUtils.Foldout(songVisibleAnim.target, "Song", null, false);
            if (EditorGUILayout.BeginFadeGroup(songVisibleAnim.faded))
            {
                EditorUtils.Indent();
                // TitleAttributeDrawer.OnGUILayout("Song");
                EditorGUILayout.PropertyField(serializedObject.FindProperty("clip"));

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.DelayedIntField(serializedObject.FindProperty("bpm"));
                EditorGUILayout.HelpBox("The time of each note will be recalculated base on the bpm when you changed it.", MessageType.Info);
                var changed = EditorGUI.EndChangeCheck();
                if (changed)
                {
                    serializedObject.ApplyModifiedProperties();
                    UpdateNotesTime(songItem);
                    serializedObject.Update();
                }
                EditorUtils.EndIndent();
            }
            EditorGUILayout.EndFadeGroup();

            sequenceVisibleAnim.target = EditorUtils.Foldout(sequenceVisibleAnim.target, "Sequence");
            if (EditorGUILayout.BeginFadeGroup(sequenceVisibleAnim.faded))
            {
                EditorUtils.Indent();
                EditorGUILayout.PropertyField(useCurrentBpmMidiImportProperty, new GUIContent("Import With Current Bpm",
                                                                                              "Some DAW export midi (e.g. Ableton) clip without bpm info, so enable this will force to import the midi with the current bpm while with disabled this, the bpm will be detected from midi file and update accordinly."));
                if (EditorGUILayout.DropdownButton(new GUIContent("Import notes"), FocusType.Keyboard, dropdownButtonStyles))
                {
                    var menu = new GenericMenu();
                    menu.AddItem(new GUIContent("MIDI"), false, () =>
                    {
                        var midiFile = FindMidiFile(songItem);
                        if (midiFile != null && EditorUtility.DisplayDialog("Import notes from midi", "This will erased all your current notes, and import from the midi clip if found", "Import", "Cancel"))
                        {
                            serializedObject.ApplyModifiedProperties();
                            Undo.RecordObject(songItem, "Import from Midi");
                            UpdateBpm(midiFile, songItem);
                            serializedObject.Update();
                        }
                    });
                    menu.AddItem(new GUIContent("JSON"), false, () =>
                    {
                        var importedLiteSongItem = FindJsonFile(songItem);
                        if (importedLiteSongItem != null && EditorUtility.DisplayDialog("Import notes from json", "This will erased all your current notes, and import notes from the json file", "Import", "Cancel"))
                        {
                            serializedObject.ApplyModifiedProperties();
                            if (importedLiteSongItem.bpm != songItem.bpm)
                            {
                                var index = EditorUtility.DisplayDialogComplex("Bpm doesn't match", "Bpm doesn't match! You have few options", "Use SongItem's", "Use Json file's", "Cancel");
                                if (index == 0)
                                {
                                    importedLiteSongItem.bpm = songItem.bpm;
                                }
                                else if (index == 1)
                                {
                                    songItem.bpm = importedLiteSongItem.bpm;
                                }
                                else if (index == 2)
                                {
                                    GUIUtility.ExitGUI();
                                    return;
                                }
                            }
                            Undo.RecordObject(songItem, "Import from Json");
                            importedLiteSongItem.RecalculateBpmTo(importedLiteSongItem.bpm);
                            songItem.LoadNotesFrom(importedLiteSongItem);
                            EditorUtility.SetDirty(songItem);
                            serializedObject.Update();
                        }
                    });
                    menu.ShowAsContext();

                    // GUIUtility.ExitGUI();
                }
                if (GUILayout.Button("Edit notes"))
                {
                    SequenceEditor.ShowWindow(songItem);
                }

                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.LabelField("Number of notes : " + serializedObject.FindProperty("notes").arraySize.ToString());
                EditorGUI.EndDisabledGroup();
                EditorUtils.EndIndent();
            }
            EditorGUILayout.EndFadeGroup();

            generatorVisibleAnim.target = EditorUtils.Foldout(generatorVisibleAnim.target, "Generator [Experimental]", useGenetatorProperty);
            if (EditorGUILayout.BeginFadeGroup(generatorVisibleAnim.faded))
            {
                EditorUtils.Indent();
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Onset", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("onsetSensitivity"));
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(onsetDataProperty.arraySize == 0 ? "Analyse Onset" : "Reanalyse"))
                {
                    serializedObject.ApplyModifiedProperties();
                    Undo.RecordObject(songItem, "Analyse Onset");
                    songItem.onsetData = songItem.GenerateOnset();

                    float max = 0;
                    float min = 0;

                    // Find strongest/weakest onset
                    for (int i = 0; i < songItem.onsetData.Length; i++)
                    {
                        max = Math.Max(max, songItem.onsetData[i]);
                        min = Math.Min(min, songItem.onsetData[i]);
                    }

                    songItem.onsetMax = max;
                    songItem.onsetMin = min;
                    EditorUtility.SetDirty(songItem);
                    serializedObject.Update();
                }
                if (onsetDataProperty.arraySize != 0)
                {
                    if (GUILayout.Button("Clear"))
                    {
                        onsetDataProperty.ClearArray();
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.HelpBox("Onset data length : " + onsetDataProperty.arraySize + "\n Min : " + songItem.onsetMin + "\n Max : " + songItem.onsetMax, MessageType.Info);

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Options", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("runtimeGenerate"));

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(genetatorProperty);
                UpdateGeneratorEditor(EditorGUI.EndChangeCheck());
                if (generatorEditor)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    EditorGUILayout.Space();
                    EditorGUI.indentLevel++;
                    generatorEditor.OnInspectorGUI();
                    EditorGUI.indentLevel--;
                    EditorGUILayout.Space();
                    EditorGUILayout.EndVertical();
                }
                if (genetatorProperty.objectReferenceValue && GUILayout.Button("Generate"))
                {
                    var notes = ((SequenceGeneratorBase)genetatorProperty.objectReferenceValue).OnGenerateSequence(songItem);
                    if (notes != null)
                    {
                        serializedObject.ApplyModifiedProperties();
                        Undo.RecordObject(songItem, "Generate Notes");
                        songItem.notes = notes;
                        EditorUtility.SetDirty(songItem);
                        serializedObject.Update();

                        SequenceEditor.ShowWindow(songItem);
                    }
                }
                EditorUtils.EndIndent();
            }
            EditorGUILayout.EndFadeGroup();

            serializedObject.ApplyModifiedProperties();
        }
예제 #2
0
        private void OnGUI()
        {
            if (wizardData == null)
            {
                return;
            }

            if (!inited)
            {
                inited = true;

                biggerButton         = new GUIStyle("button");
                biggerButton.padding = new RectOffset(12, 12, 6, 6);

                urlIcon = EditorGUIUtility.IconContent("_Help");

                eyeIcon = EditorGUIUtility.IconContent(EditorGUIUtility.isProSkin ? "ViewToolOrbit On" : "ViewToolOrbit");



                header           = new GUIStyle(EditorStyles.boldLabel);
                header.fontSize  = 14;
                header.alignment = TextAnchor.MiddleCenter;

                questionContainer = new GUIStyle();

                answer = new GUIStyle(EditorStyles.label);
                answer.normal.textColor = EditorStyles.label.normal.textColor;
                answer.wordWrap         = true;
                answer.alignment        = TextAnchor.MiddleLeft;
                answer.stretchWidth     = false;
                // var c = answer.normal.textColor;
                // c.a = 0.8f;
                // answer.normal.textColor = c;
                answer.padding = new RectOffset(4, 4, 4, 4);

                message = new GUIStyle(answer);
                // message.normal.textColor = EditorStyles.label.normal.textColor;
                // message.fontSize = 12;
                // message.stretchWidth = true;
                message.alignment    = TextAnchor.MiddleCenter;
                message.stretchWidth = true;


                question                  = new GUIStyle("box");
                question.fontSize         = 14;
                question.normal.textColor = EditorStyles.label.normal.textColor;
                question.font             = EditorStyles.boldFont;
                var c = question.normal.textColor;
                c.a = 0.9f;
                question.normal.textColor = c;
            }

            void DrawButtonLinks()
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                foreach (var wAction in wizardData.buttonLinks)
                {
                    urlIcon.text = wAction.actionText;
                    if (GUILayout.Button(urlIcon, biggerButton))
                    {
                        Application.OpenURL(wAction.url);
                    }
                }
                EditorGUILayout.EndHorizontal();
                // EditorGUILayout.Space();
            }

            scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Width(position.width));
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(wizardData.header, header);
            EditorUtils.HorizontalLine(1, header.CalcSize(new GUIContent(wizardData.header)).x);
            EditorGUILayout.Space();

            var backgroundColor = EditorGUIUtility.isProSkin ? new Color(30 / 255f, 30 / 255f, 30 / 255f) : new Color(1f, 1f, 1f);

            backgroundColor.a = 0.3f;

            var messageRect = GUILayoutUtility.GetRect(new GUIContent(wizardData.message), message);

            // EditorGUILayout.LabelField(, message);
            EditorGUI.DrawRect(messageRect, backgroundColor);
            EditorGUI.LabelField(messageRect, wizardData.message, message);

            EditorGUILayout.Separator();

            void CloseOtherGroup(WizardData.WizardActionGroup onGroup)
            {
                foreach (var group in wizardData.wizardActionGroups)
                {
                    if (group != onGroup)
                    {
                        group.visible.target = false;
                    }
                }
            }

            foreach (var group in wizardData.wizardActionGroups)
            {
                if (group.visible == null)
                {
                    Refresh();
                }

                EditorGUI.BeginChangeCheck();
                group.visible.target = EditorUtils.Foldout(group.visible.target, group.groupName);
                if (EditorGUI.EndChangeCheck() && group.visible.target)
                {
                    CloseOtherGroup(group);
                }

                if (EditorGUILayout.BeginFadeGroup(group.visible.faded))
                {
                    EditorUtils.Indent();
                    foreach (var action in group.actions)
                    {
                        EditorGUILayout.BeginVertical(questionContainer);
                        GUILayout.Space(2);

                        using (new EditorUtils.GUIColorScope(Color.yellow))
                            using (new EditorUtils.BackgroundColorScope(EditorGUIUtility.isProSkin ? Color.yellow : new Color(1, 1, 171 / 255f, 0.34f)))
                                EditorGUILayout.LabelField($"Q: {action.question}", question);
                        GUILayout.Space(2);

                        var offset = question.CalcSize(new GUIContent("Q: "));

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(offset.x);
                        // using (new EditorUtils.BackgroundColorScope(EditorGUIUtility.isProSkin ? Color.black : Color.white))
                        var answerSize = GUILayoutUtility.GetRect(new GUIContent(action.answer), answer);

                        EditorGUI.DrawRect(answerSize, backgroundColor);
                        // GUILayout.Label(, answer);
                        EditorGUI.LabelField(answerSize, action.answer, answer);
                        EditorGUILayout.EndHorizontal();

                        GUILayout.Space(2);
                        if (action.wActions != null)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.FlexibleSpace();
                            foreach (var wAction in action.wActions)
                            {
                                var isUrl = !string.IsNullOrWhiteSpace(wAction.url);

                                if (isUrl)
                                {
                                    urlIcon.text = wAction.actionText;
                                    if (GUILayout.Button(urlIcon, biggerButton))
                                    {
                                        Application.OpenURL(wAction.url);
                                    }
                                }
                                else
                                {
                                    eyeIcon.text = wAction.actionText;
                                    if (GUILayout.Button(eyeIcon, biggerButton))
                                    {
                                        if (!string.IsNullOrWhiteSpace(wAction.referenceAssetPath))
                                        {
                                            if (wAction.referenceAssetPath.EndsWith(".unity"))
                                            {
                                                LoadScene(wAction.referenceAssetPath);
                                            }
                                            else
                                            {
                                                PingAsset(LoadAsset <UnityEngine.Object>(wAction.referenceAssetPath));
                                            }
                                        }
                                        if (!string.IsNullOrWhiteSpace(wAction.referenceSceneObjectName))
                                        {
                                            LocateGameObject(GameObject.Find(wAction.referenceSceneObjectName));
                                        }
                                        GUIUtility.ExitGUI();
                                    }
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.EndVertical();

                        //Draw vertical line
                        var rect = GUILayoutUtility.GetLastRect();
                        rect.x      += 10;
                        rect.y      += offset.y + 6;
                        rect.height -= offset.y + 6;
                        rect.width   = 2;
                        var color = answer.normal.textColor;
                        color.a = 0.5f;
                        EditorGUI.DrawRect(rect, color);
                        // EditorGUILayout.Separator();
                    }
                    EditorUtils.EndIndent();
                }
                EditorGUILayout.EndFadeGroup();
            }

            GUILayout.FlexibleSpace();

            EditorGUILayout.EndScrollView();

            DrawButtonLinks();
        }