Example #1
0
        public void PostProcessLayerProperties(SerializedProperty property)
        {
            var layerSourceProperty          = property.FindPropertyRelative("sourceOptions");
            var sourceTypeProperty           = property.FindPropertyRelative("_sourceType");
            VectorSourceType sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
            string           streets_v7      = MapboxDefaultVector.GetParameters(VectorSourceType.MapboxStreets).Id;
            var    layerSourceId             = layerSourceProperty.FindPropertyRelative("layerSource.Id");
            string layerString = layerSourceId.stringValue;

            if (ShowLocationPrefabs)
            {
                if (_poiSublayerDrawer.isLayerAdded == true && sourceTypeValue != VectorSourceType.None && layerString.Contains(streets_v7))
                {
                    var prefabItemArray = property.FindPropertyRelative("locationPrefabList");
                    var prefabItem      = prefabItemArray.GetArrayElementAtIndex(prefabItemArray.arraySize - 1);
                    PrefabItemOptions prefabItemOptionToAdd = (PrefabItemOptions)EditorHelper.GetTargetObjectOfProperty(prefabItem) as PrefabItemOptions;
                    ((VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property)).OnSubLayerPropertyAdded(new VectorLayerUpdateArgs {
                        property = prefabItemOptionToAdd
                    });
                    _poiSublayerDrawer.isLayerAdded = false;
                }
            }
            if (ShowFeatures)
            {
                if (_vectorSublayerDrawer.isLayerAdded == true)
                {
                    var subLayerArray = property.FindPropertyRelative("vectorSubLayers");
                    var subLayer      = subLayerArray.GetArrayElementAtIndex(subLayerArray.arraySize - 1);
                    ((VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property)).OnSubLayerPropertyAdded(new VectorLayerUpdateArgs {
                        property = EditorHelper.GetTargetObjectOfProperty(subLayer) as MapboxDataProperty
                    });
                    _vectorSublayerDrawer.isLayerAdded = false;
                }
            }
        }
Example #2
0
        public BuildingMeshFactory(IMeshBuilder builder, BuildingsCompletion completed = null)
        {
            AllBuildingsLoaded = completed;

            _sourceOptions = new LayerSourceOptions
            {
                isActive    = true,
                layerSource = MapboxDefaultVector.GetParameters(VectorSourceType.MapboxStreetsV8WithBuildingIds)
            };
            _dataFetcher = ScriptableObject.CreateInstance <BuildingMeshFetcher>();
            _dataFetcher.dataReceived += OnVectorDataReceived;
            _builder = builder;
        }
Example #3
0
        public void DrawUI(SerializedProperty property)
        {
            objectId = property.serializedObject.targetObject.GetInstanceID().ToString();
            var layerSourceProperty = property.FindPropertyRelative("sourceOptions");
            var sourceTypeProperty  = property.FindPropertyRelative("_sourceType");

            var names = sourceTypeProperty.enumNames;
            VectorSourceType sourceTypeValue = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), names[sourceTypeProperty.enumValueIndex]));
            //VectorSourceType sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
            string streets_v7    = MapboxDefaultVector.GetParameters(VectorSourceType.MapboxStreets).Id;
            var    layerSourceId = layerSourceProperty.FindPropertyRelative("layerSource.Id");
            string layerString   = layerSourceId.stringValue;

            //Draw POI Section
            if (sourceTypeValue == VectorSourceType.None)
            {
                return;
            }

            ShowLocationPrefabs = EditorGUILayout.Foldout(ShowLocationPrefabs, "POINTS OF INTEREST");
            if (ShowLocationPrefabs)
            {
                if (sourceTypeValue != VectorSourceType.None && layerString.Contains(streets_v7))
                {
                    GUI.enabled = false;
                    EditorGUILayout.TextField(_requiredTilesetIdGui, streets_v7);
                    GUI.enabled = true;
                    _poiSublayerDrawer.DrawUI(property);
                }
                else
                {
                    EditorGUILayout.HelpBox("In order to place points of interest please add \"mapbox.mapbox-streets-v7\" to the data source.", MessageType.Error);
                }
            }

            ShowSepartor();

            //Draw Feature section.
            ShowFeatures = EditorGUILayout.Foldout(ShowFeatures, "FEATURES");
            if (ShowFeatures)
            {
                _vectorSublayerDrawer.DrawUI(property);
            }
        }
        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");
                }
            }
        }
Example #5
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            GUILayout.BeginVertical();
            EditorGUILayout.Space();

            ShowGeneral = EditorGUILayout.Foldout(ShowGeneral, new GUIContent {
                text = "GENERAL", tooltip = "Options related to map data"
            });
            if (ShowGeneral)
            {
                EditorGUILayout.Space();
                DrawMapOptions(serializedObject);
            }

            ShowSepartor();

            ShowImage = EditorGUILayout.Foldout(ShowImage, "IMAGE");
            if (ShowImage)
            {
                ShowSection(serializedObject.FindProperty("_imagery"), "_layerProperty");
            }

            ShowSepartor();

            ShowTerrain = EditorGUILayout.Foldout(ShowTerrain, "TERRAIN");
            if (ShowTerrain)
            {
                ShowSection(serializedObject.FindProperty("_terrain"), "_layerProperty");
            }

            ShowSepartor();

            ShowLocationPrefabs = EditorGUILayout.Foldout(ShowLocationPrefabs, "LOCATION PREFABS");
            if (ShowLocationPrefabs)
            {
                var vectorDataProperty = serializedObject.FindProperty("_vectorData");


                var layerProperty                = vectorDataProperty.FindPropertyRelative("_layerProperty");
                var layerSourceProperty          = layerProperty.FindPropertyRelative("sourceOptions");
                var sourceType                   = layerProperty.FindPropertyRelative("_sourceType");
                VectorSourceType sourceTypeValue = (VectorSourceType)sourceType.enumValueIndex;
                string           streets_v7      = MapboxDefaultVector.GetParameters(VectorSourceType.MapboxStreets).Id;
                string           layerString     = layerProperty.FindPropertyRelative("sourceOptions.layerSource.Id").stringValue;

                if (sourceTypeValue != VectorSourceType.None && layerString.Contains(streets_v7))
                {
                    GUI.enabled = false;
                    EditorGUILayout.TextField(_mapIdGui, streets_v7);
                    GUI.enabled = true;
                    ShowSection(vectorDataProperty, "_locationPrefabsLayerProperties");
                }
                else
                {
                    EditorGUILayout.HelpBox("In order to place location prefabs please add \"mapbox.mapbox-streets-v7\" to the data source in the Vector section.", MessageType.Error);
                }
            }

            ShowSepartor();

            ShowVector = EditorGUILayout.Foldout(ShowVector, "VECTOR");
            if (ShowVector)
            {
                ShowSection(serializedObject.FindProperty("_vectorData"), "_layerProperty");
            }
            GUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();
        }
        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, mapIdGui);
                GUI.enabled = true;
                isActiveProperty.boolValue = true;
                break;

            case VectorSourceType.Custom:
                EditorGUILayout.PropertyField(layerSourceProperty, mapIdGui);
                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);
            }
        }
Example #7
0
        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");
                }
            }
        }
        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;
            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;
            }

            sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(new GUIContent
            {
                text    = "Data Source",
                tooltip = "Source tileset for Vector Data"
            }, sourceTypeProperty.enumValueIndex, _sourceTypeContent);

            sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;

            switch (sourceTypeValue)
            {
            case VectorSourceType.MapboxStreets:
            case VectorSourceType.MapboxStreetsWithBuildingIds:
                var sourcePropertyValue = MapboxDefaultVector.GetParameters(sourceTypeValue);
                layerSourceId.stringValue = sourcePropertyValue.Id;
                GUI.enabled = false;
                EditorGUILayout.PropertyField(layerSourceProperty, mapIdGui);
                GUI.enabled = true;
                isActiveProperty.boolValue = true;
                break;

            case VectorSourceType.Custom:
                EditorGUILayout.PropertyField(layerSourceProperty, mapIdGui);
                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();

            GUILayout.Space(-2.0f * _lineHeight);
            ShowSection(serializedObject.FindProperty("_vectorData"), "_layerProperty");
        }
Example #9
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            position.height = _lineHeight;

            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;
            }

            var typePosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent
            {
                text    = "Data Source",
                tooltip = "Source tileset for Vector Data"
            });

            sourceTypeProperty.enumValueIndex =
                EditorGUI.Popup(typePosition, sourceTypeProperty.enumValueIndex, _sourceTypeContent);
            sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;

            position.y += _lineHeight;
            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;
                EditorGUILayout.PropertyField(sourceOptionsProperty, _mapIdGui);
                GUI.enabled = true;
                isActiveProperty.boolValue = true;
                break;

            case VectorSourceType.Custom:
                layerSourceId.stringValue = CustomSourceMapId;
                EditorGUILayout.PropertyField(sourceOptionsProperty, _mapIdGui);
                CustomSourceMapId          = layerSourceId.stringValue;
                isActiveProperty.boolValue = true;
                break;

            case VectorSourceType.None:
                isActiveProperty.boolValue = false;
                break;

            default:
                isActiveProperty.boolValue = false;
                break;
            }

            if (sourceTypeValue != VectorSourceType.None)
            {
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("sourceOptions"));

                var isStyleOptimized = property.FindPropertyRelative("useOptimizedStyle");
                EditorGUILayout.PropertyField(isStyleOptimized);
                position.y += _lineHeight;

                if (isStyleOptimized.boolValue)
                {
                    EditorGUILayout.PropertyField(property.FindPropertyRelative("optimizedStyle"), new GUIContent("Style Options"));
                }

                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("optimizedStyle"));
                EditorGUILayout.PropertyField(property.FindPropertyRelative("performanceOptions"),
                                              new GUIContent("Perfomance Options"));
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("performanceOptions"));

                EditorGUILayout.LabelField(new GUIContent
                {
                    text    = "Vector Layer Visualizers",
                    tooltip = "Visualizers for vector features contained in a layer. "
                });

                var subLayerArray = property.FindPropertyRelative("vectorSubLayers");
                var layersRect    = GUILayoutUtility.GetRect(0, 500, Mathf.Max(subLayerArray.arraySize + 1, 1) * _lineHeight,
                                                             (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] > subLayerArray.arraySize - 1)
                    {
                        selectedLayers[0] = subLayerArray.arraySize - 1;
                    }

                    SelectionIndex = selectedLayers[0];
                }
                else
                {
                    selectedLayers = new int[1] {
                        SelectionIndex
                    };
                    if (SelectionIndex > 0 && (SelectionIndex <= subLayerArray.arraySize - 1))
                    {
                        layerTreeView.SetSelection(selectedLayers);
                    }
                }

                GUILayout.Space(EditorGUIUtility.singleLineHeight);

                GUILayout.BeginHorizontal();

                if (GUILayout.Button(new GUIContent("Add Visualizer"), (GUIStyle)"minibuttonleft"))
                {
                    subLayerArray.arraySize++;
                    //subLayerArray.InsertArrayElementAtIndex(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 subLayerMaterialOptions = subLayer.FindPropertyRelative("materialOptions");
                    subLayerMaterialOptions.FindPropertyRelative("materials").ClearArray();
                    subLayerMaterialOptions.FindPropertyRelative("materials").arraySize               = 2;
                    subLayerMaterialOptions.FindPropertyRelative("atlasInfo").objectReferenceValue    = null;
                    subLayerMaterialOptions.FindPropertyRelative("colorPalette").objectReferenceValue = null;
                    subLayerMaterialOptions.FindPropertyRelative("texturingType").enumValueIndex      = (int)UvMapType.Tiled;

                    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.SetSelection(selectedLayers);
                }

                if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright"))
                {
                    foreach (var index in selectedLayers.OrderByDescending(i => i))
                    {
                        subLayerArray.DeleteArrayElementAtIndex(index);
                    }

                    selectedLayers = new int[0];
                    layerTreeView.SetSelection(selectedLayers);
                }

                GUILayout.EndHorizontal();

                GUILayout.Space(EditorGUIUtility.singleLineHeight);

                if (selectedLayers.Count == 1 && subLayerArray.arraySize != 0)
                {
                    //ensure that selectedLayers[0] isn't out of bounds
                    if (selectedLayers[0] > subLayerArray.arraySize - 1)
                    {
                        selectedLayers[0] = subLayerArray.arraySize - 1;
                    }

                    SelectionIndex = selectedLayers[0];

                    var layerProperty = subLayerArray.GetArrayElementAtIndex(SelectionIndex);

                    layerProperty.isExpanded = true;
                    var  subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions");
                    bool isLayerActive       = subLayerCoreOptions.FindPropertyRelative("isActive").boolValue;
                    if (!isLayerActive)
                    {
                        GUI.enabled = false;
                    }

                    DrawLayerVisualizerProperties(sourceTypeValue, layerProperty);
                    if (!isLayerActive)
                    {
                        GUI.enabled = true;
                    }
                }
                else
                {
                    GUILayout.Label("Select a visualizer to see properties");
                }
            }

            EditorGUI.EndProperty();
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            position.height = lineHeight;

            var sourceTypeProperty = property.FindPropertyRelative("sourceType");
            var sourceTypeValue    = (VectorSourceType)sourceTypeProperty.enumValueIndex;

            var typePosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent {
                text = "Style Name", tooltip = EnumExtensions.Description(sourceTypeValue)
            });

            sourceTypeProperty.enumValueIndex = EditorGUI.Popup(typePosition, sourceTypeProperty.enumValueIndex, sourceTypeProperty.enumDisplayNames);
            sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;

            position.y += lineHeight;
            var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
            var isActiveProperty      = sourceOptionsProperty.FindPropertyRelative("isActive");

            switch (sourceTypeValue)
            {
            case VectorSourceType.MapboxStreets:
            case VectorSourceType.MapboxStreetsWithBuildingIds:
                var sourcePropertyValue = MapboxDefaultVector.GetParameters(sourceTypeValue);
                var layerSourceProperty = sourceOptionsProperty.FindPropertyRelative("layerSource");
                var layerSourceId       = layerSourceProperty.FindPropertyRelative("Id");
                layerSourceId.stringValue = sourcePropertyValue.Id;
                GUI.enabled = false;
                EditorGUILayout.PropertyField(sourceOptionsProperty, new GUIContent("Source Option"));
                GUI.enabled = true;
                isActiveProperty.boolValue = true;
                break;

            case VectorSourceType.Custom:
                EditorGUILayout.PropertyField(sourceOptionsProperty, new GUIContent("Source Option"));
                isActiveProperty.boolValue = true;
                break;

            case VectorSourceType.None:
                isActiveProperty.boolValue = false;
                break;

            default:
                isActiveProperty.boolValue = false;
                break;
            }
            if (sourceTypeValue != VectorSourceType.None)
            {
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("sourceOptions"));

                var isStyleOptimized = property.FindPropertyRelative("useOptimizedStyle");
                EditorGUILayout.PropertyField(isStyleOptimized);
                position.y += lineHeight;

                if (isStyleOptimized.boolValue)
                {
                    EditorGUILayout.PropertyField(property.FindPropertyRelative("optimizedStyle"), new GUIContent("Style Options"));
                }
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("optimizedStyle"));
                EditorGUILayout.PropertyField(property.FindPropertyRelative("performanceOptions"), new GUIContent("Perfomance Options"));
                position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("performanceOptions"));

                EditorGUILayout.LabelField(new GUIContent {
                    text = "Vector Layer Visualizers", tooltip = "Visualizers for vector features contained in a layer. "
                });

                var subLayerArray = property.FindPropertyRelative("vectorSubLayers");
                var layersRect    = GUILayoutUtility.GetRect(0, 500, Mathf.Max(subLayerArray.arraySize + 1, 1) * lineHeight, (subLayerArray.arraySize + 1) * lineHeight);


                layerTreeView.Layers = subLayerArray;
                layerTreeView.Reload();
                layerTreeView.OnGUI(layersRect);

                selectedLayers = layerTreeView.GetSelection();

                GUILayout.Space(EditorGUIUtility.singleLineHeight);

                GUILayout.BeginHorizontal();

                if (GUILayout.Button(new GUIContent("Add Visualizer"), (GUIStyle)"minibuttonleft"))
                {
                    subLayerArray.arraySize++;
                    //subLayerArray.InsertArrayElementAtIndex(subLayerArray.arraySize);

                    var subLayer     = subLayerArray.GetArrayElementAtIndex(subLayerArray.arraySize - 1);
                    var subLayerName = subLayer.FindPropertyRelative("coreOptions.sublayerName");
                    Debug.Log("Active status -> " + subLayer.FindPropertyRelative("coreOptions.isActive").boolValue.ToString());
                    subLayerName.stringValue = "Untitled";


                    // Set defaults here beacuse 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("propertyName").stringValue = "height";
                }
                if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright"))
                {
                    foreach (var index in selectedLayers.OrderByDescending(i => i))
                    {
                        subLayerArray.DeleteArrayElementAtIndex(index);
                    }
                    selectedLayers = new int[0];
                    layerTreeView.SetSelection(selectedLayers);
                }

                GUILayout.EndHorizontal();

                GUILayout.Space(EditorGUIUtility.singleLineHeight);

                if (selectedLayers.Count == 1)
                {
                    var index = selectedLayers[0];

                    var layerProperty = subLayerArray.GetArrayElementAtIndex(index);

                    layerProperty.isExpanded = true;
                    DrawLayerVisualizerProperties(layerProperty);
                }
                else
                {
                    GUILayout.Label("Select a visualizer to see properties");
                }
            }
            EditorGUI.EndProperty();
        }