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.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
/// <summary> | |
/// Attach this script to objects that has a CanvasScaler component. | |
/// | |
/// This makes sure the UI enlarges/shrinks when the device resolution changes. | |
/// |
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; | |
using System.Collections.Generic; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using System.Net.Http.Headers; | |
/// <summary> | |
/// This function fires an Http Get call and get the raw resoonse in string | |
/// </summary> | |
/// <param name="base_url">e.g. new Uri("https://api.mobile.azure.com/"); </param> |
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
internal static Bounds GetBound(GameObject go) | |
{ | |
Bounds b = new Bounds(go.transform.position, Vector3.zero); | |
var rList = go.GetComponentsInChildren(typeof(Renderer)); | |
foreach (Renderer r in rList) | |
{ | |
b.Encapsulate(r.bounds); | |
} | |
return b; | |
} |
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
public static string RunCommand(string Command) | |
{ | |
Process p = new Process(); | |
p.StartInfo.FileName = "cmd.exe"; | |
p.StartInfo.Arguments = "/C " + Command; //e.g. Command = "dir" | |
p.StartInfo.CreateNoWindow = true; //important | |
p.StartInfo.UseShellExecute = false; | |
p.StartInfo.RedirectStandardOutput = true; | |
p.StartInfo.RedirectStandardError = true; | |
p.Start(); |
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
var React = require('react'); | |
var Foo = require('Foo'); | |
/** | |
* General component description, for instance use below description | |
* | |
* The button component represents generic button UI control with | |
* an image and a title sting. | |
* | |
* props: |
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
public static string SerializeObject<T> (T objectToSerialize) | |
{ | |
XmlSerializer xmlSerializer = new XmlSerializer (objectToSerialize.GetType ()); | |
using (StringWriter textWriter = new StringWriter ()) { | |
xmlSerializer.Serialize (textWriter, objectToSerialize); | |
return textWriter.ToString (); | |
} | |
} | |
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
/** | |
* Get version number from build.gradle | |
* You might also use BuildConfig.VERSION_CODE to see if this works | |
* @return version code integer | |
*/ | |
public static int getAppVersionCode() { | |
if (context == null) return -1; | |
PackageManager packageManager = context.getPackageManager(); | |
int versionCode = -1; | |
try { |
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
private static Activity getForegroundActivity(){ | |
Activity activity = null; | |
try { | |
Class activityThreadClass = Class.forName("android.app.ActivityThread"); | |
Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null); | |
Field activitiesField = activityThreadClass.getDeclaredField("mActivities"); | |
activitiesField.setAccessible(true); | |
Map<Object, Object> activities = (Map<Object, Object>) activitiesField.get(activityThread); | |
if(activities == null) |
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
// Example usage: | |
// new GetJsonTask().execute("https://api.stackexchange.com/2.2/info?site=stackoverflow&key=app key"); | |
class GetJsonTask extends AsyncTask<String, Void, String> { | |
private Exception exception; | |
protected String doInBackground(String... urls) { | |
try { | |
Request request = new Request.Builder() | |
.url(urls[0]) |
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
AsyncTask.execute(new Runnable() { | |
@Override | |
public void run() { | |
//DoSth() | |
} | |
}); |