Skip to content

Instantly share code, notes, and snippets.

@chatpongs
Last active April 1, 2019 21:59
Show Gist options
  • Save chatpongs/b587136facf49043bd31963d07cc24fd to your computer and use it in GitHub Desktop.
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
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