Last active
April 1, 2019 21:59
-
-
Save chatpongs/b587136facf49043bd31963d07cc24fd to your computer and use it in GitHub Desktop.
Unity C# script to let Unity Cloud Build create bundles and upload them to some server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.Callbacks; | |
using AssetBundles; // Require AssetBundleManager available here https://www.assetstore.unity3d.com/en/#!/content/45836 | |
// Place this file in Editor filder | |
public class CloudBundle{ | |
[PostProcessBuildAttribute(1)] | |
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { | |
string assetbundleDir = Path.Combine(System.Environment.CurrentDirectory, Utility.AssetBundlesOutputPath); | |
string platformDir = Path.Combine(assetbundleDir, Utility.GetPlatformName()); | |
BuildScript.BuildAssetBundles(); | |
WWWForm form = new WWWForm(); | |
string [] fileEntries = Directory.GetFiles(platformDir); | |
foreach(string file in fileEntries) | |
{ | |
string fileName = Path.GetFileName(file); | |
form.AddBinaryData(fileName, File.ReadAllBytes(file), fileName); | |
} | |
string remoteUrl = "http://your/server"; | |
WWW www = new WWW(remoteUrl, form); | |
while(!www.isDone); | |
if (!string.IsNullOrEmpty(www.error)) | |
{ | |
Debug.Log("WWW failed: " + www.error); | |
} | |
else | |
{ | |
Debug.Log("WWW result: " + www.text); | |
} | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment