|
| 1 | +using System.Linq; |
| 2 | +using UnityEditor; |
| 3 | +using UnityEngine; |
| 4 | + |
| 5 | +namespace CesiumForUnity |
| 6 | +{ |
| 7 | + [CustomEditor(typeof(CesiumUrlTemplateRasterOverlay))] |
| 8 | + public class CesiumUrlTemplateRasterOverlayEditor : Editor |
| 9 | + { |
| 10 | + private static readonly (string Template, string Desc)[] TEMPLATE_PARAMS = new (string Template, string Desc)[] |
| 11 | + { |
| 12 | + ("x", "The tile X coordinate in the tiling scheme, where 0 is the westernmost tile."), |
| 13 | + ("y", "The tile Y coordinate in the tiling scheme, where 0 is the nothernmost tile."), |
| 14 | + ("z", "The level of the tile in the tiling scheme, where 0 is the root of the quadtree pyramid."), |
| 15 | + ("reverseX", "The tile X coordinate in the tiling scheme, where 0 is the easternmost tile."), |
| 16 | + ("reverseY", "The tile Y coordinate in the tiling scheme, where 0 is the southernmost tile."), |
| 17 | + ("reverseZ", "The tile Z coordinate in the tiling scheme, where 0 is equivalent to `maximumLevel`."), |
| 18 | + ("westDegrees", "The western edge of the tile in geodetic degrees."), |
| 19 | + ("southDegrees", "The southern edge of the tile in geodetic degrees."), |
| 20 | + ("eastDegrees", "The eastern edge of the tile in geodetic degrees."), |
| 21 | + ("northDegrees", "The northern edge of the tile in geodetic degrees."), |
| 22 | + ("minimumX", "The minimum X coordinate of the tile's projected coordinates."), |
| 23 | + ("minimumY", "The minimum Y coordinate of the tile's projected coordinates."), |
| 24 | + ("maximumX", "The maximum X coordinate of the tile's projected coordinates."), |
| 25 | + ("maximumY", "The maximum Y coordinate of the tile's projected coordinates."), |
| 26 | + ("width", "The width of each tile in pixels."), |
| 27 | + ("height", "The height of each tile in pixels.") |
| 28 | + }; |
| 29 | + |
| 30 | + private CesiumUrlTemplateRasterOverlay _urlTemplateRasterOverlay; |
| 31 | + private CesiumRasterOverlayEditor _rasterOverlayEditor; |
| 32 | + |
| 33 | + private SerializedProperty _templateUrl; |
| 34 | + private SerializedProperty _projection; |
| 35 | + private SerializedProperty _specifyTilingScheme; |
| 36 | + private SerializedProperty _rootTilesX; |
| 37 | + private SerializedProperty _rootTilesY; |
| 38 | + private SerializedProperty _rectangleWest; |
| 39 | + private SerializedProperty _rectangleSouth; |
| 40 | + private SerializedProperty _rectangleEast; |
| 41 | + private SerializedProperty _rectangleNorth; |
| 42 | + private SerializedProperty _minimumLevel; |
| 43 | + private SerializedProperty _maximumLevel; |
| 44 | + private SerializedProperty _tileWidth; |
| 45 | + private SerializedProperty _tileHeight; |
| 46 | + private SerializedProperty _requestHeaders; |
| 47 | + |
| 48 | + private bool _foldOut = false; |
| 49 | + |
| 50 | + private void OnEnable() |
| 51 | + { |
| 52 | + this._urlTemplateRasterOverlay = |
| 53 | + (CesiumUrlTemplateRasterOverlay)this.target; |
| 54 | + this._rasterOverlayEditor = |
| 55 | + (CesiumRasterOverlayEditor)Editor.CreateEditor( |
| 56 | + this.target, |
| 57 | + typeof(CesiumRasterOverlayEditor)); |
| 58 | + |
| 59 | + this._templateUrl = this.serializedObject.FindProperty("_templateUrl"); |
| 60 | + this._projection = this.serializedObject.FindProperty("_projection"); |
| 61 | + this._specifyTilingScheme = this.serializedObject.FindProperty("_specifyTilingScheme"); |
| 62 | + this._rootTilesX = this.serializedObject.FindProperty("_rootTilesX"); |
| 63 | + this._rootTilesY = this.serializedObject.FindProperty("_rootTilesY"); |
| 64 | + this._rectangleWest = this.serializedObject.FindProperty("_rectangleWest"); |
| 65 | + this._rectangleSouth = this.serializedObject.FindProperty("_rectangleSouth"); |
| 66 | + this._rectangleEast = this.serializedObject.FindProperty("_rectangleEast"); |
| 67 | + this._rectangleNorth = this.serializedObject.FindProperty("_rectangleNorth"); |
| 68 | + this._minimumLevel = this.serializedObject.FindProperty("_minimumLevel"); |
| 69 | + this._maximumLevel = this.serializedObject.FindProperty("_maximumLevel"); |
| 70 | + this._tileWidth = this.serializedObject.FindProperty("_tileWidth"); |
| 71 | + this._tileHeight = this.serializedObject.FindProperty("_tileHeight"); |
| 72 | + this._requestHeaders = this.serializedObject.FindProperty("_requestHeaders"); |
| 73 | + } |
| 74 | + |
| 75 | + private void OnDisable() |
| 76 | + { |
| 77 | + if (this._rasterOverlayEditor != null) |
| 78 | + { |
| 79 | + DestroyImmediate(this._rasterOverlayEditor); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + public override void OnInspectorGUI() |
| 84 | + { |
| 85 | + this.serializedObject.Update(); |
| 86 | + |
| 87 | + EditorGUIUtility.labelWidth = CesiumEditorStyle.inspectorLabelWidth; |
| 88 | + DrawUrlTemplateProperties(); |
| 89 | + EditorGUILayout.Space(5); |
| 90 | + DrawRasterOverlayProperties(); |
| 91 | + |
| 92 | + this.serializedObject.ApplyModifiedProperties(); |
| 93 | + } |
| 94 | + |
| 95 | + private void DrawUrlTemplateProperties() |
| 96 | + { |
| 97 | + EditorGUILayout.DelayedTextField(this._templateUrl, new GUIContent( |
| 98 | + "Template URL", |
| 99 | + @"The URL containing template parameters that will be substituted when loading tiles.")); |
| 100 | + this._foldOut = EditorGUILayout.BeginFoldoutHeaderGroup(this._foldOut, new GUIContent("Supported URL Parameters")); |
| 101 | + |
| 102 | + if (this._foldOut) |
| 103 | + { |
| 104 | + float maxLabelSize = TEMPLATE_PARAMS.Max(param => EditorStyles.boldLabel.CalcSize(new GUIContent("{" + param.Template + "}")).x); |
| 105 | + foreach (var (name, desc) in TEMPLATE_PARAMS) |
| 106 | + { |
| 107 | + EditorGUILayout.BeginHorizontal(); |
| 108 | + EditorGUILayout.LabelField("{" + name + "}", EditorStyles.boldLabel, GUILayout.Width(maxLabelSize)); |
| 109 | + EditorGUILayout.LabelField(desc, EditorStyles.wordWrappedLabel, GUILayout.ExpandHeight(true)); |
| 110 | + EditorGUILayout.EndHorizontal(); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + EditorGUILayout.EndFoldoutHeaderGroup(); |
| 115 | + |
| 116 | + EditorGUILayout.Space(5); |
| 117 | + |
| 118 | + EditorGUILayout.PropertyField( |
| 119 | + this._projection, |
| 120 | + new GUIContent("Projection", "The type of projection used to project the imagery onto the globe.")); |
| 121 | + |
| 122 | + EditorGUILayout.PropertyField( |
| 123 | + this._specifyTilingScheme, |
| 124 | + new GUIContent("Specify Tiling Scheme", |
| 125 | + "Set this to true to specify the quadtree tiling scheme according to the specified root tile" + |
| 126 | + "numbers and projected bounding rectangle. If false, the tiling scheme will be deduced from" + |
| 127 | + "the projection.")); |
| 128 | + |
| 129 | + EditorGUI.BeginDisabledGroup(!this._specifyTilingScheme.boolValue); |
| 130 | + GUIContent rootTilesXContent = new GUIContent( |
| 131 | + "Root Tiles X", |
| 132 | + "If specified, this determines the number of tiles at the root of the quadtree tiling scheme in the X direction."); |
| 133 | + EditorGUILayout.PropertyField(this._rootTilesX, rootTilesXContent); |
| 134 | + GUIContent rootTilesYContent = new GUIContent( |
| 135 | + "Root Tiles Y", |
| 136 | + "If specified, this determines the number of tiles at the root of the quadtree tiling scheme in the Y direction."); |
| 137 | + EditorGUILayout.PropertyField(this._rootTilesY, rootTilesYContent); |
| 138 | + |
| 139 | + CesiumInspectorGUI.ClampedDoubleField( |
| 140 | + this._rectangleWest, |
| 141 | + -180, 180, |
| 142 | + new GUIContent( |
| 143 | + "Rectangle West", |
| 144 | + "The west boundary of the bounding rectangle used for the quadtree tiling" + |
| 145 | + "scheme. Specified in longitude degrees in the range [-180, 180]." |
| 146 | + )); |
| 147 | + CesiumInspectorGUI.ClampedDoubleField( |
| 148 | + this._rectangleSouth, |
| 149 | + -90, 90, |
| 150 | + new GUIContent( |
| 151 | + "Rectangle South", |
| 152 | + "The south boundary of the bounding rectangle used for the quadtree tiling" + |
| 153 | + "scheme. Specified in longitude degrees in the range [-90, 90]." |
| 154 | + )); |
| 155 | + CesiumInspectorGUI.ClampedDoubleField( |
| 156 | + this._rectangleEast, |
| 157 | + -180, 180, |
| 158 | + new GUIContent( |
| 159 | + "Rectangle East", |
| 160 | + "The east boundary of the bounding rectangle used for the quadtree tiling" + |
| 161 | + "scheme. Specified in longitude degrees in the range [-180, 180]." |
| 162 | + )); |
| 163 | + CesiumInspectorGUI.ClampedDoubleField( |
| 164 | + this._rectangleNorth, |
| 165 | + -90, 90, |
| 166 | + new GUIContent( |
| 167 | + "Rectangle North", |
| 168 | + "The north boundary of the bounding rectangle used for the quadtree tiling" + |
| 169 | + "scheme. Specified in longitude degrees in the range [-90, 90]." |
| 170 | + )); |
| 171 | + EditorGUI.EndDisabledGroup(); |
| 172 | + |
| 173 | + EditorGUILayout.PropertyField(this._minimumLevel, new GUIContent( |
| 174 | + "Minimum Level", |
| 175 | + "Minimum zoom level.\n\n" + |
| 176 | + "Take care when specifying this that the number of tiles at the minimum" + |
| 177 | + "level is small, such as four or less. A larger number is likely to result" + |
| 178 | + "in rendering problems." |
| 179 | + )); |
| 180 | + EditorGUILayout.PropertyField(this._maximumLevel, new GUIContent("Maximum Level", "Maximum zoom level.")); |
| 181 | + |
| 182 | + EditorGUILayout.PropertyField(this._tileWidth, new GUIContent("Tile Width", "The pixel width of the image tiles.")); |
| 183 | + EditorGUILayout.PropertyField(this._tileHeight, new GUIContent("Tile Height", "The pixel height of the image tiles.")); |
| 184 | + |
| 185 | + EditorGUILayout.PropertyField( |
| 186 | + this._requestHeaders, |
| 187 | + new GUIContent("Request Headers", "HTTP headers to be attached to each request made for this raster overlay.")); |
| 188 | + |
| 189 | + } |
| 190 | + |
| 191 | + private void DrawRasterOverlayProperties() |
| 192 | + { |
| 193 | + if (this._rasterOverlayEditor != null) |
| 194 | + { |
| 195 | + this._rasterOverlayEditor.OnInspectorGUI(); |
| 196 | + } |
| 197 | + } |
| 198 | + } |
| 199 | +} |
0 commit comments