public void DrawUI(SerializedProperty property) { objectId = property.serializedObject.targetObject.GetInstanceID().ToString(); var serializedMapObject = property.serializedObject; AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject; tileJSONData = mapObject.VectorData.GetTileJsonData(); var sourceTypeProperty = property.FindPropertyRelative("_sourceType"); var sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex; var displayNames = sourceTypeProperty.enumDisplayNames; int count = sourceTypeProperty.enumDisplayNames.Length; if (!_isGUIContentSet) { _sourceTypeContent = new GUIContent[count]; for (int extIdx = 0; extIdx < count; extIdx++) { _sourceTypeContent[extIdx] = new GUIContent { text = displayNames[extIdx], tooltip = ((VectorSourceType)extIdx).Description(), }; } _isGUIContentSet = true; } sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex; var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions"); var layerSourceProperty = sourceOptionsProperty.FindPropertyRelative("layerSource"); var layerSourceId = layerSourceProperty.FindPropertyRelative("Id"); var isActiveProperty = sourceOptionsProperty.FindPropertyRelative("isActive"); switch (sourceTypeValue) { case VectorSourceType.MapboxStreets: case VectorSourceType.MapboxStreetsWithBuildingIds: var sourcePropertyValue = MapboxDefaultVector.GetParameters(sourceTypeValue); layerSourceId.stringValue = sourcePropertyValue.Id; GUI.enabled = false; if (_isInitialized) { LoadEditorTileJSON(property, sourceTypeValue, layerSourceId.stringValue); } else { _isInitialized = true; } if (tileJSONData.PropertyDisplayNames.Count == 0 && tileJSONData.tileJSONLoaded) { EditorGUILayout.HelpBox("Invalid Map Id / There might be a problem with the internet connection.", MessageType.Error); } GUI.enabled = true; isActiveProperty.boolValue = true; break; case VectorSourceType.Custom: if (_isInitialized) { string test = layerSourceId.stringValue; LoadEditorTileJSON(property, sourceTypeValue, layerSourceId.stringValue); } else { _isInitialized = true; } if (tileJSONData.PropertyDisplayNames.Count == 0 && tileJSONData.tileJSONLoaded) { EditorGUILayout.HelpBox("Invalid Map Id / There might be a problem with the internet connection.", MessageType.Error); } isActiveProperty.boolValue = true; break; case VectorSourceType.None: isActiveProperty.boolValue = false; break; default: isActiveProperty.boolValue = false; break; } if (sourceTypeValue != VectorSourceType.None) { EditorGUILayout.LabelField(new GUIContent { text = "Map Features", tooltip = "Visualizers for vector features contained in a layer. " }); var subLayerArray = property.FindPropertyRelative("vectorSubLayers"); var layersRect = EditorGUILayout.GetControlRect(GUILayout.MinHeight(Mathf.Max(subLayerArray.arraySize + 1, 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight), GUILayout.MaxHeight((subLayerArray.arraySize + 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight)); if (!m_Initialized) { bool firstInit = m_MultiColumnHeaderState == null; var headerState = FeatureSubLayerTreeView.CreateDefaultMultiColumnHeaderState(); if (MultiColumnHeaderState.CanOverwriteSerializedFields(m_MultiColumnHeaderState, headerState)) { MultiColumnHeaderState.OverwriteSerializedFields(m_MultiColumnHeaderState, headerState); } m_MultiColumnHeaderState = headerState; var multiColumnHeader = new FeatureSectionMultiColumnHeader(headerState); if (firstInit) { multiColumnHeader.ResizeToFit(); } treeModel = new TreeModel <FeatureTreeElement>(GetData(subLayerArray)); if (m_TreeViewState == null) { m_TreeViewState = new TreeViewState(); } if (layerTreeView == null) { layerTreeView = new FeatureSubLayerTreeView(m_TreeViewState, multiColumnHeader, treeModel); } layerTreeView.multiColumnHeader = multiColumnHeader; m_Initialized = true; } layerTreeView.Layers = subLayerArray; layerTreeView.Reload(); layerTreeView.OnGUI(layersRect); if (layerTreeView.hasChanged) { EditorHelper.CheckForModifiedProperty(property); layerTreeView.hasChanged = false; } selectedLayers = layerTreeView.GetSelection(); //if there are selected elements, set the selection index at the first element. //if not, use the Selection index to persist the selection at the right index. if (selectedLayers.Count > 0) { //ensure that selectedLayers[0] isn't out of bounds if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdFeature > subLayerArray.arraySize - 1) { selectedLayers[0] = subLayerArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdFeature; } SelectionIndex = selectedLayers[0]; } else { if (SelectionIndex > 0 && (SelectionIndex - FeatureSubLayerTreeView.uniqueIdFeature <= subLayerArray.arraySize - 1)) { selectedLayers = new int[1] { SelectionIndex }; layerTreeView.SetSelection(selectedLayers); } } GUILayout.Space(EditorGUIUtility.singleLineHeight); EditorGUILayout.BeginHorizontal(); //var presetTypes = property.FindPropertyRelative("presetFeatureTypes"); GenericMenu menu = new GenericMenu(); foreach (var name in Enum.GetNames(typeof(PresetFeatureType))) { menu.AddItem(new GUIContent() { text = name }, false, FetchPresetProperties, name); } GUILayout.Space(0); // do not remove this line; it is needed for the next line to work Rect rect = GUILayoutUtility.GetLastRect(); rect.y += 2 * _lineHeight / 3; if (EditorGUILayout.DropdownButton(new GUIContent { text = "Add Feature" }, FocusType.Passive, (GUIStyle)"minibuttonleft")) { menu.DropDown(rect); } //Assign subLayerProperties after fetching it from the presets class. This happens everytime an element is added if (subLayerProperties != null) { subLayerArray.arraySize++; var subLayer = subLayerArray.GetArrayElementAtIndex(subLayerArray.arraySize - 1); SetSubLayerProps(subLayer); //Refreshing the tree layerTreeView.Layers = subLayerArray; layerTreeView.AddElementToTree(subLayer); layerTreeView.Reload(); selectedLayers = new int[1] { subLayerArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdFeature }; layerTreeView.SetSelection(selectedLayers); subLayerProperties = null; // setting this to null so that the if block is not called again if (EditorHelper.DidModifyProperty(property)) { ((VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property)).OnSubLayerPropertyAdded(new VectorLayerUpdateArgs { property = EditorHelper.GetTargetObjectOfProperty(subLayer) as MapboxDataProperty }); } } if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright")) { foreach (var index in selectedLayers.OrderByDescending(i => i)) { if (layerTreeView != null) { var subLayer = subLayerArray.GetArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdFeature); VectorLayerProperties vectorLayerProperties = (VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property); VectorSubLayerProperties vectorSubLayerProperties = (VectorSubLayerProperties)EditorHelper.GetTargetObjectOfProperty(subLayer); vectorLayerProperties.OnSubLayerPropertyRemoved(new VectorLayerUpdateArgs { property = vectorSubLayerProperties }); layerTreeView.RemoveItemFromTree(index); subLayerArray.DeleteArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdFeature); layerTreeView.treeModel.SetData(GetData(subLayerArray)); } } selectedLayers = new int[0]; layerTreeView.SetSelection(selectedLayers); } EditorGUILayout.EndHorizontal(); GUILayout.Space(EditorGUIUtility.singleLineHeight); if (selectedLayers.Count == 1 && subLayerArray.arraySize != 0 && selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdFeature >= 0) { //ensure that selectedLayers[0] isn't out of bounds if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdFeature > subLayerArray.arraySize - 1) { selectedLayers[0] = subLayerArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdFeature; } SelectionIndex = selectedLayers[0]; var layerProperty = subLayerArray.GetArrayElementAtIndex(SelectionIndex - FeatureSubLayerTreeView.uniqueIdFeature); layerProperty.isExpanded = true; var subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions"); bool isLayerActive = subLayerCoreOptions.FindPropertyRelative("isActive").boolValue; if (!isLayerActive) { GUI.enabled = false; } DrawLayerVisualizerProperties(sourceTypeValue, layerProperty, property); if (!isLayerActive) { GUI.enabled = true; } } else { GUILayout.Label("Select a visualizer to see properties"); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //property.serializedObject.Update(); var extrusionTypeProperty = property.FindPropertyRelative("extrusionType"); var displayNames = extrusionTypeProperty.enumDisplayNames; int count = extrusionTypeProperty.enumDisplayNames.Length; if (!isGUIContentSet) { extrusionTypeContent = new GUIContent[count]; for (int extIdx = 0; extIdx < count; extIdx++) { extrusionTypeContent[extIdx] = new GUIContent { text = displayNames[extIdx], tooltip = EnumExtensions.Description((ExtrusionType)extIdx), }; } isGUIContentSet = true; } var extrusionTypeLabel = new GUIContent { text = "Extrusion Type", tooltip = "Type of geometry extrusion" }; EditorGUI.BeginChangeCheck(); extrusionTypeProperty.enumValueIndex = EditorGUILayout.Popup(extrusionTypeLabel, extrusionTypeProperty.enumValueIndex, extrusionTypeContent); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } var sourceTypeValue = (Unity.Map.ExtrusionType)extrusionTypeProperty.enumValueIndex; var minHeightProperty = property.FindPropertyRelative("minimumHeight"); var maxHeightProperty = property.FindPropertyRelative("maximumHeight"); var extrusionGeometryType = property.FindPropertyRelative("extrusionGeometryType"); var extrusionGeometryGUI = new GUIContent { text = "Geometry Type", tooltip = EnumExtensions.Description((Unity.Map.ExtrusionGeometryType)extrusionGeometryType.enumValueIndex) }; EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); switch (sourceTypeValue) { case Unity.Map.ExtrusionType.None: break; case Unity.Map.ExtrusionType.PropertyHeight: EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI); DrawPropertyDropDown(property, position); break; case Unity.Map.ExtrusionType.MinHeight: EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI); DrawPropertyDropDown(property, position); break; case Unity.Map.ExtrusionType.MaxHeight: EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI); DrawPropertyDropDown(property, position); break; case Unity.Map.ExtrusionType.RangeHeight: EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI); DrawPropertyDropDown(property, position); EditorGUILayout.PropertyField(minHeightProperty); EditorGUILayout.PropertyField(maxHeightProperty); if (minHeightProperty.floatValue > maxHeightProperty.floatValue) { EditorGUILayout.HelpBox("Maximum Height less than Minimum Height!", MessageType.Error); } break; case Unity.Map.ExtrusionType.AbsoluteHeight: EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI); EditorGUILayout.PropertyField(maxHeightProperty, new GUIContent { text = "Height" }); break; default: break; } if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(property.FindPropertyRelative("extrusionScaleFactor"), new GUIContent { text = "Scale Factor" }); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } EditorGUI.indentLevel--; }
void DrawLayerVisualizerProperties(VectorSourceType sourceType, SerializedProperty layerProperty, SerializedProperty property) { var subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions"); //var layerName = layerProperty.FindPropertyRelative("coreOptions.layerName"); //var roadLayerName = layerProperty.FindPropertyRelative("roadLayer"); //var landuseLayerName = layerProperty.FindPropertyRelative("landuseLayer"); var subLayerName = subLayerCoreOptions.FindPropertyRelative("sublayerName").stringValue; var visualizerLayer = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue; var subLayerType = PresetSubLayerPropertiesFetcher.GetPresetTypeFromLayerName(visualizerLayer); //var maskValue = layerProperty.FindPropertyRelative("_maskValue"); //var selectedTypes = layerProperty.FindPropertyRelative("selectedTypes"); GUILayout.Space(-_lineHeight); layerProperty.FindPropertyRelative("presetFeatureType").intValue = (int)subLayerType; //EditorGUILayout.LabelField("Sub-type : " + "Highway", visualizerNameAndType); GUILayout.Space(_lineHeight); //*********************** LAYER NAME BEGINS ***********************************// VectorPrimitiveType primitiveTypeProp = (VectorPrimitiveType)subLayerCoreOptions.FindPropertyRelative("geometryType").enumValueIndex; var serializedMapObject = property.serializedObject; AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject; tileJsonData = mapObject.VectorData.GetTileJsonData(); var layerDisplayNames = tileJsonData.LayerDisplayNames; EditorGUI.BeginChangeCheck(); DrawLayerName(subLayerCoreOptions, layerDisplayNames); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(subLayerCoreOptions); } //*********************** LAYER NAME ENDS ***********************************// //*********************** TYPE DROPDOWN BEGINS ***********************************// //if (_streetsV7TileStats == null || subTypeValues == null) //{ // subTypeValues = GetSubTypeValues(layerProperty, visualizerLayer, sourceType); //} //if ((layerName.stringValue == roadLayerName.stringValue || layerName.stringValue == landuseLayerName.stringValue) && subTypeValues!=null) //{ // maskValue.intValue = EditorGUILayout.MaskField("Type",maskValue.intValue, subTypeValues); // string selectedOptions = string.Empty; // for (int i = 0; i < subTypeValues.Length; i++) // { // if ((maskValue.intValue & (1 << i)) == (1 << i)) // { // if (string.IsNullOrEmpty(selectedOptions)) // { // selectedOptions = subTypeValues[i]; // continue; // } // selectedOptions += "," + subTypeValues[i]; // } // } // selectedTypes.stringValue = selectedOptions; //} //*********************** TYPE DROPDOWN ENDS ***********************************// EditorGUI.indentLevel++; //*********************** FILTERS SECTION BEGINS ***********************************// var filterOptions = layerProperty.FindPropertyRelative("filterOptions"); filterOptions.FindPropertyRelative("_selectedLayerName").stringValue = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue; GUILayout.Space(-_lineHeight); EditorGUILayout.PropertyField(filterOptions, new GUIContent("Filters")); //*********************** FILTERS SECTION ENDS ***********************************// //*********************** MODELING SECTION BEGINS ***********************************// _modelingSectionDrawer.DrawUI(subLayerCoreOptions, layerProperty, primitiveTypeProp); //*********************** MODELING SECTION ENDS ***********************************// //*********************** TEXTURING SECTION BEGINS ***********************************// if (primitiveTypeProp != VectorPrimitiveType.Point && primitiveTypeProp != VectorPrimitiveType.Custom) { GUILayout.Space(-_lineHeight); EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("materialOptions")); } //*********************** TEXTURING SECTION ENDS ***********************************// //*********************** GAMEPLAY SECTION BEGINS ***********************************// _behaviorModifierSectionDrawer.DrawUI(layerProperty, primitiveTypeProp, sourceType); //*********************** GAMEPLAY SECTION ENDS ***********************************// EditorGUI.indentLevel--; }
void DrawMapLayerOptions() { var vectorDataProperty = serializedObject.FindProperty("_vectorData"); var layerProperty = vectorDataProperty.FindPropertyRelative("_layerProperty"); var layerSourceProperty = layerProperty.FindPropertyRelative("sourceOptions"); var sourceTypeProperty = layerProperty.FindPropertyRelative("_sourceType"); VectorSourceType sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex; var layerSourceId = layerProperty.FindPropertyRelative("sourceOptions.layerSource.Id"); string layerString = layerSourceId.stringValue; var isActiveProperty = layerSourceProperty.FindPropertyRelative("isActive"); var displayNames = sourceTypeProperty.enumDisplayNames; var names = sourceTypeProperty.enumNames; int count = sourceTypeProperty.enumDisplayNames.Length; if (!_isGUIContentSet) { _sourceTypeContent = new GUIContent[count]; var index = 0; foreach (var name in names) { _sourceTypeContent[index] = new GUIContent { text = displayNames[index], tooltip = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), name)).Description(), }; index++; } // // for (int extIdx = 0; extIdx < count; extIdx++) // { // _sourceTypeContent[extIdx] = new GUIContent // { // text = displayNames[extIdx], // tooltip = ((VectorSourceType)extIdx).Description(), // }; // } _isGUIContentSet = true; } EditorGUI.BeginChangeCheck(); sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(new GUIContent { text = "Data Source", tooltip = "Source tileset for Vector Data" }, sourceTypeProperty.enumValueIndex, _sourceTypeContent); //sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex; sourceTypeValue = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), names[sourceTypeProperty.enumValueIndex])); switch (sourceTypeValue) { case VectorSourceType.MapboxStreets: case VectorSourceType.MapboxStreetsV8: case VectorSourceType.MapboxStreetsWithBuildingIds: case VectorSourceType.MapboxStreetsV8WithBuildingIds: var sourcePropertyValue = MapboxDefaultVector.GetParameters(sourceTypeValue); layerSourceId.stringValue = sourcePropertyValue.Id; GUI.enabled = false; EditorGUILayout.PropertyField(layerSourceProperty, tilesetIdGui); GUI.enabled = true; isActiveProperty.boolValue = true; break; case VectorSourceType.Custom: EditorGUILayout.PropertyField(layerSourceProperty, tilesetIdGui); isActiveProperty.boolValue = true; break; case VectorSourceType.None: isActiveProperty.boolValue = false; break; default: isActiveProperty.boolValue = false; break; } if (sourceTypeValue != VectorSourceType.None) { var isStyleOptimized = layerProperty.FindPropertyRelative("useOptimizedStyle"); EditorGUILayout.PropertyField(isStyleOptimized); if (isStyleOptimized.boolValue) { EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("optimizedStyle"), new GUIContent("Style Options")); } GUILayout.Space(-_lineHeight); EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("performanceOptions"), new GUIContent("Perfomance Options")); } EditorGUILayout.Space(); ShowSepartor(); _vectorLayerDrawer.DrawUI(layerProperty); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(layerProperty); } }
private void DrawPropertyName(SerializedProperty property, Rect position, string selectedLayerName) { var parsedString = "No property selected"; var descriptionString = "No description available"; if (string.IsNullOrEmpty(selectedLayerName) || tileJsonData == null || !tileJsonData.PropertyDisplayNames.ContainsKey(selectedLayerName)) { DrawWarningMessage(position); } else { var propertyDisplayNames = tileJsonData.PropertyDisplayNames[selectedLayerName]; _propertyNamesList = new List <string>(propertyDisplayNames); //check if the selection is valid var propertyString = property.FindPropertyRelative("propertyName").stringValue; if (_propertyNamesList.Contains(propertyString)) { //if the layer contains the current layerstring, set it's index to match _propertyIndex = propertyDisplayNames.FindIndex(s => s.Equals(propertyString)); //create guicontent for a valid layer _propertyNameContent = new GUIContent[_propertyNamesList.Count]; for (int extIdx = 0; extIdx < _propertyNamesList.Count; extIdx++) { var parsedPropertyString = _propertyNamesList[extIdx].Split(new string[] { tileJsonData.optionalPropertiesString }, System.StringSplitOptions.None)[0].Trim(); _propertyNameContent[extIdx] = new GUIContent { text = _propertyNamesList[extIdx], tooltip = tileJsonData.LayerPropertyDescriptionDictionary[selectedLayerName][parsedPropertyString] }; } //display popup var propertyNameLabel = new GUIContent { text = "Property Name", tooltip = "The name of the property in the selected Mapbox layer that will be used for extrusion" }; EditorGUI.BeginChangeCheck(); _propertyIndex = EditorGUILayout.Popup(propertyNameLabel, _propertyIndex, _propertyNameContent); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } //set new string values based on selection parsedString = _propertyNamesList[_propertyIndex].Split(new string[] { tileJsonData.optionalPropertiesString }, System.StringSplitOptions.None)[0].Trim(); descriptionString = tileJsonData.LayerPropertyDescriptionDictionary[selectedLayerName][parsedString]; } else { //if the selected layer isn't in the source, add a placeholder entry _propertyIndex = 0; _propertyNamesList.Insert(0, propertyString); //create guicontent for an invalid layer _propertyNameContent = new GUIContent[_propertyNamesList.Count]; //first property gets a unique tooltip _propertyNameContent[0] = new GUIContent { text = _propertyNamesList[0], tooltip = "Unavialable in Selected Layer" }; for (int extIdx = 1; extIdx < _propertyNamesList.Count; extIdx++) { var parsedPropertyString = _propertyNamesList[extIdx].Split(new string[] { tileJsonData.optionalPropertiesString }, System.StringSplitOptions.None)[0].Trim(); _propertyNameContent[extIdx] = new GUIContent { text = _propertyNamesList[extIdx], tooltip = tileJsonData.LayerPropertyDescriptionDictionary[selectedLayerName][parsedPropertyString] }; } //display popup var propertyNameLabel = new GUIContent { text = "Property Name", tooltip = "The name of the property in the selected Mapbox layer that will be used for extrusion" }; EditorGUI.BeginChangeCheck(); _propertyIndex = EditorGUILayout.Popup(propertyNameLabel, _propertyIndex, _propertyNameContent); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } //set new string values based on the offset parsedString = _propertyNamesList[_propertyIndex].Split(new string[] { tileJsonData.optionalPropertiesString }, System.StringSplitOptions.None)[0].Trim(); descriptionString = "Unavailable in Selected Layer."; } property.FindPropertyRelative("propertyName").stringValue = parsedString; property.FindPropertyRelative("propertyDescription").stringValue = descriptionString; } descriptionString = string.IsNullOrEmpty(descriptionString) ? "No description available" : descriptionString; var propertyDescriptionPrefixLabel = new GUIContent { text = "Property Description", tooltip = "Factual information about the selected property" }; EditorGUILayout.LabelField(propertyDescriptionPrefixLabel, new GUIContent(descriptionString), (GUIStyle)"wordWrappedLabel"); }
void DrawMapOptions(SerializedObject mapObject) { var property = mapObject.FindProperty("_options"); if (!((AbstractMap)serializedObject.targetObject).IsAccessTokenValid) { EditorGUILayout.HelpBox("Invalid Access Token. Please add a valid access token using the Mapbox > Setup Menu", MessageType.Error); } EditorGUILayout.LabelField("Location ", GUILayout.Height(_lineHeight)); EditorGUILayout.PropertyField(property.FindPropertyRelative("locationOptions")); var extentOptions = property.FindPropertyRelative("extentOptions"); var extentOptionsType = extentOptions.FindPropertyRelative("extentType"); if ((MapExtentType)extentOptionsType.enumValueIndex == MapExtentType.Custom) { var tileProviderProperty = mapObject.FindProperty("_tileProvider"); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(extentOptionsType); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(extentOptions); } EditorGUI.indentLevel++; EditorGUILayout.PropertyField(tileProviderProperty); EditorGUI.indentLevel--; } else { GUILayout.Space(-_lineHeight); EditorGUILayout.PropertyField(extentOptions); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(serializedObject.FindProperty("_initializeOnStart")); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } ShowPosition = EditorGUILayout.Foldout(ShowPosition, "Others"); if (ShowPosition) { GUILayout.Space(-_lineHeight); EditorGUI.BeginChangeCheck(); var placementOptions = property.FindPropertyRelative("placementOptions"); EditorGUILayout.PropertyField(placementOptions); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(placementOptions); } GUILayout.Space(-_lineHeight); EditorGUI.BeginChangeCheck(); var scalingOptions = property.FindPropertyRelative("scalingOptions"); EditorGUILayout.PropertyField(scalingOptions); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(scalingOptions); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(property.FindPropertyRelative("loadingTexture")); EditorGUILayout.PropertyField(property.FindPropertyRelative("tileMaterial")); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } } }
void DrawLayerVisualizerProperties(VectorSourceType sourceType, SerializedProperty layerProperty, SerializedProperty property) { var subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions"); var subLayerName = subLayerCoreOptions.FindPropertyRelative("sublayerName").stringValue; var visualizerLayer = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue; var subLayerType = PresetSubLayerPropertiesFetcher.GetPresetTypeFromLayerName(visualizerLayer); GUILayout.Space(-_lineHeight); layerProperty.FindPropertyRelative("presetFeatureType").intValue = (int)subLayerType; GUILayout.Space(_lineHeight); //*********************** LAYER NAME BEGINS ***********************************// VectorPrimitiveType primitiveTypeProp = (VectorPrimitiveType)subLayerCoreOptions.FindPropertyRelative("geometryType").enumValueIndex; var serializedMapObject = property.serializedObject; AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject; tileJsonData = mapObject.VectorData.GetTileJsonData(); var layerDisplayNames = tileJsonData.LayerDisplayNames; EditorGUI.BeginChangeCheck(); DrawLayerName(subLayerCoreOptions, layerDisplayNames); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(subLayerCoreOptions); } //*********************** LAYER NAME ENDS ***********************************// EditorGUI.indentLevel++; //*********************** FILTERS SECTION BEGINS ***********************************// var filterOptions = layerProperty.FindPropertyRelative("filterOptions"); filterOptions.FindPropertyRelative("_selectedLayerName").stringValue = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue; GUILayout.Space(-_lineHeight); EditorGUILayout.PropertyField(filterOptions, new GUIContent("Filters")); //*********************** FILTERS SECTION ENDS ***********************************// //*********************** MODELING SECTION BEGINS ***********************************// _modelingSectionDrawer.DrawUI(subLayerCoreOptions, layerProperty, primitiveTypeProp); //*********************** MODELING SECTION ENDS ***********************************// //*********************** TEXTURING SECTION BEGINS ***********************************// if (primitiveTypeProp != VectorPrimitiveType.Point && primitiveTypeProp != VectorPrimitiveType.Custom) { GUILayout.Space(-_lineHeight); EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("materialOptions")); } //*********************** TEXTURING SECTION ENDS ***********************************// //*********************** GAMEPLAY SECTION BEGINS ***********************************// _behaviorModifierSectionDrawer.DrawUI(layerProperty, primitiveTypeProp, sourceType); //*********************** GAMEPLAY SECTION ENDS ***********************************// EditorGUI.indentLevel--; }
void OnGUI() { GUILayout.Label("Search for a location"); string oldSearchInput = _searchInput; GUI.SetNextControlName(searchFieldName); _searchInput = GUILayout.TextField(_searchInput); if (_searchInput.Length == 0) { GUILayout.Label("Type in a location to find it's latitude and longtitude"); } else { bool changed = oldSearchInput != _searchInput; if (changed) { HandleUserInput(_searchInput); } if (_features.Count > 0) { GUILayout.Label("Results:"); for (int i = 0; i < _features.Count; i++) { Feature feature = _features[i]; string coordinates = feature.Center.x.ToString(CultureInfo.InvariantCulture) + ", " + feature.Center.y.ToString(CultureInfo.InvariantCulture); //abreviated coords for display in the UI string truncatedCoordinates = feature.Center.x.ToString("F2", CultureInfo.InvariantCulture) + ", " + feature.Center.y.ToString("F2", CultureInfo.InvariantCulture); //split feature name and add elements until the maxButtonContentLenght is exceeded string[] featureNameSplit = feature.PlaceName.Split(','); string buttonContent = ""; int maxButtonContentLength = 30; for (int j = 0; j < featureNameSplit.Length; j++) { if (buttonContent.Length + featureNameSplit[j].Length < maxButtonContentLength) { if (String.IsNullOrEmpty(buttonContent)) { buttonContent = featureNameSplit[j]; } else { buttonContent = buttonContent + "," + featureNameSplit[j]; } } } if (buttonContent.Length < maxButtonContentLength + 15) { buttonContent = buttonContent + "," + " (" + truncatedCoordinates + ")"; } if (GUILayout.Button(buttonContent)) { _coordinateProperty.stringValue = coordinates; _coordinateProperty.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(_coordinateProperty.serializedObject.targetObject); if (_objectToUpdate != null) { EditorHelper.CheckForModifiedProperty(_coordinateProperty, _objectToUpdate, true); } Close(); } } } else { if (_isSearching) { GUILayout.Label("Searching..."); } else { GUILayout.Label("No search results"); } } } if (!hasSetFocus) { GUI.FocusControl(searchFieldName); hasSetFocus = true; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { objectId = property.serializedObject.targetObject.GetInstanceID().ToString(); var sourceTypeProperty = property.FindPropertyRelative("sourceType"); var displayNames = sourceTypeProperty.enumDisplayNames; int count = sourceTypeProperty.enumDisplayNames.Length; if (!isGUIContentSet) { sourceTypeContent = new GUIContent[count]; for (int extIdx = 0; extIdx < count; extIdx++) { sourceTypeContent[extIdx] = new GUIContent { text = displayNames[extIdx], tooltip = ((ElevationSourceType)extIdx).Description(), }; } isGUIContentSet = true; } var sourceTypeLabel = new GUIContent { text = "Data Source", tooltip = "Source tileset for Terrain." }; EditorGUI.BeginChangeCheck(); sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(sourceTypeLabel, sourceTypeProperty.enumValueIndex, sourceTypeContent); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } var sourceTypeValue = (ElevationSourceType)sourceTypeProperty.enumValueIndex; var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions"); var layerSourceProperty = sourceOptionsProperty.FindPropertyRelative("layerSource"); var layerSourceId = layerSourceProperty.FindPropertyRelative("Id"); EditorGUI.BeginChangeCheck(); switch (sourceTypeValue) { case ElevationSourceType.MapboxTerrain: var sourcePropertyValue = MapboxDefaultElevation.GetParameters(sourceTypeValue); layerSourceId.stringValue = sourcePropertyValue.Id; GUI.enabled = false; EditorGUILayout.PropertyField(sourceOptionsProperty, _tilesetIdGui); GUI.enabled = true; break; case ElevationSourceType.Custom: layerSourceId.stringValue = string.IsNullOrEmpty(CustomSourceTilesetId) ? MapboxDefaultElevation.GetParameters(ElevationSourceType.MapboxTerrain).Id : CustomSourceTilesetId; EditorGUILayout.PropertyField(sourceOptionsProperty, _tilesetIdGui); CustomSourceTilesetId = layerSourceId.stringValue; break; default: break; } if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } var elevationLayerType = property.FindPropertyRelative("elevationLayerType"); if (sourceTypeValue == ElevationSourceType.None) { GUI.enabled = false; elevationLayerType.enumValueIndex = (int)ElevationLayerType.FlatTerrain; } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(property.FindPropertyRelative("elevationLayerType"), new GUIContent { text = elevationLayerType.displayName, tooltip = ((ElevationLayerType)elevationLayerType.enumValueIndex).Description() }); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } if (sourceTypeValue == ElevationSourceType.None) { GUI.enabled = true; } GUILayout.Space(-lineHeight); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(property.FindPropertyRelative("colliderOptions"), true); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property.FindPropertyRelative("colliderOptions")); } GUILayout.Space(2 * -lineHeight); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(property.FindPropertyRelative("requiredOptions"), true); GUILayout.Space(-lineHeight); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } ShowPosition = EditorGUILayout.Foldout(ShowPosition, "Others"); if (ShowPosition) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(property.FindPropertyRelative("modificationOptions"), true); EditorGUILayout.PropertyField(property.FindPropertyRelative("sideWallOptions"), true); EditorGUILayout.PropertyField(property.FindPropertyRelative("unityLayerOptions"), true); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { objectId = property.serializedObject.targetObject.GetInstanceID().ToString(); showTexturing = EditorGUILayout.Foldout(showTexturing, new GUIContent { text = "Texturing", tooltip = "Material options to texture the generated building geometry" }); if (showTexturing) { LoadDefaultStyleIcons(); EditorGUI.BeginProperty(position, label, property); var styleTypeLabel = new GUIContent { text = "Style Type", tooltip = "Texturing style for feature; choose from sample style or create your own by choosing Custom. " }; var styleType = property.FindPropertyRelative("style"); GUIContent[] styleTypeGuiContent = new GUIContent[styleType.enumDisplayNames.Length]; for (int i = 0; i < styleType.enumDisplayNames.Length; i++) { styleTypeGuiContent[i] = new GUIContent { text = styleType.enumDisplayNames[i] }; } EditorGUI.BeginChangeCheck(); styleType.enumValueIndex = EditorGUILayout.Popup(styleTypeLabel, styleType.enumValueIndex, styleTypeGuiContent); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } EditorGUI.indentLevel++; if ((StyleTypes)styleType.enumValueIndex != StyleTypes.Custom) { GUILayout.BeginHorizontal(); var style = (StyleTypes)styleType.enumValueIndex; Texture2D thumbnailTexture = (Texture2D)_styleIconBundles[style].texture; if ((StyleTypes)styleType.enumValueIndex == StyleTypes.Simple) { var samplePaletteType = property.FindPropertyRelative("samplePalettes"); var palette = (SamplePalettes)samplePaletteType.enumValueIndex; thumbnailTexture = (Texture2D)_paletteIconBundles[palette].texture; } string descriptionLabel = EnumExtensions.Description(style); EditorGUILayout.LabelField(new GUIContent(" ", thumbnailTexture), Constants.GUI.Styles.EDITOR_TEXTURE_THUMBNAIL_STYLE, GUILayout.Height(60), GUILayout.Width(EditorGUIUtility.labelWidth - 60)); EditorGUILayout.TextArea(descriptionLabel, (GUIStyle)"wordWrappedLabel"); GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); switch ((StyleTypes)styleType.enumValueIndex) { case StyleTypes.Simple: var samplePaletteType = property.FindPropertyRelative("samplePalettes"); var samplePaletteTypeLabel = new GUIContent { text = "Palette Type", tooltip = "Palette type for procedural colorization; choose from sample palettes or create your own by choosing Custom. " }; GUIContent[] samplePaletteTypeGuiContent = new GUIContent[samplePaletteType.enumDisplayNames.Length]; for (int i = 0; i < samplePaletteType.enumDisplayNames.Length; i++) { samplePaletteTypeGuiContent[i] = new GUIContent { text = samplePaletteType.enumDisplayNames[i] }; } samplePaletteType.enumValueIndex = EditorGUILayout.Popup(samplePaletteTypeLabel, samplePaletteType.enumValueIndex, samplePaletteTypeGuiContent); break; case StyleTypes.Light: property.FindPropertyRelative("lightStyleOpacity").floatValue = EditorGUILayout.Slider("Opacity", property.FindPropertyRelative("lightStyleOpacity").floatValue, 0.0f, 1.0f); break; case StyleTypes.Dark: property.FindPropertyRelative("darkStyleOpacity").floatValue = EditorGUILayout.Slider("Opacity", property.FindPropertyRelative("darkStyleOpacity").floatValue, 0.0f, 1.0f); break; case StyleTypes.Color: property.FindPropertyRelative("colorStyleColor").colorValue = EditorGUILayout.ColorField("Color", property.FindPropertyRelative("colorStyleColor").colorValue); break; default: break; } if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } } else { var customStyleProperty = property.FindPropertyRelative("customStyleOptions"); var texturingType = customStyleProperty.FindPropertyRelative("texturingType"); int valIndex = texturingType.enumValueIndex == 0 ? 0 : texturingType.enumValueIndex + 1; var texturingTypeGUI = new GUIContent { text = "Texturing Type", tooltip = EnumExtensions.Description((UvMapType)valIndex) }; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(texturingType, texturingTypeGUI); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } var matList = customStyleProperty.FindPropertyRelative("materials"); if (matList.arraySize == 0) { matList.arraySize = 2; } GUILayout.Space(-lineHeight); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(matList.GetArrayElementAtIndex(0), new GUIContent { text = "Top Material", tooltip = "Unity material to use for extruded top/roof mesh. " }); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } GUILayout.Space(-lineHeight); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(matList.GetArrayElementAtIndex(1), new GUIContent { text = "Side Material", tooltip = "Unity material to use for extruded side/wall mesh. " }); if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } EditorGUI.BeginChangeCheck(); if ((UvMapType)texturingType.enumValueIndex + 1 == UvMapType.Atlas) { var atlasInfo = customStyleProperty.FindPropertyRelative("atlasInfo"); EditorGUILayout.ObjectField(atlasInfo, new GUIContent { text = "Altas Info", tooltip = "Atlas information scriptable object, this defines how the texture roof and wall texture atlases will be used. " }); } if ((UvMapType)texturingType.enumValueIndex + 1 == UvMapType.AtlasWithColorPalette) { var atlasInfo = customStyleProperty.FindPropertyRelative("atlasInfo"); EditorGUILayout.ObjectField(atlasInfo, new GUIContent { text = "Altas Info", tooltip = "Atlas information scriptable object, this defines how the texture roof and wall texture atlases will be used. " }); var colorPalette = customStyleProperty.FindPropertyRelative("colorPalette"); EditorGUILayout.ObjectField(colorPalette, new GUIContent { text = "Color Palette", tooltip = "Color palette scriptable object, allows texture features to be procedurally colored at runtime. Requires materials that use the MapboxPerRenderer shader. " }); EditorGUILayout.LabelField(new GUIContent { text = "Note: Atlas With Color Palette requires materials that use the MapboxPerRenderer shader." }, Constants.GUI.Styles.EDITOR_NOTE_STYLE); } if (EditorGUI.EndChangeCheck()) { EditorHelper.CheckForModifiedProperty(property); } } EditorGUI.indentLevel--; EditorGUI.EndProperty(); } }