51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
using UnityEngine;
|
|||
|
|
|
||
|
|
// Версия игры на экране (05.11, требование Миши: в каждом билде видно, что это за версия).
|
||
|
|
// В углу экрана: версия из Player Settings (Application.version) и сборка -- ветка, коммит, дата.
|
||
|
|
// Сборку пишет Editor/BuildInfoWriter перед билдом в Resources/BuildInfo.txt; в редакторе -- "редактор".
|
||
|
|
// Создаётся сам при запуске, живёт между сценами.
|
||
|
|
public class GameVersionLabel : MonoBehaviour
|
||
|
|
{
|
||
|
|
static GameVersionLabel instance;
|
||
|
|
string text;
|
||
|
|
GUIStyle style, shadow;
|
||
|
|
|
||
|
|
public static string BuildInfo
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
var asset = Resources.Load<TextAsset>("BuildInfo");
|
||
|
|
return asset != null ? asset.text.Trim() : "редактор";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public static string FullVersion => $"v{Application.version} • {BuildInfo}";
|
||
|
|
|
||
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
|
||
|
|
static void Create()
|
||
|
|
{
|
||
|
|
if (instance != null) return;
|
||
|
|
var go = new GameObject("GameVersionLabel");
|
||
|
|
DontDestroyOnLoad(go);
|
||
|
|
instance = go.AddComponent<GameVersionLabel>();
|
||
|
|
instance.text = FullVersion;
|
||
|
|
Debug.Log("[ВЕРСИЯ] " + instance.text);
|
||
|
|
}
|
||
|
|
|
||
|
|
void OnGUI()
|
||
|
|
{
|
||
|
|
if (style == null)
|
||
|
|
{
|
||
|
|
int size = Mathf.Max(12, Screen.height / 60);
|
||
|
|
style = new GUIStyle(GUI.skin.label) { fontSize = size, alignment = TextAnchor.LowerLeft };
|
||
|
|
style.normal.textColor = new Color(1f, 1f, 1f, 0.75f);
|
||
|
|
shadow = new GUIStyle(style);
|
||
|
|
shadow.normal.textColor = new Color(0f, 0f, 0f, 0.6f);
|
||
|
|
}
|
||
|
|
GUI.depth = -1000; // поверх всего
|
||
|
|
var r = new Rect(8, Screen.height - style.fontSize * 2 - 4, Screen.width * 0.6f, style.fontSize * 2);
|
||
|
|
GUI.Label(new Rect(r.x + 1, r.y + 1, r.width, r.height), text, shadow);
|
||
|
|
GUI.Label(r, text, style);
|
||
|
|
}
|
||
|
|
}
|