一、在游戏代码中记录版本号,方便获取
using System; using System.IO; using UnityEngine; using UnityEditor; /// <summary> /// 自动在代码中记录 verion、bundleVersionCode /// 参考 https://blog.csdn.net/zxsean/article/details/52117146 /// 将此脚本放到Editor目录下 /// </summary> [InitializeOnLoad] public class VersionCheckEditor { //当打开Unity工程或脚本需要重新编译时,此构造方法会被执行 static VersionCheckEditor() { string version = PlayerSettings.bundleVersion; int bundleVersionCode = PlayerSettings.Android.bundleVersionCode; string code = "public static class VersionInfo \n{\n"; code += String.Format("\tpublic static readonly string version = \"{0}\";\n", version); code += String.Format("\tpublic static readonly string bundleVersionCode = {0};\n", bundleVersionCode); code += "}"; //保存路径根据实际项目填写 string targetCodeFile = string.Format("{0}/Scripts/Util/VersionInfo.cs", Application.dataPath); Debug.LogFormat("Auto generate code: {0}", targetCodeFile); File.WriteAllText(targetCodeFile, code); } }