/// <summary> /// Get field by name /// </summary> /// <param name="extraFields">Array of fields</param> /// <param name="token">Field name</param> /// <returns>Field or null</returns> private static OnlineMapsProvider.ExtraField GetExtraField(OnlineMapsProvider.IExtraField[] extraFields, string token) { if (extraFields == null) { return(null); } // Iterate each field foreach (var field in extraFields) { // If this is a field, compare it token if (field is OnlineMapsProvider.ExtraField) { OnlineMapsProvider.ExtraField f = field as OnlineMapsProvider.ExtraField; if (f.token == token) { return(f); } } // If this is group, check group fields else if (field is OnlineMapsProvider.ToggleExtraGroup) { var res = GetExtraField((field as OnlineMapsProvider.ToggleExtraGroup).fields, token); if (res != null) { return(res); } } } return(null); }
/// <summary> /// Draws UI elements using IMGUI /// </summary> private void OnGUI() { if (GUILayout.Button("Set DigitalGlobe")) { // Switch to DigitalGlobe / Satellite string mapTypeID = "digitalglobe.satellite"; OnlineMaps.instance.mapType = mapTypeID; // Get map type OnlineMapsProvider.MapType mapType = OnlineMapsProvider.FindMapType(mapTypeID); // Try get access token field from map type OnlineMapsProvider.ExtraField field = GetExtraField(mapType.extraFields, "accesstoken"); // If the field is not in the map type, try to get it from the provider if (field == null) { field = GetExtraField(mapType.provider.extraFields, "accesstoken"); } // If the field is present, set value if (field != null) { field.value = "My DigitalGlobe Token"; } } }
private void DrawProviderExtraField(OnlineMapsProvider.ExtraField field, ref bool dirty) { EditorGUI.BeginChangeCheck(); field.value = EditorGUILayout.TextField(field.title, field.value); if (EditorGUI.EndChangeCheck()) { dirty = true; } }
private void DrawProviderExtraField(OnlineMapsProvider.ExtraField field) { field.value = EditorGUILayout.TextField(field.title, field.value); }
private void DrawMapTypes(ref bool dirty) { if (control != null && !control.useRasterTiles) { return; } if (pSource.enumValueIndex == (int)OnlineMapsSource.Resources) { return; } if (pSource.enumValueIndex == (int)OnlineMapsSource.StreamingAssets) { return; } DrawProviderGUI(); if (mapType.provider.types.Length > 1) { GUIContent[] availableTypes = mapType.provider.types.Select(t => new GUIContent(t.title)).ToArray(); int index = mapType.index; EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); index = EditorGUILayout.Popup(new GUIContent("Type", "Type of map texture"), index, availableTypes); if (EditorGUI.EndChangeCheck()) { mapType = mapType.provider.types[index]; pMapType.stringValue = mapType.ToString(); } OnlineMapsEditorUtils.HelpButton("Type (style) of the map"); EditorGUILayout.EndHorizontal(); } DrawProviderExtraFields(ref dirty, mapType.provider.extraFields); DrawProviderExtraFields(ref dirty, mapType.extraFields); if (mapType.fullID == "google.satellite") { if (GUILayout.Button("Detect the latest version of tiles")) { WebClient client = new WebClient(); string response = client.DownloadString("http://maps.googleapis.com/maps/api/js"); Match match = Regex.Match(response, @"kh\?v=(\d+)"); if (match.Success) { OnlineMapsProvider.ExtraField version = mapType.extraFields.FirstOrDefault(f => { OnlineMapsProvider.ExtraField ef = f as OnlineMapsProvider.ExtraField; if (ef == null) { return(false); } if (ef.token != "version") { return(false); } return(true); }) as OnlineMapsProvider.ExtraField; if (version != null) { version.value = match.Groups[1].Value; } } } } DrawLabelsGUI(); }