-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuildInformation.cs
More file actions
81 lines (75 loc) · 2.33 KB
/
Copy pathBuildInformation.cs
File metadata and controls
81 lines (75 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.IO;
using UnityEngine;
namespace CustomBuilder
{
[CreateAssetMenu(menuName = "Custom/BuildInformation")]
public class BuildInformation : ScriptableObject
{
public const string FileName = "BuildInfo";
[SerializeField]
string version;
public string Version
{
get { return version; }
set { version = value; }
}
[SerializeField]
string buildDate;
public string BuildDate
{
get { return buildDate; }
set { buildDate = value; }
}
public void Reset()
{
version = "";
buildDate = "";
}
public BuildInformation()
{
this.Reset();
}
public void SetDummyVersion(string version)
{
this.version = version;
buildDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
static BuildInformation _instance;
public static BuildInformation Instance
{
get
{
if (_instance == null)
{
_instance = Resources.Load<BuildInformation>(FileName);
}
// 如果没有正确的打包信息,那就只能尝试用工作目录的,或者是用程序内置的版本信息
if (_instance == null)
{
string version = Application.version;
#if UNITY_EDITOR
try
{
var currentDir = Directory.GetCurrentDirectory();
var gitDir = Path.Combine(currentDir, ".git");
if (Directory.Exists(gitDir))
{
GitDescriber git = new GitDescriber(gitDir);
version = git.Describe();
}
}
catch (Exception e)
{
Debug.LogError("读取Git描述失败:" + e);
version = Application.version;
}
#endif
_instance = CreateInstance<BuildInformation>();
_instance.SetDummyVersion(version);
}
return _instance;
}
}
}
}