90 lines
2.5 KiB
C#
90 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using YooAsset;
|
|
|
|
namespace BuildCli
|
|
{
|
|
public class PlayModeManager
|
|
{
|
|
private string[] _playmodeSettings;
|
|
|
|
private Dictionary<string, EPlayMode> _resourceModeSettings = new Dictionary<string, EPlayMode>
|
|
{
|
|
{ "编辑器模式", EPlayMode.EditorSimulateMode },
|
|
{ "单机模式", EPlayMode.OfflinePlayMode },
|
|
{ "热更模式", EPlayMode.HostPlayMode },
|
|
};
|
|
|
|
private static string PrefsKey => Application.dataPath.GetHashCode() + "GamePlayMode";
|
|
|
|
public static void EditorStartScene() => EditorSceneManager.playModeStartScene = null;
|
|
|
|
public void PlayScene()
|
|
{
|
|
if (!EditorApplication.isPlaying)
|
|
{
|
|
EditorApplication.isPlaying = true;
|
|
}
|
|
else
|
|
EditorApplication.isPlaying = false;
|
|
}
|
|
|
|
|
|
public List<string> GenerateResourceModeList()
|
|
{
|
|
return _resourceModeSettings.Keys.ToList();
|
|
}
|
|
|
|
|
|
public void SetPlayMode(string value)
|
|
{
|
|
if (_resourceModeSettings.TryGetValue(value, out EPlayMode playMode))
|
|
{
|
|
EditorPrefs.SetInt(PrefsKey, (int)playMode);
|
|
}
|
|
}
|
|
|
|
|
|
public int GetSelectPlayMode()
|
|
{
|
|
var selectIndex = EditorPrefs.GetInt(PrefsKey, -1);
|
|
if (selectIndex == -1)
|
|
{
|
|
selectIndex = (int)EPlayMode.EditorSimulateMode;
|
|
EditorPrefs.SetInt(PrefsKey, selectIndex);
|
|
}
|
|
return selectIndex;
|
|
}
|
|
|
|
public string GetSelectPlayModeValue()
|
|
{
|
|
var selectIndex = EditorPrefs.GetInt(PrefsKey, -1);
|
|
if (selectIndex == -1)
|
|
{
|
|
selectIndex = (int)EPlayMode.EditorSimulateMode;
|
|
EditorPrefs.SetInt(PrefsKey, selectIndex);
|
|
}
|
|
|
|
EPlayMode mode = (EPlayMode)selectIndex;
|
|
return mode.ToString();
|
|
}
|
|
|
|
|
|
public List<string> GeneratePlayModeSettingsList()
|
|
{
|
|
_playmodeSettings = new[]
|
|
{
|
|
"Default (Reload Domain, Reload Scene)", "Disable Reload Domain", "Disable Reload Scene", "Disable All"
|
|
};
|
|
|
|
var playModeSettingsList = new List<string>(_playmodeSettings);
|
|
|
|
return playModeSettingsList;
|
|
}
|
|
}
|
|
}
|