diff --git a/Editor/Upload/UploadItch.cs b/Editor/Upload/UploadItch.cs new file mode 100644 index 0000000..6d9940c --- /dev/null +++ b/Editor/Upload/UploadItch.cs @@ -0,0 +1,135 @@ +using UnityEngine; +using UnityEditor; +using System.IO; + +namespace UnityBuild +{ + +public class UploadItch : PostBuildAction +{ + private const string WINDOWS = "windows"; + private const string OSX = "osx"; + private const string LINUX = "linux"; + + #region MenuItems + + [MenuItem("Build/Upload/itch.io/Execute", false, 50)] + private static void UploadAll() + { + for (int i = 0; i < BuildProject.platforms.Count; i++) + { + BuildPlatform platform = BuildProject.platforms[i]; + PerformUpload(platform); + } + } + + [MenuItem("Build/Upload/itch.io/Auto Upload")] + private static void ToggleAutoUpload() + { + EditorPrefs.SetBool("buildUploadItchAuto", !EditorPrefs.GetBool("buildUploadItchAuto", false)); + } + + [MenuItem("Build/Upload/itch.io/Auto Upload", true)] + private static bool ToggleAutoUploadValidate() + { + Menu.SetChecked("Build/Upload/itch.io/Auto Upload", EditorPrefs.GetBool("buildUploadItchAuto", false)); + return true; + } + + #endregion + + #region Public Methods + + public override void Execute(BuildPlatform platform) + { + if (EditorPrefs.GetBool("buildUploadItchAuto", false)) + PerformUpload(platform); + } + + #endregion + + #region Private Methods + + private static void PerformUpload(BuildPlatform platform) + { + if (!platform.buildEnabled) + return; + + string absolutePath = Path.GetFullPath(platform.buildPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + if (File.Exists(absolutePath)) + { + Debug.Log("UploadItch: Upload Failed - Build does not exist for platform " + platform.name + " - " + absolutePath); + return; + } + + string channel = GetChannelName(platform.target); + if (string.IsNullOrEmpty(channel)) + { + Debug.Log("UploadItch: Upload Failed - Unknown platform " + platform.name); + return; + } + + string arguments = "push \"" + absolutePath + "\" " + UploadItchSettings.itchUserName + "/" + UploadItchSettings.itchGameName + ":" + channel; + + if (!string.IsNullOrEmpty(UploadItchSettings.versionNumber)) + { + arguments += "--userversion " + UploadItchSettings.versionNumber; + } + + System.Diagnostics.Process uploadProc = new System.Diagnostics.Process(); + uploadProc.StartInfo.FileName = UploadItchSettings.butlerPath; + uploadProc.StartInfo.Arguments = + arguments; + uploadProc.StartInfo.CreateNoWindow = false; + uploadProc.StartInfo.UseShellExecute = false; + uploadProc.Start(); + } + + private static string GetChannelName(BuildTarget target) + { + switch (target) + { + // Windows + case BuildTarget.StandaloneWindows: + return WINDOWS + "-x86"; + case BuildTarget.StandaloneWindows64: + return WINDOWS + "-x64"; + + // Linux + case BuildTarget.StandaloneLinux: + return LINUX + "-x86"; + case BuildTarget.StandaloneLinux64: + return LINUX + "-x64"; + case BuildTarget.StandaloneLinuxUniversal: + return LINUX + "-universal"; + + // OSX + case BuildTarget.StandaloneOSXIntel: + return OSX + "-intel"; + case BuildTarget.StandaloneOSXIntel64: + return OSX + "-intel64"; + case BuildTarget.StandaloneOSXUniversal: + return OSX + "-universal"; + + default: + return null; + } + } + + #endregion + + #region Public Properties + + public override int priority + { + get + { + return 1000; + } + } + + #endregion +} + +} \ No newline at end of file diff --git a/Editor/Upload/UploadItch.cs.meta b/Editor/Upload/UploadItch.cs.meta new file mode 100644 index 0000000..4d49550 --- /dev/null +++ b/Editor/Upload/UploadItch.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 97d88f7d353534a4fbdeb11196057db7 +timeCreated: 1461244919 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Upload/UploadItchSettings.cs b/Editor/Upload/UploadItchSettings.cs new file mode 100644 index 0000000..17206b3 --- /dev/null +++ b/Editor/Upload/UploadItchSettings.cs @@ -0,0 +1,49 @@ +using UnityEngine; +using UnityEditor; + +public class UploadItchSettings +{ + #region Constants + + private const string _butlerPath = @"D:\User\Chase\Downloads\game-dev\butler\butler.exe"; + private const string _itchUserName = "supersystems"; + private const string _itchGameName = "butler-test"; + + #endregion + + #region Public Properties + + public static string versionNumber + { + get + { + return string.Empty; + } + } + + public static string butlerPath + { + get + { + return _butlerPath; + } + } + + public static string itchUserName + { + get + { + return _itchUserName; + } + } + + public static string itchGameName + { + get + { + return _itchGameName; + } + } + + #endregion +} \ No newline at end of file diff --git a/Editor/Upload/UploadItchSettings.cs.meta b/Editor/Upload/UploadItchSettings.cs.meta new file mode 100644 index 0000000..425ba5d --- /dev/null +++ b/Editor/Upload/UploadItchSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 438393e651c4f1542a0219910e455f7b +timeCreated: 1462337906 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Upload/blank.txt b/Editor/Upload/blank.txt deleted file mode 100644 index e69de29..0000000 diff --git a/Editor/Upload/blank.txt.meta b/Editor/Upload/blank.txt.meta deleted file mode 100644 index b49c515..0000000 --- a/Editor/Upload/blank.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a9151b86424841b4391466a6b76ff5de -timeCreated: 1461103576 -licenseType: Pro -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: