Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            Settings settings = target as Settings;

            DrawLinks();

            EditorGUI.BeginChangeCheck();

            hasBankSourceChanged = false;
            bool hasBankTargetChanged = false;

            GUIStyle style = new GUIStyle(GUI.skin.label);

            style.richText = true;

            GUI.skin.FindStyle("HelpBox").richText = true;

            SourceType sourceType = settings.HasSourceProject ? SourceType.Project : (settings.HasPlatforms ? SourceType.Multi : SourceType.Single);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            sourceType = GUILayout.Toggle(sourceType == SourceType.Project, "Project", "Button") ? 0 : sourceType;
            sourceType = GUILayout.Toggle(sourceType == SourceType.Single, "Single Platform Build", "Button") ? SourceType.Single : sourceType;
            sourceType = GUILayout.Toggle(sourceType == SourceType.Multi, "Multiple Platform Build", "Button") ? SourceType.Multi : sourceType;
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical();

            EditorGUILayout.HelpBox(
                "<size=11>Select the way you wish to connect Unity to the FMOD Studio content:\n" +
                "<b>• Project</b>\t\tIf you have the complete FMOD Studio project avaliable\n" +
                "<b>• Single Platform</b>\tIf you have only the contents of the <i>Build</i> folder for a single platform\n" +
                "<b>• Multiple Platforms</b>\tIf you have only the contents of the <i>Build</i> folder for multiple platforms, each platform in its own sub directory\n" +
                "</size>"
                , MessageType.Info, true);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (sourceType == SourceType.Project)
            {
                EditorGUILayout.BeginHorizontal();
                string oldPath = settings.SourceProjectPath;
                EditorGUILayout.PrefixLabel("Studio Project Path", GUI.skin.textField, style);

                EditorGUI.BeginChangeCheck();
                string newPath = EditorGUILayout.TextField(GUIContent.none, settings.SourceProjectPath);
                if (EditorGUI.EndChangeCheck())
                {
                    if (newPath.EndsWith(".fspro"))
                    {
                        settings.SourceProjectPath = newPath;
                    }
                }

                if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false)))
                {
                    GUI.FocusControl(null);
                    string path = EditorUtility.OpenFilePanel("Locate Studio Project", oldPath, "fspro");
                    if (!string.IsNullOrEmpty(path))
                    {
                        settings.SourceProjectPath = MakePathRelative(path);
                        Repaint();
                    }
                }
                EditorGUILayout.EndHorizontal();

                // Cache in settings for runtime access in play-in-editor mode
                string bankPath = EditorUtils.GetBankDirectory();
                settings.SourceBankPath   = bankPath;
                settings.HasPlatforms     = true;
                settings.HasSourceProject = true;

                // First time project path is set or changes, copy to streaming assets
                if (settings.SourceProjectPath != oldPath)
                {
                    hasBankSourceChanged = true;
                }
            }
            else if (sourceType == SourceType.Single || sourceType == SourceType.Multi)
            {
                EditorGUILayout.BeginHorizontal();
                string oldPath = settings.SourceBankPath;
                EditorGUILayout.PrefixLabel("Build Path", GUI.skin.textField, style);

                EditorGUI.BeginChangeCheck();
                string tempPath = EditorGUILayout.TextField(GUIContent.none, settings.SourceBankPath);
                if (EditorGUI.EndChangeCheck())
                {
                    settings.SourceBankPath = tempPath;
                }

                if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false)))
                {
                    GUI.FocusControl(null);
                    string newPath = EditorUtility.OpenFolderPanel("Locate Build Folder", oldPath, null);
                    if (!string.IsNullOrEmpty(newPath))
                    {
                        settings.SourceBankPath = MakePathRelative(newPath);
                        Repaint();
                    }
                }
                EditorGUILayout.EndHorizontal();

                settings.HasPlatforms     = (sourceType == SourceType.Multi);
                settings.HasSourceProject = false;

                // First time project path is set or changes, copy to streaming assets
                if (settings.SourceBankPath != oldPath)
                {
                    hasBankSourceChanged = true;
                }
            }

            bool   validBanks;
            string failReason;

            EditorUtils.ValidateSource(out validBanks, out failReason);
            if (!validBanks)
            {
                failReason += "\n\nFor detailed setup instructions, please see the getting started guide linked above.";
                EditorGUILayout.HelpBox(failReason, MessageType.Error, true);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(settings);
                }
                return;
            }

            ImportType importType = (ImportType)EditorGUILayout.EnumPopup("Import Type", settings.ImportType);

            if (importType != settings.ImportType)
            {
                hasBankTargetChanged = true;
                settings.ImportType  = importType;

                bool deleteBanks = EditorUtility.DisplayDialog(
                    "FMOD Bank Import Type Changed", "Do you want to delete the " + settings.ImportType.ToString() + " banks in " + settings.TargetPath,
                    "Yes", "No");
                if (deleteBanks)
                {
                    // Delete the old banks
                    EventManager.removeBanks = true;
                    EventManager.RefreshBanks();
                }
            }

            // ----- Asset Sub Directory -------------
            {
                GUI.SetNextControlName("targetSubFolder");
                targetSubFolder = settings.ImportType == ImportType.AssetBundle
                    ? EditorGUILayout.TextField("FMOD Asset Sub Folder", string.IsNullOrEmpty(targetSubFolder) ? settings.TargetAssetPath : targetSubFolder)
                    : EditorGUILayout.TextField("FMOD Bank Sub Folder", string.IsNullOrEmpty(targetSubFolder) ? settings.TargetSubFolder : targetSubFolder);
                if (GUI.GetNameOfFocusedControl() == "targetSubFolder")
                {
                    focused = true;
                    if (Event.current.isKey)
                    {
                        switch (Event.current.keyCode)
                        {
                        case KeyCode.Return:
                        case KeyCode.KeypadEnter:
                            if (settings.TargetSubFolder != targetSubFolder)
                            {
                                EventManager.RemoveBanks(settings.TargetPath);
                                settings.TargetSubFolder = targetSubFolder;
                                hasBankTargetChanged     = true;
                            }
                            targetSubFolder = "";
                            break;
                        }
                    }
                }
                else if (focused)
                {
                    if (settings.TargetPath != targetSubFolder)
                    {
                        EventManager.RemoveBanks(settings.TargetPath);
                        settings.TargetSubFolder = targetSubFolder;
                        hasBankTargetChanged     = true;
                    }
                    targetSubFolder = "";
                }
            }

            // ----- Logging -----------------
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("<b>Logging</b>", style);
            EditorGUI.indentLevel++;
            settings.LoggingLevel = (FMOD.DEBUG_FLAGS)EditorGUILayout.EnumPopup("Logging Level", settings.LoggingLevel);
            EditorGUI.indentLevel--;

            // ----- Loading -----------------
            EditorGUI.BeginDisabledGroup(settings.ImportType == ImportType.AssetBundle);
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("<b>Initialization</b>", style);
            EditorGUI.indentLevel++;

            settings.EnableMemoryTracking = EditorGUILayout.Toggle("Enable Memory Tracking", settings.EnableMemoryTracking);

            settings.BankLoadType = (BankLoadType)EditorGUILayout.EnumPopup("Load Banks", settings.BankLoadType);
            switch (settings.BankLoadType)
            {
            case BankLoadType.All:
                break;

            case BankLoadType.Specified:
                settings.AutomaticEventLoading = false;
                Texture upArrowTexture   = EditorGUIUtility.Load("FMOD/ArrowUp.png") as Texture;
                Texture downArrowTexture = EditorGUIUtility.Load("FMOD/ArrowDown.png") as Texture;
                bankFoldOutState = EditorGUILayout.Foldout(bankFoldOutState, "Specified Banks", true);
                if (bankFoldOutState)
                {
                    for (int i = 0; i < settings.BanksToLoad.Count; i++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUI.indentLevel++;

                        var bankName = settings.BanksToLoad[i];
                        EditorGUILayout.TextField(bankName.Replace(".bank", ""));

                        if (GUILayout.Button(upArrowTexture, GUILayout.ExpandWidth(false)))
                        {
                            if (i > 0)
                            {
                                var temp = settings.BanksToLoad[i];
                                settings.BanksToLoad[i]     = settings.BanksToLoad[i - 1];
                                settings.BanksToLoad[i - 1] = temp;
                            }
                            continue;
                        }
                        if (GUILayout.Button(downArrowTexture, GUILayout.ExpandWidth(false)))
                        {
                            if (i < settings.BanksToLoad.Count - 1)
                            {
                                var temp = settings.BanksToLoad[i];
                                settings.BanksToLoad[i]     = settings.BanksToLoad[i + 1];
                                settings.BanksToLoad[i + 1] = temp;
                            }
                            continue;
                        }

                        if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false)))
                        {
                            GUI.FocusControl(null);
                            string path = EditorUtility.OpenFilePanel("Locate Bank", settings.TargetPath, "bank");
                            if (!string.IsNullOrEmpty(path))
                            {
                                path = RuntimeUtils.GetCommonPlatformPath(path);
                                settings.BanksToLoad[i] = path.Replace(settings.TargetPath, "");
                                Repaint();
                            }
                        }
                        if (GUILayout.Button("Remove", GUILayout.ExpandWidth(false)))
                        {
                            Settings.Instance.BanksToLoad.RemoveAt(i);
                            continue;
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUI.indentLevel--;
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(30);
                    if (GUILayout.Button("Add Bank", GUILayout.ExpandWidth(false)))
                    {
                        settings.BanksToLoad.Add("");
                    }
                    if (GUILayout.Button("Add All Banks", GUILayout.ExpandWidth(false)))
                    {
                        string sourceDir;

                        if (settings.HasSourceProject)
                        {
                            sourceDir = string.Format("{0}/{1}/", settings.SourceBankPath, settings.CurrentEditorPlatform.BuildDirectory);
                        }
                        else
                        {
                            sourceDir = settings.SourceBankPath;
                        }

                        sourceDir = RuntimeUtils.GetCommonPlatformPath(sourceDir);

                        var banksFound = new List <string>(Directory.GetFiles(sourceDir, "*.bank", SearchOption.AllDirectories));
                        for (int i = 0; i < banksFound.Count; i++)
                        {
                            string bankShortName = RuntimeUtils.GetCommonPlatformPath(banksFound[i]).Replace(sourceDir, "");
                            if (!settings.BanksToLoad.Contains(bankShortName))
                            {
                                settings.BanksToLoad.Add(bankShortName);
                            }
                        }

                        Repaint();
                    }
                    if (GUILayout.Button("Clear", GUILayout.ExpandWidth(false)))
                    {
                        settings.BanksToLoad.Clear();
                    }
                    GUILayout.EndHorizontal();
                }
                break;

            case BankLoadType.None:
                settings.AutomaticEventLoading = false;
                break;

            default:
                break;
            }

            EditorGUI.BeginDisabledGroup(settings.BankLoadType == BankLoadType.None);
            settings.AutomaticSampleLoading = EditorGUILayout.Toggle("Load Bank Sample Data", settings.AutomaticSampleLoading);
            EditorGUI.EndDisabledGroup();

            settings.EncryptionKey = EditorGUILayout.TextField("Bank Encryption Key", settings.EncryptionKey);

            EditorGUI.indentLevel--;
            EditorGUI.EndDisabledGroup();

            // ----- PIE ----------------------------------------------
            EditorGUILayout.Separator();
            DisplayPlatform(settings.PlayInEditorPlatform);

            // ----- Default ----------------------------------------------
            EditorGUILayout.Separator();
            DisplayPlatform(settings.DefaultPlatform);

            // Top-level platforms
            EditorGUILayout.Separator();
            DisplayPlatformHeader();

            EditorGUI.indentLevel++;
            foreach (Platform platform in settings.DefaultPlatform.Children)
            {
                DisplayPlatform(platform);
            }
            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(settings);
            }

            if (hasBankSourceChanged)
            {
                EventManager.RefreshBanks();
            }
            if (hasBankTargetChanged)
            {
                EventManager.RefreshBanks();
            }
            if (pendingPlatformDelete != null)
            {
                settings.RemovePlatformProperties(pendingPlatformDelete);

                ParentCandidates.Remove(pendingPlatformDelete);

                if (!(pendingPlatformDelete is PlatformGroup))
                {
                    MissingPlatforms.Add(pendingPlatformDelete);
                    MissingPlatforms.Sort(CompareDisplayNames);
                }

                pendingPlatformDelete = null;
            }
        }