From cf7dbefb94a49ff2049eae3855d18f7067a3f03c Mon Sep 17 00:00:00 2001 From: Chuan Liu Date: Mon, 13 Nov 2017 12:46:55 +0000 Subject: [PATCH] Build Version is now optional. --- Utils/BuildVersion.cs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Utils/BuildVersion.cs b/Utils/BuildVersion.cs index c24596f..902f7ca 100644 --- a/Utils/BuildVersion.cs +++ b/Utils/BuildVersion.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR && ENABLE_BUILD_VERSION using UnityEditor; using UnityEditor.Build; #endif @@ -8,35 +8,30 @@ namespace DUCK.Utils { public class BuildVersion : ScriptableObject { - internal const string AssetPath = "BuildVersion"; + internal const string ASSET_NAME = "BuildVersion"; - public string DateStamp = "debug/Editor"; + public string dateStamp = "debug/Editor"; -#if UNITY_EDITOR +#if UNITY_EDITOR && ENABLE_BUILD_VERSION public void UpdateForNewBuild() { - DateStamp = System.DateTime.Now.ToString("dd/MM/yyyy"); + dateStamp = System.DateTime.Now.ToString("dd/MM/yyyy"); } #endif private static BuildVersion buildVersion; public static BuildVersion GetBuildVersion() { - if (buildVersion == null) - { - buildVersion = (Resources.Load(AssetPath) as BuildVersion) ?? CreateInstance(); - } - - return buildVersion; + return buildVersion ?? (buildVersion = Resources.Load(ASSET_NAME) as BuildVersion ?? CreateInstance()); } public override string ToString() { - return DateStamp; + return dateStamp; } } -#if UNITY_EDITOR +#if UNITY_EDITOR && ENABLE_BUILD_VERSION public class BuildVersionAutoIncrement : IPreprocessBuild { public int callbackOrder { get { return 0; } } @@ -45,8 +40,8 @@ public void OnPreprocessBuild(BuildTarget target, string path) { const string root = "Assets"; const string folder = "Resources"; - const string folderPath = root + "/" + folder + "/"; - const string fullPath = folderPath + BuildVersion.AssetPath + ".asset"; + const string folderPath = root + "/" + folder; + const string fullPath = folderPath + "/" + BuildVersion.ASSET_NAME + ".asset"; var buildVersion = ScriptableObject.CreateInstance(); buildVersion.UpdateForNewBuild();