// NOTE : 타일의 지형 데이터를 json형식으로 컨버트 public static void SetTileTerrainData(List <Tile.Tile> tiles) { var data = new TileJsonData(); data.tileDataList = tiles.Select(x => new TileJsonData.TileJsonDataElement() { terrainType = (int)x.TerrainType, x = x.IndexPair.X, y = x.IndexPair.Y }).ToList(); ExportToJson(data, "TileData", "TerrainData.json"); }
private void DrawPropertyDropDown(SerializedProperty property, Rect position) { var selectedLayerName = property.FindPropertyRelative("_selectedLayerName").stringValue; var serializedMapObject = property.serializedObject; AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject; tileJsonData = mapObject.VectorData.LayerProperty.tileJsonData; DrawPropertyName(property, position, selectedLayerName); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, null, property); // Draw label. var primitiveType = property.FindPropertyRelative("geometryType"); var primitiveTypeLabel = new GUIContent { text = "Primitive Type", tooltip = "Primitive geometry type of the visualizer, allowed primitives - point, line, polygon." }; var displayNames = primitiveType.enumDisplayNames; int count = primitiveType.enumDisplayNames.Length; if (!_isGUIContentSet) { _primitiveTypeContent = new GUIContent[count]; for (int extIdx = 0; extIdx < count; extIdx++) { _primitiveTypeContent[extIdx] = new GUIContent { text = displayNames[extIdx], tooltip = EnumExtensions.Description((VectorPrimitiveType)extIdx), }; } _isGUIContentSet = true; } primitiveType.enumValueIndex = EditorGUILayout.Popup(primitiveTypeLabel, primitiveType.enumValueIndex, _primitiveTypeContent); var serializedMapObject = property.serializedObject; AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject; tileJsonData = mapObject.VectorData.LayerProperty.tileJsonData; var layerDisplayNames = tileJsonData.LayerDisplayNames; DrawLayerName(property, position, layerDisplayNames); var snapToTerrainProperty = property.FindPropertyRelative("snapToTerrain"); var groupFeaturesProperty = property.FindPropertyRelative("groupFeatures"); snapToTerrainProperty.boolValue = EditorGUILayout.Toggle(snapToTerrainProperty.displayName, snapToTerrainProperty.boolValue); groupFeaturesProperty.boolValue = EditorGUILayout.Toggle(groupFeaturesProperty.displayName, groupFeaturesProperty.boolValue); if ((VectorPrimitiveType)primitiveType.enumValueIndex == VectorPrimitiveType.Line) { EditorGUILayout.PropertyField(property.FindPropertyRelative("lineWidth")); } EditorGUI.EndProperty(); }
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; 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 index0 = 0; index0 < count; index0++) // { // _sourceTypeContent[index0] = new GUIContent // { // text = displayNames[index0], // tooltip = ((VectorSourceType)index0).Description(), // }; // } _isGUIContentSet = true; } //sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex; sourceTypeValue = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), names[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.MapboxStreetsV8: case VectorSourceType.MapboxStreetsWithBuildingIds: case VectorSourceType.MapboxStreetsV8WithBuildingIds: 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 Tileset 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 Tileset 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(); 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)) { isLayerAdded = true; } } 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"); } } }
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--; }
private void DrawPropertyDropDown(SerializedProperty originalProperty, SerializedProperty filterProperty) { var selectedLayerName = originalProperty.FindPropertyRelative("_selectedLayerName").stringValue; AbstractMap mapObject = (AbstractMap)originalProperty.serializedObject.targetObject; TileJsonData tileJsonData = mapObject.VectorData.LayerProperty.tileJsonData; if (string.IsNullOrEmpty(selectedLayerName) || !tileJsonData.PropertyDisplayNames.ContainsKey(selectedLayerName)) { DrawWarningMessage(); return; } var parsedString = "no property selected"; var descriptionString = "no description available"; var propertyDisplayNames = tileJsonData.PropertyDisplayNames[selectedLayerName]; _propertyNamesList = new List <string>(propertyDisplayNames); var propertyString = filterProperty.FindPropertyRelative("Key").stringValue; //check if the selection is valid 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 _propertyIndex = EditorGUILayout.Popup(_propertyIndex, _propertyNameContent, GUILayout.MaxWidth(150)); //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 _propertyIndex = EditorGUILayout.Popup(_propertyIndex, _propertyNameContent, GUILayout.MaxWidth(150)); //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."; } filterProperty.FindPropertyRelative("Key").stringValue = parsedString; filterProperty.FindPropertyRelative("KeyDescription").stringValue = descriptionString; }
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.LayerProperty.tileJsonData; var layerDisplayNames = tileJsonData.LayerDisplayNames; DrawLayerName(subLayerCoreOptions, layerDisplayNames); //*********************** 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--; }
public void DrawUI(SerializedProperty property) { objectId = property.serializedObject.targetObject.GetInstanceID().ToString(); var serializedMapObject = property.serializedObject; AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject; tileJSONData = mapObject.VectorData.LayerProperty.tileJsonData; 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 = "Vector Layer Visualizers", 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), GUILayout.MaxHeight((subLayerArray.arraySize + 1) * _lineHeight)); layerTreeView.Layers = subLayerArray; layerTreeView.Reload(); layerTreeView.OnGUI(layersRect); 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] - layerTreeView.uniqueId > subLayerArray.arraySize - 1) { selectedLayers[0] = subLayerArray.arraySize - 1 + layerTreeView.uniqueId; } SelectionIndex = selectedLayers[0]; } else { if (SelectionIndex > 0 && (SelectionIndex - layerTreeView.uniqueId <= subLayerArray.arraySize - 1)) { selectedLayers = new int[1] { SelectionIndex }; layerTreeView.SetSelection(selectedLayers); } } GUILayout.Space(EditorGUIUtility.singleLineHeight); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Add Visualizer"), (GUIStyle)"minibuttonleft")) { subLayerArray.arraySize++; var subLayer = subLayerArray.GetArrayElementAtIndex(subLayerArray.arraySize - 1); var subLayerName = subLayer.FindPropertyRelative("coreOptions.sublayerName"); subLayerName.stringValue = "Untitled"; // Set defaults here because SerializedProperty copies the previous element. var subLayerCoreOptions = subLayer.FindPropertyRelative("coreOptions"); subLayerCoreOptions.FindPropertyRelative("isActive").boolValue = true; subLayerCoreOptions.FindPropertyRelative("layerName").stringValue = "building"; subLayerCoreOptions.FindPropertyRelative("geometryType").enumValueIndex = (int)VectorPrimitiveType.Polygon; subLayerCoreOptions.FindPropertyRelative("snapToTerrain").boolValue = true; subLayerCoreOptions.FindPropertyRelative("groupFeatures").boolValue = false; subLayerCoreOptions.FindPropertyRelative("lineWidth").floatValue = 1.0f; var subLayerExtrusionOptions = subLayer.FindPropertyRelative("extrusionOptions"); subLayerExtrusionOptions.FindPropertyRelative("extrusionType").enumValueIndex = (int)ExtrusionType.None; subLayerExtrusionOptions.FindPropertyRelative("extrusionGeometryType").enumValueIndex = (int)ExtrusionGeometryType.RoofAndSide; subLayerExtrusionOptions.FindPropertyRelative("propertyName").stringValue = "height"; subLayerExtrusionOptions.FindPropertyRelative("extrusionScaleFactor").floatValue = 1f; var subLayerFilterOptions = subLayer.FindPropertyRelative("filterOptions"); subLayerFilterOptions.FindPropertyRelative("filters").ClearArray(); subLayerFilterOptions.FindPropertyRelative("combinerType").enumValueIndex = (int)LayerFilterCombinerOperationType.Any; var subLayerGeometryMaterialOptions = subLayer.FindPropertyRelative("materialOptions"); subLayerGeometryMaterialOptions.FindPropertyRelative("style").enumValueIndex = (int)StyleTypes.Realistic; GeometryMaterialOptions geometryMaterialOptionsReference = MapboxDefaultStyles.GetDefaultAssets(); var mats = subLayerGeometryMaterialOptions.FindPropertyRelative("materials"); mats.arraySize = 2; var topMatArray = mats.GetArrayElementAtIndex(0).FindPropertyRelative("Materials"); var sideMatArray = mats.GetArrayElementAtIndex(1).FindPropertyRelative("Materials"); if (topMatArray.arraySize == 0) { topMatArray.arraySize = 1; } if (sideMatArray.arraySize == 0) { sideMatArray.arraySize = 1; } var topMat = topMatArray.GetArrayElementAtIndex(0); var sideMat = sideMatArray.GetArrayElementAtIndex(0); var atlas = subLayerGeometryMaterialOptions.FindPropertyRelative("atlasInfo"); var palette = subLayerGeometryMaterialOptions.FindPropertyRelative("colorPalette"); topMat.objectReferenceValue = geometryMaterialOptionsReference.materials[0].Materials[0]; sideMat.objectReferenceValue = geometryMaterialOptionsReference.materials[1].Materials[0]; atlas.objectReferenceValue = geometryMaterialOptionsReference.atlasInfo; palette.objectReferenceValue = geometryMaterialOptionsReference.colorPalette; subLayer.FindPropertyRelative("buildingsWithUniqueIds").boolValue = false; subLayer.FindPropertyRelative("moveFeaturePositionTo").enumValueIndex = (int)PositionTargetType.TileCenter; subLayer.FindPropertyRelative("MeshModifiers").ClearArray(); subLayer.FindPropertyRelative("GoModifiers").ClearArray(); var subLayerColliderOptions = subLayer.FindPropertyRelative("colliderOptions"); subLayerColliderOptions.FindPropertyRelative("colliderType").enumValueIndex = (int)ColliderType.None; selectedLayers = new int[1] { subLayerArray.arraySize - 1 + layerTreeView.uniqueId }; layerTreeView.SetSelection(selectedLayers); } if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright")) { foreach (var index in selectedLayers.OrderByDescending(i => i)) { subLayerArray.DeleteArrayElementAtIndex(index - layerTreeView.uniqueId); } selectedLayers = new int[0]; layerTreeView.SetSelection(selectedLayers); } EditorGUILayout.EndHorizontal(); GUILayout.Space(EditorGUIUtility.singleLineHeight); if (selectedLayers.Count == 1 && subLayerArray.arraySize != 0) { //ensure that selectedLayers[0] isn't out of bounds if (selectedLayers[0] - layerTreeView.uniqueId > subLayerArray.arraySize - 1) { selectedLayers[0] = subLayerArray.arraySize - 1 + layerTreeView.uniqueId; } SelectionIndex = selectedLayers[0]; var layerProperty = subLayerArray.GetArrayElementAtIndex(SelectionIndex - layerTreeView.uniqueId); 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"); } } }