public void OnGUI()
        {
            using (var scroll = new EditorGUILayout.ScrollViewScope(m_scroll)) {
                m_scroll = scroll.scrollPosition;

                bool newClearCache = EditorGUILayout.ToggleLeft("Clear Cache On Play", AssetBundleManager.CleanCacheOnPlay);
                if (newClearCache != AssetBundleManager.CleanCacheOnPlay)
                {
                    Settings.ClearCacheOnPlay = newClearCache;
                }

                GUILayout.Space(12f);
                GUILayout.Label("Server Settings", "BoldLabel");
                foreach (var s in Settings.ServerSettings)
                {
                    using (new EditorGUILayout.VerticalScope("box")) {
                        var newName = EditorGUILayout.TextField("Name", s.Name);
                        if (newName != s.Name)
                        {
                            s.Name = newName;
                        }

                        var newType = (ServerSettingType)EditorGUILayout.EnumPopup("Server Type", s.ServerType);
                        if (newType != s.ServerType)
                        {
                            s.ServerType = newType;
                        }

                        switch (s.ServerType)
                        {
                        case ServerSettingType.Local:
                        {
                            var newFolder = DrawFolderSelector("AssetBundle Directory",
                                                               "Select AssetBundle Directory",
                                                               s.AssetBundleDirectory,
                                                               Application.dataPath + "/../");
                            if (newFolder != s.AssetBundleDirectory)
                            {
                                var projectPath = Directory.GetParent(Application.dataPath).ToString();

                                if (projectPath == newFolder)
                                {
                                    newFolder = string.Empty;
                                }
                                else
                                {
                                    var index = newFolder.IndexOf(projectPath);
                                    if (index >= 0)
                                    {
                                        newFolder = newFolder.Substring(projectPath.Length + index);
                                        if (newFolder.IndexOf('/') == 0)
                                        {
                                            newFolder = newFolder.Substring(1);
                                        }
                                    }
                                }

                                s.AssetBundleDirectory = newFolder;
                            }
                        }
                        break;

                        case ServerSettingType.Remote:
                        {
                            var url = EditorGUILayout.TextField("Server URL", s.ServerURL);
                            if (url != s.ServerURL)
                            {
                                s.ServerURL = url;
                            }
                        }
                        break;
                        }

                        bool newWithPlatformDir = EditorGUILayout.ToggleLeft("Use Platform Subdirectory", s.UsePlatformSubDir);
                        if (newWithPlatformDir != s.UsePlatformSubDir)
                        {
                            s.UsePlatformSubDir = newWithPlatformDir;
                        }

                        using (new EditorGUI.DisabledScope(s.UsePlatformSubDir)) {
                            if (string.IsNullOrEmpty(s.ManifestFileName))
                            {
                                if (s.ServerType == ServerSettingType.Local)
                                {
                                    s.ManifestFileName = Path.GetFileName(s.AssetBundleDirectory);
                                }
                            }
                            var newManifestName = EditorGUILayout.TextField("Manifest File Name", s.ManifestFileName);
                            if (newManifestName != s.ManifestFileName)
                            {
                                s.ManifestFileName = newManifestName;
                            }
                        }

                        if (GUILayout.Button("Remove"))
                        {
                            m_removingItem.Add(s);
                        }
                    }
                }

                if (m_removingItem.Count > 0)
                {
                    foreach (var r in m_removingItem)
                    {
                        Settings.RemoveServerSetting(r);
                    }
                    m_removingItem.Clear();
                }

                GUILayout.Space(8f);
                if (GUILayout.Button("Add Server Setting"))
                {
                    Settings.CreateServerSetting("New Setting", ServerSettingType.Local);
                }


                GUILayout.Space(12f);
                GUILayout.Label("Editor Server Setting", "BoldLabel");


                var names        = Settings.ServerSettings.Select(x => x.Name).ToArray();
                var namesWithSim = new string[names.Length + 2];
                namesWithSim [0] = "Simulation Mode";
                namesWithSim [1] = "Simulation Mode(GraphTool)";
                Array.Copy(names, 0, namesWithSim, 2, names.Length);

                int editorIndex = 0;
                if (Settings.Mode == Settings.AssetBundleManagerMode.SimulationMode)
                {
                    editorIndex = 0;
                }
                else if (Settings.Mode == Settings.AssetBundleManagerMode.SimulationModeGraphTool)
                {
                    editorIndex = 1;
                }
                else
                {
                    editorIndex = (Settings.CurrentSetting == null) ? -1 : Settings.ServerSettings.IndexOf(Settings.CurrentSetting) + 2;
                }

                int devIndex       = (Settings.DevelopmentBuildSetting == null) ? -1 : Settings.ServerSettings.IndexOf(Settings.DevelopmentBuildSetting);
                int releaseIndex   = (Settings.ReleaseBuildSetting == null) ? -1 : Settings.ServerSettings.IndexOf(Settings.ReleaseBuildSetting);
                int streamingIndex = (Settings.StreamingAssetsSetting == null) ? -1 : Settings.ServerSettings.IndexOf(Settings.StreamingAssetsSetting);


                var newEditorIndex = EditorGUILayout.Popup("Editor Setting", editorIndex, namesWithSim);

                GUILayout.Space(12f);
                GUILayout.Label("Player Server Setting", "BoldLabel");

                var newDevIndex             = EditorGUILayout.Popup("Development Build", devIndex, names);
                var newReleaseIndex         = EditorGUILayout.Popup("Release Build", releaseIndex, names);
                var newStreamingAssetsIndex = EditorGUILayout.Popup("Streaming Assets", streamingIndex, names);

                if (newEditorIndex != editorIndex)
                {
                    if (newEditorIndex == 0)
                    {
                        Settings.Mode = Settings.AssetBundleManagerMode.SimulationMode;
                    }
                    else if (newEditorIndex == 1)
                    {
                        Settings.Mode = Settings.AssetBundleManagerMode.SimulationModeGraphTool;
                    }
                    else
                    {
                        Settings.Mode           = Settings.AssetBundleManagerMode.Server;
                        Settings.CurrentSetting = Settings.ServerSettings [newEditorIndex - 2];
                    }
                }
                if (newDevIndex != devIndex)
                {
                    if (Settings.ServerSettings.Count > newDevIndex)
                    {
                        Settings.DevelopmentBuildSetting = Settings.ServerSettings [newDevIndex];
                    }
                }
                if (newReleaseIndex != releaseIndex)
                {
                    if (Settings.ServerSettings.Count > newReleaseIndex)
                    {
                        Settings.ReleaseBuildSetting = Settings.ServerSettings [newReleaseIndex];
                    }
                }
                if (newStreamingAssetsIndex != streamingIndex)
                {
                    if (Settings.ServerSettings.Count > newStreamingAssetsIndex)
                    {
                        var newSetting = Settings.ServerSettings [newStreamingAssetsIndex];
                        if (newSetting.ServerType == ServerSettingType.StreamingAssets)
                        {
                            Settings.StreamingAssetsSetting = newSetting;
                        }
                    }
                }

                GUILayout.Space(20f);

                var curSetting = Settings.CurrentSetting;
                if (curSetting != null)
                {
                    bool isRunning = LaunchAssetBundleServer.IsRunning();
                    EditorGUILayout.LabelField("Local Server Running", isRunning.ToString());
                    EditorGUILayout.LabelField("Server URL", curSetting.ServerURL);

                    EditorGUILayout.HelpBox(LaunchAssetBundleServer.GetServerArgs(), MessageType.Info);

                    using (new EditorGUI.DisabledScope(Settings.Mode != Settings.AssetBundleManagerMode.Server || curSetting.ServerType != ServerSettingType.Local)) {
                        if (GUILayout.Button(isRunning ? "Stop Local Server": "Start Local Server"))
                        {
                            LaunchAssetBundleServer.ToggleLocalAssetBundleServer();
                        }
                    }
                    GUILayout.Space(8f);
                }
            }
        }
Exemplo n.º 2
0
        public void OnGUI()
        {
            using (new EditorGUILayout.VerticalScope()) {
                bool newClearCache = EditorGUILayout.ToggleLeft("Clear Cache On Play", AssetBundleManager.CleanCacheOnPlay);
                if (newClearCache != AssetBundleManager.CleanCacheOnPlay)
                {
                    Settings.ClearCacheOnPlay = newClearCache;
                }

                GUILayout.Space(12f);
                GUILayout.Label("Editor Server Setting", "BoldLabel");
                DrawServerSettingDropDown(Settings.CurrentSetting, m_menuTitle, true, true, (Settings.ServerSetting s) => {
                    Settings.CurrentSetting = s;
                    Settings.Mode           = Settings.AssetBundleManagerMode.Server;
                    ConfigureMenuSelectionName();
                    return(true);
                });

                var curSetting = Settings.CurrentSetting;
                if (curSetting != null)
                {
                    var newName = EditorGUILayout.TextField("Name", curSetting.Name);
                    if (newName != curSetting.Name)
                    {
                        curSetting.Name = newName;
                        ConfigureMenuSelectionName();
                    }

                    if (curSetting.IsLocalServer)
                    {
                        var newFolder = DrawFolderSelector("AssetBundle Directory",
                                                           "Select AssetBundle Directory",
                                                           curSetting.AssetBundleDirectory,
                                                           Application.dataPath + "/../");
                        if (newFolder != curSetting.AssetBundleDirectory)
                        {
                            curSetting.AssetBundleDirectory = newFolder;
                        }
                    }
                    else
                    {
                        var url = EditorGUILayout.TextField("Server URL", curSetting.ServerURL);
                        if (url != curSetting.ServerURL)
                        {
                            curSetting.ServerURL = url;
                        }
                    }

                    bool newWithPlatformDir = EditorGUILayout.ToggleLeft("Use Platform Subdirectory", curSetting.UsePlatformSubDir);
                    if (newWithPlatformDir != curSetting.UsePlatformSubDir)
                    {
                        curSetting.UsePlatformSubDir = newWithPlatformDir;
                    }
                }

                GUILayout.Space(8f);

                GUILayout.Space(4f);
                GUILayout.Label("Development Server", "BoldLabel");
                string devTitle = (Settings.DevelopmentBuildSetting == null) ? "<select server>" : Settings.DevelopmentBuildSetting.Name;
                DrawServerSettingDropDown(Settings.DevelopmentBuildSetting, devTitle, false, false, (Settings.ServerSetting s) => {
                    Settings.DevelopmentBuildSetting = s;
                    return(true);
                });
                GUILayout.Space(4f);
                GUILayout.Label("Release Server", "BoldLabel");
                string relTitle = (Settings.ReleaseBuildSetting == null) ? "<select server>" : Settings.ReleaseBuildSetting.Name;
                DrawServerSettingDropDown(Settings.ReleaseBuildSetting, relTitle, false, false, (Settings.ServerSetting s) => {
                    Settings.ReleaseBuildSetting = s;
                    return(true);
                });

                GUILayout.Space(20f);


                if (newClearCache != AssetBundleManager.CleanCacheOnPlay)
                {
                    Settings.ClearCacheOnPlay = newClearCache;
                }

                bool isRunning = LaunchAssetBundleServer.IsRunning();
                EditorGUILayout.LabelField("Local Server Running", isRunning.ToString());
                EditorGUILayout.LabelField("Server URL", curSetting.ServerURL);

                EditorGUILayout.HelpBox(LaunchAssetBundleServer.GetServerArgs(), MessageType.Info);

                using (new EditorGUI.DisabledScope(Settings.Mode != Settings.AssetBundleManagerMode.Server || curSetting == null || !curSetting.IsLocalServer)) {
                    if (GUILayout.Button(isRunning ? "Stop Local Server": "Start Local Server"))
                    {
                        LaunchAssetBundleServer.ToggleLocalAssetBundleServer();
                    }
                }
            }
        }