Skip to content

Instantly share code, notes, and snippets.

@ProtoJazz
Created July 26, 2015 04:13
Show Gist options
  • Select an option

  • Save ProtoJazz/f3db2a6ed50fd7eeb472 to your computer and use it in GitHub Desktop.

Select an option

Save ProtoJazz/f3db2a6ed50fd7eeb472 to your computer and use it in GitHub Desktop.
Unity3D NotifyMyAndroid Integration
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class BuildAndNotify : MonoBehaviour
{
private static string URL = "https://www.notifymyandroid.com/publicapi/notify";
private static string apiKey = "YOUR API KEY HEERE!!!!";
//private static string toolName = "Super Awesome Tool of Ultimate Usefullness";
private const string toolName = "Build and Notify";
[MenuItem(toolName+"/WindowsBuild")]
public static void BuildWindows()
{
BuildGame(BuildTarget.StandaloneWindows);
}
[MenuItem(toolName + "/AndroidBuild")]
public static void BuildAndroid()
{
BuildGame(BuildTarget.Android);
}
[MenuItem(toolName + "/IOSBuild")]
public static void BuildIOS()
{
BuildGame(BuildTarget.iOS);
}
[MenuItem(toolName + "/WebPlayerBuild")]
public static void BuildWebplayer()
{
BuildGame(BuildTarget.WebPlayer);
}
public static void BuildGame(BuildTarget target)
{
// Get filename.
string path = EditorUtility.SaveFolderPanel("Choose Location of Built Game", "", "");
string[] levels = new string[] { "Assets/MainMenu.unity","YOUR LEVELS / SCENES HERE!"};
// Build player.
BuildPipeline.BuildPlayer(levels, path + "/BuiltGame",target, BuildOptions.None);
Dictionary<string, string> notifyParams = new Dictionary<string, string>();
notifyParams["apikey"] = apiKey;
notifyParams["application"] = GetProjectName();
notifyParams["event"] = "Build is done, master";
notifyParams["description"] = "The " + target.ToString() + " build you requested is done!";
POST(URL, notifyParams);
}
private static WWW POST(string url, Dictionary<string, string> post)
{
WWWForm form = new WWWForm();
foreach (KeyValuePair<string, string> post_arg in post)
{
form.AddField(post_arg.Key, post_arg.Value);
}
WWW www = new WWW(url, form);
return www;
}
private static string GetProjectName()
{
string[] s = Application.dataPath.Split('/');
string projectName = s[s.Length - 2];
return projectName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment