|
| 1 | +using UnityEditor; |
| 2 | +using UnityEngine; |
| 3 | + |
| 4 | +namespace CesiumForUnity |
| 5 | +{ |
| 6 | + [CustomEditor(typeof(CesiumGoogleMapTilesRasterOverlay))] |
| 7 | + public class CesiumGoogleMapTilesRasterOverlayEditor : Editor |
| 8 | + { |
| 9 | + private CesiumRasterOverlayEditor _rasterOverlayEditor; |
| 10 | + |
| 11 | + private SerializedProperty _apiKey; |
| 12 | + private SerializedProperty _mapType; |
| 13 | + private SerializedProperty _language; |
| 14 | + private SerializedProperty _region; |
| 15 | + private SerializedProperty _scale; |
| 16 | + private SerializedProperty _highDpi; |
| 17 | + private SerializedProperty _layerTypes; |
| 18 | + private SerializedProperty _styles; |
| 19 | + private SerializedProperty _overlay; |
| 20 | + |
| 21 | + private string[] _scaleOptions; |
| 22 | + private int _selectedScaleIndex; |
| 23 | + |
| 24 | + private void OnEnable() |
| 25 | + { |
| 26 | + this._rasterOverlayEditor = |
| 27 | + (CesiumRasterOverlayEditor)Editor.CreateEditor( |
| 28 | + this.target, |
| 29 | + typeof(CesiumRasterOverlayEditor)); |
| 30 | + |
| 31 | + this._apiKey = this.serializedObject.FindProperty("_apiKey"); |
| 32 | + this._mapType = this.serializedObject.FindProperty("_mapType"); |
| 33 | + this._language = this.serializedObject.FindProperty("_language"); |
| 34 | + this._region = this.serializedObject.FindProperty("_region"); |
| 35 | + this._scale = this.serializedObject.FindProperty("_scale"); |
| 36 | + this._highDpi = this.serializedObject.FindProperty("_highDpi"); |
| 37 | + this._layerTypes = this.serializedObject.FindProperty("_layerTypes"); |
| 38 | + this._styles = this.serializedObject.FindProperty("_styles"); |
| 39 | + this._overlay = this.serializedObject.FindProperty("_overlay"); |
| 40 | + |
| 41 | + // Remove "ScaleFactor" prefix from the Scale enum options. |
| 42 | + int nameOffset = ("ScaleFactor").Length; |
| 43 | + this._scaleOptions = this._scale.enumNames; |
| 44 | + for (int i = 0; i < this._scaleOptions.Length; i++) |
| 45 | + { |
| 46 | + this._scaleOptions[i] = this._scaleOptions[i].Substring(nameOffset); |
| 47 | + } |
| 48 | + this._selectedScaleIndex = this._scale.enumValueIndex; |
| 49 | + } |
| 50 | + |
| 51 | + private void OnDisable() |
| 52 | + { |
| 53 | + if (this._rasterOverlayEditor != null) |
| 54 | + { |
| 55 | + DestroyImmediate(this._rasterOverlayEditor); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + public override void OnInspectorGUI() |
| 60 | + { |
| 61 | + this.serializedObject.Update(); |
| 62 | + |
| 63 | + EditorGUIUtility.labelWidth = CesiumEditorStyle.inspectorLabelWidth; |
| 64 | + this.DrawGoogleMapTilesProperties(); |
| 65 | + EditorGUILayout.Space(5); |
| 66 | + this.DrawRasterOverlayProperties(); |
| 67 | + |
| 68 | + this.serializedObject.ApplyModifiedProperties(); |
| 69 | + } |
| 70 | + |
| 71 | + private void DrawGoogleMapTilesProperties() |
| 72 | + { |
| 73 | + GUIContent apiKeyContent = new GUIContent( |
| 74 | + "API Key", |
| 75 | + "The Google Map Tiles API key to use."); |
| 76 | + EditorGUILayout.DelayedTextField(this._apiKey, apiKeyContent); |
| 77 | + |
| 78 | + GUIContent mapTypeContent = new GUIContent( |
| 79 | + "Map Type", |
| 80 | + "The type of base map."); |
| 81 | + EditorGUILayout.PropertyField(this._mapType, mapTypeContent); |
| 82 | + |
| 83 | + GUIContent languageContent = new GUIContent( |
| 84 | + "Language", |
| 85 | + "An IETF language tag that specifies the language used to display " + |
| 86 | + "information on the tiles. For example, `en-US` specifies the " + |
| 87 | + "English language as spoken in the United States."); |
| 88 | + EditorGUILayout.DelayedTextField(this._language, languageContent); |
| 89 | + |
| 90 | + GUIContent regionContent = new GUIContent( |
| 91 | + "Region", |
| 92 | + "A Common Locale Data Repository region identifier (two uppercase " + |
| 93 | + "letters) that represents the physical location of the user. For " + |
| 94 | + "example, `US`."); |
| 95 | + EditorGUILayout.DelayedTextField(this._region, regionContent); |
| 96 | + |
| 97 | + GUIContent scaleContent = new GUIContent( |
| 98 | + "Scale", |
| 99 | + "Scales-up the size of map elements (such as road labels), while " + |
| 100 | + "retaining the tile size and coverage area of the default tile." + |
| 101 | + "\n\n" + |
| 102 | + "Increasing the scale also reduces the number of labels on the map, " + |
| 103 | + "which reduces clutter."); |
| 104 | + this._selectedScaleIndex = |
| 105 | + EditorGUILayout.Popup(scaleContent, this._selectedScaleIndex, this._scaleOptions); |
| 106 | + this._scale.enumValueIndex = this._selectedScaleIndex; |
| 107 | + |
| 108 | + GUIContent highDpiContent = new GUIContent( |
| 109 | + "High DPI", |
| 110 | + "Specifies whether to return high-resolution tiles." + |
| 111 | + "\n\n" + |
| 112 | + "If the scale-factor is increased, High DPI is used to increase the " + |
| 113 | + "size of the tile. Normally, increasing the scale factor enlarges the " + |
| 114 | + "resulting tile into an image of the same size, which lowers quality. " + |
| 115 | + "With High DPI, the resulting size is also increased, preserving quality. " + |
| 116 | + "DPI stands for Dots per Inch, and High DPI means the tile renders using " + |
| 117 | + "more dots per inch than normal." + |
| 118 | + "\n\n" + |
| 119 | + "If enabled, the number of pixels in each of the x and y dimensions is " + |
| 120 | + "multiplied by the scale factor (that is, 2x or 4x). The coverage area " + |
| 121 | + "of the tile remains unchanged. This parameter works only with Scale " + |
| 122 | + "values of 2x or 4x. It has no effect on 1x scale tiles."); |
| 123 | + EditorGUILayout.PropertyField(this._highDpi, highDpiContent); |
| 124 | + |
| 125 | + GUIContent layerTypesContent = new GUIContent( |
| 126 | + "Layer Types", |
| 127 | + "The layer types to be added to the map."); |
| 128 | + EditorGUILayout.PropertyField(this._layerTypes, layerTypesContent); |
| 129 | + |
| 130 | + GUIContent stylesContent = new GUIContent( |
| 131 | + "Styles", |
| 132 | + "A list of JSON style objects that specify the appearance and detail " + |
| 133 | + "level of map features such as roads, parks, and built-up areas." + |
| 134 | + "\n\n" + |
| 135 | + "Styling is used to customize the standard Google base map. The Styles " + |
| 136 | + "parameter is valid only if the Map Type is Roadmap."); |
| 137 | + EditorGUILayout.PropertyField(this._styles, stylesContent); |
| 138 | + |
| 139 | + GUIContent overlayContent = new GUIContent( |
| 140 | + "Overlay", |
| 141 | + "Specifies whether Layer Types are rendered as a separate overlay, or " + |
| 142 | + "combined with the base imagery." + |
| 143 | + "\n\n" + |
| 144 | + "When enabled, the base map isn't displayed. If you haven't defined any " + |
| 145 | + "Layer Types, then this value is ignored."); |
| 146 | + EditorGUILayout.PropertyField(this._overlay, overlayContent); |
| 147 | + |
| 148 | + GUILayout.BeginHorizontal(); |
| 149 | + GUILayout.FlexibleSpace(); |
| 150 | + if (EditorGUILayout.LinkButton("Map Tiles API Style reference")) |
| 151 | + { |
| 152 | + Application.OpenURL("https://developers.google.com/maps/documentation/tile/style-reference"); |
| 153 | + } |
| 154 | + GUILayout.FlexibleSpace(); |
| 155 | + GUILayout.EndHorizontal(); |
| 156 | + } |
| 157 | + |
| 158 | + private void DrawRasterOverlayProperties() |
| 159 | + { |
| 160 | + if (this._rasterOverlayEditor != null) |
| 161 | + { |
| 162 | + this._rasterOverlayEditor.OnInspectorGUI(); |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments