修复本地存档位置,增加版本号自动构建
This commit is contained in:
parent
aadbba66fc
commit
74f4943b39
18
Unity/Assets/Resources/DataAssets/VersionConfig.asset
Normal file
18
Unity/Assets/Resources/DataAssets/VersionConfig.asset
Normal file
@ -0,0 +1,18 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c659b850b20e460f866ed3f696be406b, type: 3}
|
||||
m_Name: VersionConfig
|
||||
m_EditorClassIdentifier:
|
||||
majorVersion: 1
|
||||
minorVersion: 0
|
||||
patchVersion: 0
|
||||
buildNumber: 2
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b57f2b79c9807c44b82f92cb4540b99d
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -18,25 +18,33 @@ namespace Logic.Config
|
||||
{
|
||||
public static ConfigManager Instance = new ConfigManager();
|
||||
public GameConfig Config;
|
||||
public VersionConfig VersionCfg;
|
||||
|
||||
|
||||
public void Init()
|
||||
{
|
||||
if (Config != null) return;
|
||||
string path = Application.persistentDataPath + "/game_record.json";
|
||||
if (File.Exists(path))
|
||||
if (Config == null)
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
Config = JsonUtility.FromJson<GameConfig>(json);
|
||||
string path = Application.persistentDataPath + "/game_cfg.json";
|
||||
if (File.Exists(path))
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
Config = JsonUtility.FromJson<GameConfig>(json);
|
||||
}
|
||||
Config ??= new GameConfig();
|
||||
}
|
||||
|
||||
if (!VersionCfg)
|
||||
{
|
||||
VersionCfg = Resources.Load<VersionConfig>("DataAssets/VersionConfig");
|
||||
}
|
||||
Config ??= new GameConfig();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Config == null || !Config.IsChanged) return;
|
||||
string json = JsonUtility.ToJson(Config);
|
||||
File.WriteAllText(Application.persistentDataPath + "/game_record.json", json);
|
||||
File.WriteAllText(Application.persistentDataPath + "/game_cfg.json", json);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
23
Unity/Assets/Scripts/Logic/Config/VersionConfig.cs
Normal file
23
Unity/Assets/Scripts/Logic/Config/VersionConfig.cs
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* @Author: 白哉
|
||||
* @Description:
|
||||
* @Date: 2025年07月25日 星期五 14:07:09
|
||||
* @Modify:
|
||||
*/
|
||||
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Logic.Config
|
||||
{
|
||||
public class VersionConfig : ScriptableObject
|
||||
{
|
||||
public string majorVersion; // 主版本号
|
||||
public string minorVersion; // 次版本号
|
||||
public string patchVersion; // 补丁号
|
||||
public int buildNumber; // 构建号
|
||||
|
||||
public string FullVersion => $"{majorVersion}.{minorVersion}.{patchVersion}.{buildNumber}";
|
||||
}
|
||||
}
|
||||
3
Unity/Assets/Scripts/Logic/Config/VersionConfig.cs.meta
Normal file
3
Unity/Assets/Scripts/Logic/Config/VersionConfig.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c659b850b20e460f866ed3f696be406b
|
||||
timeCreated: 1753426144
|
||||
57
Unity/Assets/Scripts/Logic/Editor/BuildEditor.cs
Normal file
57
Unity/Assets/Scripts/Logic/Editor/BuildEditor.cs
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* @Author: 白哉
|
||||
* @Description:
|
||||
* @Date: 2025年07月25日 星期五 14:07:55
|
||||
* @Modify:
|
||||
*/
|
||||
|
||||
|
||||
using Logic.Config;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Logic.Editor
|
||||
{
|
||||
// 编辑器工具类
|
||||
public class BuildEditor : EditorWindow
|
||||
{
|
||||
private VersionConfig _asset;
|
||||
|
||||
[MenuItem("Tools/打包窗口")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
var window = GetWindow<BuildEditor>();
|
||||
window.titleContent = new GUIContent("打包");
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (!_asset)
|
||||
{
|
||||
var path = $"Assets/Resources/DataAssets/VersionConfig.asset";
|
||||
_asset = AssetDatabase.LoadAssetAtPath<VersionConfig>(path);
|
||||
if (!_asset)
|
||||
{
|
||||
_asset = CreateInstance<VersionConfig>();
|
||||
AssetDatabase.CreateAsset(_asset, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
_asset.majorVersion = EditorGUILayout.TextField("重大更新", _asset.majorVersion);
|
||||
_asset.minorVersion = EditorGUILayout.TextField("功能更新", _asset.minorVersion);
|
||||
_asset.patchVersion = EditorGUILayout.TextField("补丁修复", _asset.patchVersion);
|
||||
EditorGUILayout.IntField("构建号", _asset.buildNumber);
|
||||
|
||||
if (GUILayout.Button("构建版本号"))
|
||||
{
|
||||
_asset.buildNumber++;
|
||||
EditorUtility.SetDirty(_asset);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
// 更新Unity版本号
|
||||
PlayerSettings.bundleVersion = _asset.FullVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Unity/Assets/Scripts/Logic/Editor/BuildEditor.cs.meta
Normal file
3
Unity/Assets/Scripts/Logic/Editor/BuildEditor.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae50ebc5ae6046fb8897da91f46b03df
|
||||
timeCreated: 1753425709
|
||||
Loading…
x
Reference in New Issue
Block a user