Skip to content

Instantly share code, notes, and snippets.

@tim-hub
Created August 26, 2016 04:07
Show Gist options
  • Save tim-hub/d159e3e0e8087fe7586c6d36d5c7a649 to your computer and use it in GitHub Desktop.
Save tim-hub/d159e3e0e8087fe7586c6d36d5c7a649 to your computer and use it in GitHub Desktop.
This script is for vuforia to set the vuforia api key.

If you want to set the key, but not want to share the key to the public, you need this.

  1. put it on ARCamera, and give it the first priority in components
  2. put your key as apiKey.txt file in Builds folder
using UnityEngine;
using System.Collections;
using Vuforia;
using System.IO;
public class ARKeySetter : MonoBehaviour {
// Use this for initialization
void Awake(){
#if UNITY_EDITOR
Debug.Log("start to read and set key");
string apiKey = ReadKey();
GetComponent<VuforiaBehaviour> ().SetAppLicenseKey (apiKey);
#endif
}
string ReadKey(){
string keyLocation="Builds/apiKey.txt";
if (File.Exists (keyLocation)) {
Debug.Log ("there is a file");
return File.ReadAllText (keyLocation);
} else {
Debug.LogError("Apply key on developer.vuforia.com, " +
"and creat a apiKey.txt in Builds folder, and paste it to the txt file");
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment