[Unity]游戏内查看BundleVersion版本号.
来源:互联网 发布:TS是什么画图软件 编辑:程序博客网 时间:2024/06/11 05:27
转载自StackOverFlow
基本原理是[InitializeOnLoad]
在每次有变动完毕之后会执行BundleVersionChecker
在BundleVersionChecker中会自动判断版本号是否变更,如果变更会把新的版本号写入cs文件.
从而实现在游戏中获取版本号.
我直接贴代码吧
using System.IO;using UnityEditor;using UnityEngine;[InitializeOnLoad]public class BundleVersionChecker{ /// <summary> /// Class name to use when referencing from code. /// </summary> private const string ClassName = "CurrentBundleVersion"; // cs文件路径 private const string TargetCodeFile = "Assets/GameResources/Script/Config/" + ClassName + ".cs"; static BundleVersionChecker() { string bundleVersion = PlayerSettings.bundleVersion; string lastVersion = CurrentBundleVersion.version; if (lastVersion != bundleVersion) { Debug.Log("Found new bundle version " + bundleVersion + " replacing code from previous version " + lastVersion + " in file \"" + TargetCodeFile + "\""); CreateNewBuildVersionClassFile(bundleVersion); } } private static string CreateNewBuildVersionClassFile(string bundleVersion) { using (StreamWriter writer = new StreamWriter(TargetCodeFile, false)) { try { string code = GenerateCode(bundleVersion); writer.WriteLine("{0}", code); } catch (System.Exception ex) { string msg = " threw:\n" + ex.ToString(); Debug.LogError(msg); EditorUtility.DisplayDialog("Error when trying to regenerate class", msg, "OK"); } } return TargetCodeFile; } /// <summary> /// Regenerates (and replaces) the code for ClassName with new bundle version id. /// </summary> /// <returns> /// Code to write to file. /// </returns> /// <param name='bundleVersion'> /// New bundle version. /// </param> private static string GenerateCode(string bundleVersion) { string code = "public static class " + ClassName + "\n{\n"; code += System.String.Format("\tpublic static readonly string version = \"{0}\";", bundleVersion); code += "\n}\n"; return code; }}
// 另外一个文件public static class CurrentBundleVersion{ public static readonly string version = "0.8.5";}
实际调用
if (CurrentBundleVersion != "0.8.4"){ // do migration stuff}
0 0
- [Unity]游戏内查看BundleVersion版本号.
- iOS 获得版本号 区分BundleVersion和BundleShortVersionString
- iOS 获得版本号 区分BundleVersion和BundleShortVersionString
- unity打开内嵌游戏网页
- 查看版本号
- 【Unity】查看与显示游戏帧数FPS
- 查看Redhat版本号 /OpenGL版本号
- 获取unity当前版本号
- 获取unity当前版本号
- 查看linux操作系统版本号,查看glibc版本号
- unity 嵌入 百度分享 与 游戏内购物 iap
- Unity如何判断游戏对象是否在屏幕内
- 查看Ubuntu的版本号
- 如何查看linux版本号
- 查看open client 版本号
- 查看SQL版本号
- 查看windows详细版本号
- 查看Microsoft SQLerver版本号
- adb查看设备的时候,显示 List of devices attached
- iOS开发中单例设计模式、通知中心的使用
- scanf()、getch()、getchar()、getc()、gets()、gets_s()
- HDU-2089-不要62(数位DP)
- Android进阶之路-接口回调(一)
- [Unity]游戏内查看BundleVersion版本号.
- 价格计算工具类
- linux后台进程管理Supervisor
- leetcode[6] ZigZag Conversion
- JDK1.5/1.6/1.7之新特性(二)实践篇
- 随机数的最大值
- hdu 1075
- C++笔记-1(C++类型转换)
- CSS background属性