コード例 #1
0
        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");
                }
            }
        }
コード例 #2
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");
                }
            }
        }