Skip to content

Instantly share code, notes, and snippets.

@doggan
Forked from rcavallari/CloudBundle.cs
Created March 10, 2017 02:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doggan/08605b58771cf8caab6d292ab3b26e35 to your computer and use it in GitHub Desktop.
Save doggan/08605b58771cf8caab6d292ab3b26e35 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