17 #region Vuforia_lifecycle_events 21 if (initError != VuforiaUnity.InitError.INIT_SUCCESS)
23 SetErrorCode(initError);
24 SetErrorOccurred(
true);
28 #endregion // Vuforia_lifecycle_events 30 #region PRIVATE_MEMBER_VARIABLES 32 string mErrorText =
"";
35 const string headerLabel =
"Vuforia Initialization Error";
41 Texture2D bodyTexture;
42 Texture2D headerTexture;
43 Texture2D footerTexture;
45 #endregion // PRIVATE_MEMBER_VARIABLES 47 #region UNTIY_MONOBEHAVIOUR_METHODS 64 GUI.Window(0,
new Rect(0, 0, Screen.width, Screen.height), DrawWindowContent,
"");
75 #endregion // UNTIY_MONOBEHAVIOUR_METHODS 77 #region PRIVATE_METHODS 79 void DrawWindowContent(
int id)
81 var headerRect =
new Rect(0, 0, Screen.width, Screen.height / 8);
82 var bodyRect =
new Rect(0, Screen.height / 8, Screen.width, Screen.height / 8 * 6);
83 var footerRect =
new Rect(0, Screen.height - Screen.height / 8, Screen.width, Screen.height / 8);
85 GUI.Label(headerRect, headerLabel, headerStyle);
86 GUI.Label(bodyRect, mErrorText, bodyStyle);
88 if (GUI.Button(footerRect,
"Close", footerStyle))
98 void SetErrorCode(VuforiaUnity.InitError errorCode)
102 case VuforiaUnity.InitError.INIT_EXTERNAL_DEVICE_NOT_DETECTED:
104 "Failed to initialize Vuforia because this " +
105 "device is not docked with required external hardware.";
107 case VuforiaUnity.InitError.INIT_LICENSE_ERROR_MISSING_KEY:
109 "Vuforia App key is missing. Please get a valid key " +
110 "by logging into your account at developer.vuforia.com " +
111 "and creating a new project.";
113 case VuforiaUnity.InitError.INIT_LICENSE_ERROR_INVALID_KEY:
115 "Vuforia App key is invalid. " +
116 "Please get a valid key by logging into your account at " +
117 "developer.vuforia.com and creating a new project. \n\n" +
120 case VuforiaUnity.InitError.INIT_LICENSE_ERROR_NO_NETWORK_TRANSIENT:
121 mErrorText =
"Unable to contact server. Please try again later.";
123 case VuforiaUnity.InitError.INIT_LICENSE_ERROR_NO_NETWORK_PERMANENT:
124 mErrorText =
"No network available. Please make sure you are connected to the Internet.";
126 case VuforiaUnity.InitError.INIT_LICENSE_ERROR_CANCELED_KEY:
128 "This App license key has been cancelled and may no longer be used. " +
129 "Please get a new license key. \n\n" +
132 case VuforiaUnity.InitError.INIT_LICENSE_ERROR_PRODUCT_TYPE_MISMATCH:
134 "Vuforia App key is not valid for this product. Please get a valid key " +
135 "by logging into your account at developer.vuforia.com and choosing the " +
136 "right product type during project creation. \n\n" +
137 getKeyInfo() +
" \n\n" +
138 "Note that Universal Windows Platform (UWP) apps require " +
139 "a license key created on or after August 9th, 2016.";
141 case VuforiaUnity.InitError.INIT_NO_CAMERA_ACCESS:
143 "User denied Camera access to this app.\n" +
144 "To restore, enable Camera access in Settings:\n" +
145 "Settings > Privacy > Camera > " + Application.productName +
"\n" +
146 "Also verify that the Camera is enabled in:\n" +
147 "Settings > General > Restrictions.";
149 case VuforiaUnity.InitError.INIT_DEVICE_NOT_SUPPORTED:
150 mErrorText =
"Failed to initialize Vuforia because this device is not supported.";
152 case VuforiaUnity.InitError.INIT_ERROR:
153 mErrorText =
"Failed to initialize Vuforia.";
158 mErrorText =
"<color=red>" + errorCode.ToString().Replace(
"_",
" ") +
"</color>\n\n" + mErrorText;
161 var errorTextConsole = mErrorText.Replace(
"<color=red>",
"").Replace(
"</color>",
"");
163 Debug.LogError(
"Vuforia initialization failed: " + errorCode +
"\n\n" + errorTextConsole);
166 void SetErrorOccurred(
bool errorOccurred)
168 mErrorOccurred = errorOccurred;
173 string key = VuforiaConfiguration.Instance.Vuforia.LicenseKey;
177 "Your current key is <color=red>" + key.Length +
"</color> characters in length. " +
178 "It begins with <color=red>" + key.Substring(0, 5) +
"</color> " +
179 "and ends with <color=red>" + key.Substring(key.Length - 5, 5) +
"</color>.";
182 "Your current key is <color=red>" + key.Length +
"</color> characters in length. \n" +
183 "The key is: <color=red>" + key +
"</color>.";
187 void SetupGUIStyles()
190 var shortSidePixels = Screen.width < Screen.height ? Screen.width : Screen.height;
191 var shortSideInches = shortSidePixels / Screen.dpi;
192 var physicalSizeMultiplier = shortSideInches > 4.0f ? 2 : 1;
195 bodyTexture = CreateSinglePixelTexture(Color.white);
196 headerTexture = CreateSinglePixelTexture(
new Color(
197 Mathf.InverseLerp(0, 255, 220),
198 Mathf.InverseLerp(0, 255, 220),
199 Mathf.InverseLerp(0, 255, 220)));
200 footerTexture = CreateSinglePixelTexture(
new Color(
201 Mathf.InverseLerp(0, 255, 35),
202 Mathf.InverseLerp(0, 255, 178),
203 Mathf.InverseLerp(0, 255, 0)));
206 bodyStyle =
new GUIStyle();
207 bodyStyle.normal.background = bodyTexture;
208 bodyStyle.font = Resources.GetBuiltinResource<Font>(
"Arial.ttf");
209 bodyStyle.fontSize = (int) (18 * physicalSizeMultiplier * Screen.dpi / 160);
210 bodyStyle.normal.textColor = Color.black;
211 bodyStyle.wordWrap =
true;
212 bodyStyle.alignment = TextAnchor.MiddleCenter;
213 bodyStyle.padding =
new RectOffset(40, 40, 0, 0);
216 headerStyle =
new GUIStyle(bodyStyle);
217 headerStyle.normal.background = headerTexture;
218 headerStyle.fontSize = (int) (24 * physicalSizeMultiplier * Screen.dpi / 160);
221 footerStyle =
new GUIStyle(bodyStyle);
222 footerStyle.normal.background = footerTexture;
223 footerStyle.normal.textColor = Color.white;
224 footerStyle.fontSize = (int) (28 * physicalSizeMultiplier * Screen.dpi / 160);
227 Texture2D CreateSinglePixelTexture(Color color)
230 var texture =
new Texture2D(1, 1, TextureFormat.ARGB32,
false);
231 texture.SetPixel(0, 0, color);
236 #endregion // PRIVATE_METHODS void OnVuforiaInitializationError(VuforiaUnity.InitError initError)
A custom handler that registers for Vuforia initialization errors