/// <summary> /// Sets the sub layer properties for the newly added layer /// </summary> /// <param name="subLayer">Sub layer.</param> void SetSubLayerProps(SerializedProperty subLayer) { subLayer.FindPropertyRelative("coreOptions.sublayerName").stringValue = subLayerProperties.coreOptions.sublayerName; subLayer.FindPropertyRelative("presetFeatureType").enumValueIndex = (int)subLayerProperties.presetFeatureType; // Set defaults here because SerializedProperty copies the previous element. var subLayerCoreOptions = subLayer.FindPropertyRelative("coreOptions"); CoreVectorLayerProperties coreOptions = subLayerProperties.coreOptions; subLayerCoreOptions.FindPropertyRelative("isActive").boolValue = coreOptions.isActive; subLayerCoreOptions.FindPropertyRelative("layerName").stringValue = coreOptions.layerName; subLayerCoreOptions.FindPropertyRelative("geometryType").enumValueIndex = (int)coreOptions.geometryType; subLayerCoreOptions.FindPropertyRelative("snapToTerrain").boolValue = coreOptions.snapToTerrain; subLayerCoreOptions.FindPropertyRelative("combineMeshes").boolValue = coreOptions.combineMeshes; subLayerCoreOptions.FindPropertyRelative("lineWidth").floatValue = coreOptions.lineWidth; var subLayerExtrusionOptions = subLayer.FindPropertyRelative("extrusionOptions"); var extrusionOptions = subLayerProperties.extrusionOptions; subLayerExtrusionOptions.FindPropertyRelative("extrusionType").enumValueIndex = (int)extrusionOptions.extrusionType; subLayerExtrusionOptions.FindPropertyRelative("extrusionGeometryType").enumValueIndex = (int)extrusionOptions.extrusionGeometryType; subLayerExtrusionOptions.FindPropertyRelative("propertyName").stringValue = extrusionOptions.propertyName; subLayerExtrusionOptions.FindPropertyRelative("extrusionScaleFactor").floatValue = extrusionOptions.extrusionScaleFactor; var subLayerFilterOptions = subLayer.FindPropertyRelative("filterOptions"); var filterOptions = subLayerProperties.filterOptions; subLayerFilterOptions.FindPropertyRelative("filters").ClearArray(); subLayerFilterOptions.FindPropertyRelative("combinerType").enumValueIndex = (int)filterOptions.combinerType; //Add any future filter related assignments here var subLayerGeometryMaterialOptions = subLayer.FindPropertyRelative("materialOptions"); var materialOptions = subLayerProperties.materialOptions; subLayerGeometryMaterialOptions.FindPropertyRelative("style").enumValueIndex = (int)materialOptions.style; 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 = subLayerProperties.buildingsWithUniqueIds; subLayer.FindPropertyRelative("moveFeaturePositionTo").enumValueIndex = (int)subLayerProperties.moveFeaturePositionTo; subLayer.FindPropertyRelative("MeshModifiers").ClearArray(); subLayer.FindPropertyRelative("GoModifiers").ClearArray(); var subLayerColliderOptions = subLayer.FindPropertyRelative("colliderOptions"); subLayerColliderOptions.FindPropertyRelative("colliderType").enumValueIndex = (int)subLayerProperties.colliderOptions.colliderType; }
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"); } } }