游戏版本号检测

作者:追风剑情 发布于:2022-1-7 12:05 分类:Unity3d

一、在游戏代码中记录版本号,方便获取

  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. using UnityEditor;
  5. /// <summary>
  6. /// 自动在代码中记录 verion、bundleVersionCode
  7. /// 参考 https://blog.csdn.net/zxsean/article/details/52117146
  8. /// 将此脚本放到Editor目录下
  9. /// </summary>
  10. [InitializeOnLoad]
  11. public class VersionCheckEditor
  12. {
  13. //当打开Unity工程或脚本需要重新编译时,此构造方法会被执行
  14. static VersionCheckEditor()
  15. {
  16. string version = PlayerSettings.bundleVersion;
  17. int bundleVersionCode = PlayerSettings.Android.bundleVersionCode;
  18.  
  19. string code = "public static class VersionInfo \n{\n";
  20. code += String.Format("\tpublic static readonly string version = \"{0}\";\n", version);
  21. code += String.Format("\tpublic static readonly string bundleVersionCode = {0};\n", bundleVersionCode);
  22. code += "}";
  23.  
  24. //保存路径根据实际项目填写
  25. string targetCodeFile = string.Format("{0}/Scripts/Util/VersionInfo.cs", Application.dataPath);
  26. Debug.LogFormat("Auto generate code: {0}", targetCodeFile);
  27.  
  28. File.WriteAllText(targetCodeFile, code);
  29. }
  30. }


标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号