예제 #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;
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            ColliderOptions colliderOptions = (ColliderOptions)EditorHelper.GetTargetObjectOfProperty(property);

            EditorGUI.BeginProperty(position, null, property);
            var colliderTypeLabel = new GUIContent
            {
                text    = "Collider Type",
                tooltip = "The type of collider added to game objects in this layer."
            };
            var colliderTypeProperty = property.FindPropertyRelative("colliderType");

            var displayNames = colliderTypeProperty.enumDisplayNames;
            int count        = colliderTypeProperty.enumDisplayNames.Length;

            if (!isGUIContentSet)
            {
                colliderTypeContent = new GUIContent[count];
                for (int extIdx = 0; extIdx < count; extIdx++)
                {
                    colliderTypeContent[extIdx] = new GUIContent
                    {
                        text    = displayNames[extIdx],
                        tooltip = EnumExtensions.Description((ColliderType)extIdx),
                    };
                }
                isGUIContentSet = true;
            }

            colliderTypeProperty.enumValueIndex = EditorGUILayout.Popup(colliderTypeLabel, colliderTypeProperty.enumValueIndex, colliderTypeContent);
            EditorHelper.CheckForModifiedProperty(colliderTypeProperty, colliderOptions);

            EditorGUI.EndProperty();
        }
        private void ShowAddressOrLatLonUI(SerializedProperty property)
        {
            //EditorGUILayout.BeginVertical();
            var coordinateProperties = property.FindPropertyRelative("coordinates");

            for (int i = 0; i < coordinateProperties.arraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                //get the element to draw
                var coordinate = coordinateProperties.GetArrayElementAtIndex(i);

                //label for each location.
                var coordinateLabel = String.Format("Location {0}", i);

                // draw coordinate string.
                EditorGUI.BeginChangeCheck();
                coordinate.stringValue = EditorGUILayout.TextField(coordinateLabel, coordinate.stringValue);

                if (EditorGUI.EndChangeCheck())
                {
                    EditorHelper.CheckForModifiedProperty(property, true);
                }
                // draw search button.
                if (GUILayout.Button(new GUIContent(searchButtonContent), (GUIStyle)"minibuttonleft", GUILayout.MaxWidth(100)))
                {
                    object propertyObject = EditorHelper.GetTargetObjectOfProperty(property);
                    GeocodeAttributeSearchWindow.Open(coordinate, propertyObject);
                }

                //include a remove button in the row
                if (GUILayout.Button(new GUIContent(" X "), (GUIStyle)"minibuttonright", GUILayout.MaxWidth(30)))
                {
                    coordinateProperties.DeleteArrayElementAtIndex(i);
                    EditorHelper.CheckForModifiedProperty(property);
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUIUtility.labelWidth - 3);

            if (GUILayout.Button(new GUIContent("Add Location"), (GUIStyle)"minibutton"))
            {
                coordinateProperties.arraySize++;
                var newElement = coordinateProperties.GetArrayElementAtIndex(coordinateProperties.arraySize - 1);
                newElement.stringValue = "";
                EditorHelper.CheckForModifiedProperty(property);
            }
            EditorGUILayout.EndHorizontal();
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            objectId = property.serializedObject.targetObject.GetInstanceID().ToString();
            VectorFilterOptions options = (VectorFilterOptions)EditorHelper.GetTargetObjectOfProperty(property);

            showFilters = EditorGUILayout.Foldout(showFilters, new GUIContent {
                text = "Filters", tooltip = "Filter features in a vector layer based on criterion specified.  "
            });
            if (showFilters)
            {
                var propertyFilters = property.FindPropertyRelative("filters");

                for (int i = 0; i < propertyFilters.arraySize; i++)
                {
                    DrawLayerFilter(property, propertyFilters, i, options);
                }
                if (propertyFilters.arraySize > 0)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(property.FindPropertyRelative("combinerType"));
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorHelper.CheckForModifiedProperty(property);
                    }
                }
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * 12);

                EditorGUI.BeginChangeCheck();
                if (GUILayout.Button(new GUIContent("Add New Empty"), (GUIStyle)"minibutton"))
                {
                    options.AddFilter();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    EditorHelper.CheckForModifiedProperty(property);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            CoreVectorLayerProperties coreOptions = (CoreVectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property);

            EditorGUI.BeginProperty(position, null, property);

            var primitiveType = property.FindPropertyRelative("geometryType");

            var primitiveTypeLabel = new GUIContent
            {
                text    = "Primitive Type",
                tooltip = "Primitive geometry type of the visualizer, allowed primitives - point, line, polygon."
            };

            var displayNames = primitiveType.enumDisplayNames;
            int count        = primitiveType.enumDisplayNames.Length;

            if (!_isGUIContentSet)
            {
                _primitiveTypeContent = new GUIContent[count];
                for (int extIdx = 0; extIdx < count; extIdx++)
                {
                    _primitiveTypeContent[extIdx] = new GUIContent
                    {
                        text    = displayNames[extIdx],
                        tooltip = EnumExtensions.Description((VectorPrimitiveType)extIdx),
                    };
                }
                _isGUIContentSet = true;
            }

            primitiveType.enumValueIndex = EditorGUILayout.Popup(primitiveTypeLabel, primitiveType.enumValueIndex, _primitiveTypeContent);
            EditorHelper.CheckForModifiedProperty(primitiveType, coreOptions);

            if ((VectorPrimitiveType)primitiveType.enumValueIndex == VectorPrimitiveType.Line)
            {
                EditorGUILayout.PropertyField(property.FindPropertyRelative("lineWidth"));
                EditorHelper.CheckForModifiedProperty(property.FindPropertyRelative("lineWidth"), coreOptions);
            }
            EditorGUI.EndProperty();
        }
        public void DrawUI(SerializedProperty property)
        {
            objectId = property.serializedObject.targetObject.GetInstanceID().ToString();
            var         serializedMapObject = property.serializedObject;
            AbstractMap mapObject           = (AbstractMap)serializedMapObject.targetObject;

            tileJSONData = mapObject.VectorData.GetTileJsonData();

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

            var displayNames = sourceTypeProperty.enumDisplayNames;
            var names        = sourceTypeProperty.enumNames;
            int count        = sourceTypeProperty.enumDisplayNames.Length;

            if (!_isGUIContentSet)
            {
                _sourceTypeContent = new GUIContent[count];

                var index = 0;
                foreach (var name in names)
                {
                    _sourceTypeContent[index] = new GUIContent
                    {
                        text    = displayNames[index],
                        tooltip = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), name)).Description(),
                    };
                    index++;
                }

                //				for (int index0 = 0; index0 < count; index0++)
                //				{
                //					_sourceTypeContent[index0] = new GUIContent
                //					{
                //						text = displayNames[index0],
                //						tooltip = ((VectorSourceType)index0).Description(),
                //					};
                //				}
                _isGUIContentSet = true;
            }

            //sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
            sourceTypeValue = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), names[sourceTypeProperty.enumValueIndex]));
            var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
            var layerSourceProperty   = sourceOptionsProperty.FindPropertyRelative("layerSource");
            var layerSourceId         = layerSourceProperty.FindPropertyRelative("Id");
            var isActiveProperty      = sourceOptionsProperty.FindPropertyRelative("isActive");

            switch (sourceTypeValue)
            {
            case VectorSourceType.MapboxStreets:
            case VectorSourceType.MapboxStreetsV8:
            case VectorSourceType.MapboxStreetsWithBuildingIds:
            case VectorSourceType.MapboxStreetsV8WithBuildingIds:
                var sourcePropertyValue = MapboxDefaultVector.GetParameters(sourceTypeValue);
                layerSourceId.stringValue = sourcePropertyValue.Id;
                GUI.enabled = false;
                if (_isInitialized)
                {
                    LoadEditorTileJSON(property, sourceTypeValue, layerSourceId.stringValue);
                }
                else
                {
                    _isInitialized = true;
                }
                if (tileJSONData.PropertyDisplayNames.Count == 0 && tileJSONData.tileJSONLoaded)
                {
                    EditorGUILayout.HelpBox("Invalid Tileset Id / There might be a problem with the internet connection.", MessageType.Error);
                }
                GUI.enabled = true;
                isActiveProperty.boolValue = true;
                break;

            case VectorSourceType.Custom:
                if (_isInitialized)
                {
                    string test = layerSourceId.stringValue;
                    LoadEditorTileJSON(property, sourceTypeValue, layerSourceId.stringValue);
                }
                else
                {
                    _isInitialized = true;
                }
                if (tileJSONData.PropertyDisplayNames.Count == 0 && tileJSONData.tileJSONLoaded)
                {
                    EditorGUILayout.HelpBox("Invalid Tileset Id / There might be a problem with the internet connection.", MessageType.Error);
                }
                isActiveProperty.boolValue = true;
                break;

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

            default:
                isActiveProperty.boolValue = false;
                break;
            }

            if (sourceTypeValue != VectorSourceType.None)
            {
                EditorGUILayout.LabelField(new GUIContent
                {
                    text    = "Map Features",
                    tooltip = "Visualizers for vector features contained in a layer. "
                });

                var subLayerArray = property.FindPropertyRelative("vectorSubLayers");

                var layersRect = EditorGUILayout.GetControlRect(GUILayout.MinHeight(Mathf.Max(subLayerArray.arraySize + 1, 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight),
                                                                GUILayout.MaxHeight((subLayerArray.arraySize + 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight));

                if (!m_Initialized)
                {
                    bool firstInit   = m_MultiColumnHeaderState == null;
                    var  headerState = FeatureSubLayerTreeView.CreateDefaultMultiColumnHeaderState();
                    if (MultiColumnHeaderState.CanOverwriteSerializedFields(m_MultiColumnHeaderState, headerState))
                    {
                        MultiColumnHeaderState.OverwriteSerializedFields(m_MultiColumnHeaderState, headerState);
                    }
                    m_MultiColumnHeaderState = headerState;

                    var multiColumnHeader = new FeatureSectionMultiColumnHeader(headerState);

                    if (firstInit)
                    {
                        multiColumnHeader.ResizeToFit();
                    }

                    treeModel = new TreeModel <FeatureTreeElement>(GetData(subLayerArray));
                    if (m_TreeViewState == null)
                    {
                        m_TreeViewState = new TreeViewState();
                    }

                    if (layerTreeView == null)
                    {
                        layerTreeView = new FeatureSubLayerTreeView(m_TreeViewState, multiColumnHeader, treeModel);
                    }
                    layerTreeView.multiColumnHeader = multiColumnHeader;
                    m_Initialized = true;
                }
                layerTreeView.Layers = subLayerArray;
                layerTreeView.Reload();
                layerTreeView.OnGUI(layersRect);

                if (layerTreeView.hasChanged)
                {
                    EditorHelper.CheckForModifiedProperty(property);
                    layerTreeView.hasChanged = false;
                }

                selectedLayers = layerTreeView.GetSelection();

                //if there are selected elements, set the selection index at the first element.
                //if not, use the Selection index to persist the selection at the right index.
                if (selectedLayers.Count > 0)
                {
                    //ensure that selectedLayers[0] isn't out of bounds
                    if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdFeature > subLayerArray.arraySize - 1)
                    {
                        selectedLayers[0] = subLayerArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdFeature;
                    }

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

                GUILayout.Space(EditorGUIUtility.singleLineHeight);

                EditorGUILayout.BeginHorizontal();
                GenericMenu menu = new GenericMenu();
                foreach (var name in Enum.GetNames(typeof(PresetFeatureType)))
                {
                    menu.AddItem(new GUIContent()
                    {
                        text = name
                    }, false, FetchPresetProperties, name);
                }
                GUILayout.Space(0);                 // do not remove this line; it is needed for the next line to work
                Rect rect = GUILayoutUtility.GetLastRect();
                rect.y += 2 * _lineHeight / 3;

                if (EditorGUILayout.DropdownButton(new GUIContent {
                    text = "Add Feature"
                }, FocusType.Passive, (GUIStyle)"minibuttonleft"))
                {
                    menu.DropDown(rect);
                }

                //Assign subLayerProperties after fetching it from the presets class. This happens everytime an element is added
                if (subLayerProperties != null)
                {
                    subLayerArray.arraySize++;
                    var subLayer = subLayerArray.GetArrayElementAtIndex(subLayerArray.arraySize - 1);
                    SetSubLayerProps(subLayer);

                    //Refreshing the tree
                    layerTreeView.Layers = subLayerArray;
                    layerTreeView.AddElementToTree(subLayer);
                    layerTreeView.Reload();

                    selectedLayers = new int[1] {
                        subLayerArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdFeature
                    };
                    layerTreeView.SetSelection(selectedLayers);
                    subLayerProperties = null;                     // setting this to null so that the if block is not called again

                    if (EditorHelper.DidModifyProperty(property))
                    {
                        isLayerAdded = true;
                    }
                }

                if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright"))
                {
                    foreach (var index in selectedLayers.OrderByDescending(i => i))
                    {
                        if (layerTreeView != null)
                        {
                            var subLayer = subLayerArray.GetArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdFeature);

                            VectorLayerProperties    vectorLayerProperties    = (VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property);
                            VectorSubLayerProperties vectorSubLayerProperties = (VectorSubLayerProperties)EditorHelper.GetTargetObjectOfProperty(subLayer);

                            vectorLayerProperties.OnSubLayerPropertyRemoved(new VectorLayerUpdateArgs {
                                property = vectorSubLayerProperties
                            });

                            layerTreeView.RemoveItemFromTree(index);
                            subLayerArray.DeleteArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdFeature);
                            layerTreeView.treeModel.SetData(GetData(subLayerArray));
                        }
                    }

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

                EditorGUILayout.EndHorizontal();

                GUILayout.Space(EditorGUIUtility.singleLineHeight);

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

                    SelectionIndex = selectedLayers[0];

                    var layerProperty = subLayerArray.GetArrayElementAtIndex(SelectionIndex - FeatureSubLayerTreeView.uniqueIdFeature);

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

                    DrawLayerVisualizerProperties(sourceTypeValue, layerProperty, property);

                    if (!isLayerActive)
                    {
                        GUI.enabled = true;
                    }
                }
                else
                {
                    GUILayout.Label("Select a visualizer to see properties");
                }
            }
        }
        void CellGUI(Rect cellRect, TreeViewItem <FeatureTreeElement> item, FeatureSubLayerColumns column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            if (Layers == null || Layers.arraySize == 0)
            {
                return;
            }

            if (Layers.arraySize <= args.item.id - uniqueId)
            {
                return;
            }

            var layer = Layers.GetArrayElementAtIndex(args.item.id - uniqueId);

            CenterRectUsingSingleLineHeight(ref cellRect);
            if (column == FeatureSubLayerColumns.Name)
            {
                Rect toggleRect = cellRect;
                toggleRect.x    += GetContentIndent(item);
                toggleRect.width = kToggleWidth;

                EditorGUI.BeginChangeCheck();
                item.data.isActive = layer.FindPropertyRelative("coreOptions.isActive").boolValue;
                if (toggleRect.xMax < cellRect.xMax)
                {
                    item.data.isActive = EditorGUI.Toggle(toggleRect, item.data.isActive);                     // hide when outside cell rect
                }
                layer.FindPropertyRelative("coreOptions.isActive").boolValue = item.data.isActive;
                if (EditorGUI.EndChangeCheck())
                {
                    VectorSubLayerProperties vectorSubLayerProperties = (VectorSubLayerProperties)EditorHelper.GetTargetObjectOfProperty(layer);
                    EditorHelper.CheckForModifiedProperty(layer, vectorSubLayerProperties.coreOptions);
                }

                cellRect.xMin += nameOffset;                 // Adding some gap between the checkbox and the name
                args.rowRect   = cellRect;

                layer.FindPropertyRelative("coreOptions.sublayerName").stringValue = item.data.Name;
                //This draws the name property
                base.RowGUI(args);
            }
            if (column == FeatureSubLayerColumns.Type)
            {
                cellRect.xMin += 15f;                 // Adding some gap between the checkbox and the name

                var typeString = ((PresetFeatureType)layer.FindPropertyRelative("presetFeatureType").intValue).ToString();
                item.data.Type = typeString;
                EditorGUI.LabelField(cellRect, item.data.Type, columnStyle);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GeometryExtrusionOptions extrusionOptions = (GeometryExtrusionOptions)EditorHelper.GetTargetObjectOfProperty(property);

            var extrusionTypeProperty = property.FindPropertyRelative("extrusionType");
            var displayNames          = extrusionTypeProperty.enumDisplayNames;
            int count = extrusionTypeProperty.enumDisplayNames.Length;

            if (!isGUIContentSet)
            {
                extrusionTypeContent = new GUIContent[count];
                for (int extIdx = 0; extIdx < count; extIdx++)
                {
                    extrusionTypeContent[extIdx] = new GUIContent
                    {
                        text    = displayNames[extIdx],
                        tooltip = EnumExtensions.Description((ExtrusionType)extIdx),
                    };
                }
                isGUIContentSet = true;
            }

            var extrusionTypeLabel = new GUIContent
            {
                text    = "Extrusion Type",
                tooltip = "Type of geometry extrusion"
            };

            extrusionTypeProperty.enumValueIndex = EditorGUILayout.Popup(extrusionTypeLabel, extrusionTypeProperty.enumValueIndex, extrusionTypeContent);
            EditorHelper.CheckForModifiedProperty(extrusionTypeProperty, extrusionOptions);

            var sourceTypeValue = (Unity.Map.ExtrusionType)extrusionTypeProperty.enumValueIndex;

            var minHeightProperty = property.FindPropertyRelative("minimumHeight");
            var maxHeightProperty = property.FindPropertyRelative("maximumHeight");

            var extrusionGeometryType = property.FindPropertyRelative("extrusionGeometryType");
            var extrusionGeometryGUI  = new GUIContent {
                text = "Geometry Type", tooltip = EnumExtensions.Description((Unity.Map.ExtrusionGeometryType)extrusionGeometryType.enumValueIndex)
            };

            EditorGUI.indentLevel++;
            switch (sourceTypeValue)
            {
            case Unity.Map.ExtrusionType.None:
                break;

            case Unity.Map.ExtrusionType.PropertyHeight:
                EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
                DrawPropertyDropDown(property, position);
                break;

            case Unity.Map.ExtrusionType.MinHeight:
                EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
                DrawPropertyDropDown(property, position);
                break;

            case Unity.Map.ExtrusionType.MaxHeight:
                EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
                DrawPropertyDropDown(property, position);
                break;

            case Unity.Map.ExtrusionType.RangeHeight:
                EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
                DrawPropertyDropDown(property, position);
                EditorGUILayout.PropertyField(minHeightProperty);
                EditorGUILayout.PropertyField(maxHeightProperty);
                if (minHeightProperty.floatValue > maxHeightProperty.floatValue)
                {
                    EditorGUILayout.HelpBox("Maximum Height less than Minimum Height!", MessageType.Error);
                }
                break;

            case Unity.Map.ExtrusionType.AbsoluteHeight:
                EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
                EditorGUILayout.PropertyField(maxHeightProperty, new GUIContent {
                    text = "Height"
                });
                break;

            default:
                break;
            }

            EditorHelper.CheckForModifiedProperty(extrusionGeometryType, extrusionOptions);

            EditorGUILayout.PropertyField(property.FindPropertyRelative("extrusionScaleFactor"), new GUIContent {
                text = "Scale Factor"
            });
            EditorHelper.CheckForModifiedProperty(property.FindPropertyRelative("extrusionScaleFactor"), extrusionOptions);

            EditorGUI.indentLevel--;
        }
        public void DrawUI(SerializedProperty subLayerCoreOptions, SerializedProperty layerProperty, VectorPrimitiveType primitiveTypeProp)
        {
            VectorSubLayerProperties vectorSubLayerProperties = (VectorSubLayerProperties)EditorHelper.GetTargetObjectOfProperty(layerProperty);

            objectId = layerProperty.serializedObject.targetObject.GetInstanceID().ToString();

            EditorGUILayout.BeginVertical();
            showModeling = EditorGUILayout.Foldout(showModeling, new GUIContent {
                text = "Modeling", tooltip = "This section provides you with options to fine tune your meshes"
            });
            if (showModeling)
            {
                GUILayout.Space(-_lineHeight);
                EditorGUILayout.PropertyField(subLayerCoreOptions);

                if (primitiveTypeProp != VectorPrimitiveType.Point && primitiveTypeProp != VectorPrimitiveType.Custom)
                {
                    GUILayout.Space(-_lineHeight);
                    var extrusionOptions = layerProperty.FindPropertyRelative("extrusionOptions");
                    extrusionOptions.FindPropertyRelative("_selectedLayerName").stringValue = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue;
                    EditorGUILayout.PropertyField(extrusionOptions);
                }

                var snapToTerrainProperty = subLayerCoreOptions.FindPropertyRelative("snapToTerrain");
                snapToTerrainProperty.boolValue = EditorGUILayout.Toggle(snapToTerrainProperty.displayName, snapToTerrainProperty.boolValue);
                EditorHelper.CheckForModifiedProperty(snapToTerrainProperty, vectorSubLayerProperties);

                var combineMeshesProperty = subLayerCoreOptions.FindPropertyRelative("combineMeshes");
                combineMeshesProperty.boolValue = EditorGUILayout.Toggle(combineMeshesProperty.displayName, combineMeshesProperty.boolValue);
                EditorHelper.CheckForModifiedProperty(combineMeshesProperty, vectorSubLayerProperties);

                if (primitiveTypeProp != VectorPrimitiveType.Point && primitiveTypeProp != VectorPrimitiveType.Custom)
                {
                    EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("colliderOptions"));
                }
            }
            EditorGUILayout.EndVertical();
        }
        void OnGUI()
        {
            if (_assets == null || _assets.Count == 0)
            {
                var list = AssetDatabase.FindAssets("t:" + _type.Name);
                _assets = new List <ScriptableObject>();
                foreach (var item in list)
                {
                    var ne    = AssetDatabase.GUIDToAssetPath(item);
                    var asset = AssetDatabase.LoadAssetAtPath(ne, _type) as ScriptableObject;
                    _assets.Add(asset);
                }
                _assets = _assets.OrderBy(x => x.GetType().Name).ThenBy(x => x.name).ToList();
            }

            var st = new GUIStyle();

            st.padding = new RectOffset(15, 15, 15, 15);
            scrollPos  = EditorGUILayout.BeginScrollView(scrollPos, st);
            for (int i = 0; i < _assets.Count; i++)
            {
                var asset = _assets[i];
                if (asset == null)                 //yea turns out this can happen
                {
                    continue;
                }
                GUILayout.BeginHorizontal();

                var b = Header(string.Format("{0,-40} - {1, -15}", asset.GetType().Name, asset.name), i == activeIndex);

                if (b)
                {
                    activeIndex = i;
                }
                if (GUILayout.Button(new GUIContent("Select"), header, GUILayout.Width(80)))
                {
                    if (_act != null)
                    {
                        _act(asset);
                    }
                    else
                    {
                        if (_index == -1)
                        {
                            _finalize.arraySize++;
                            _finalize.GetArrayElementAtIndex(_finalize.arraySize - 1).objectReferenceValue = asset;
                            _finalize.serializedObject.ApplyModifiedProperties();
                        }
                        else
                        {
                            _finalize.GetArrayElementAtIndex(_index).objectReferenceValue = asset;
                            _finalize.serializedObject.ApplyModifiedProperties();
                        }
                    }

                    MapboxDataProperty mapboxDataProperty = (MapboxDataProperty)EditorHelper.GetTargetObjectOfProperty(_container);
                    if (mapboxDataProperty != null)
                    {
                        mapboxDataProperty.HasChanged = true;
                    }

                    this.Close();
                }

                GUILayout.EndHorizontal();
                if (b)
                {
                    EditorGUILayout.Space();
                    EditorGUI.indentLevel += 4;
                    GUI.enabled            = false;
                    var ed = UnityEditor.Editor.CreateEditor(asset);
                    ed.hideFlags = HideFlags.NotEditable;
                    ed.OnInspectorGUI();
                    GUI.enabled            = true;
                    EditorGUI.indentLevel -= 4;
                    EditorGUILayout.Space();
                }
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndScrollView();
        }
예제 #11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            objectId = property.serializedObject.targetObject.GetInstanceID().ToString();

            GeometryMaterialOptions materialOptions = (GeometryMaterialOptions)EditorHelper.GetTargetObjectOfProperty(property);

            showTexturing = EditorGUILayout.Foldout(showTexturing, new GUIContent {
                text = "Texturing", tooltip = "Material options to texture the generated building geometry"
            });
            if (showTexturing)
            {
                LoadDefaultStyleIcons();
                EditorGUI.BeginProperty(position, label, property);

                var styleTypeLabel = new GUIContent {
                    text = "Style Type", tooltip = "Texturing style for feature; choose from sample style or create your own by choosing Custom. "
                };
                var styleType = property.FindPropertyRelative("style");

                GUIContent[] styleTypeGuiContent = new GUIContent[styleType.enumDisplayNames.Length];
                for (int i = 0; i < styleType.enumDisplayNames.Length; i++)
                {
                    styleTypeGuiContent[i] = new GUIContent
                    {
                        text = styleType.enumDisplayNames[i]
                    };
                }

                styleType.enumValueIndex = EditorGUILayout.Popup(styleTypeLabel, styleType.enumValueIndex, styleTypeGuiContent);
                EditorHelper.CheckForModifiedProperty(styleType, materialOptions);

                EditorGUI.indentLevel++;
                if ((StyleTypes)styleType.enumValueIndex != StyleTypes.Custom)
                {
                    GUILayout.BeginHorizontal();

                    var style = (StyleTypes)styleType.enumValueIndex;

                    Texture2D thumbnailTexture = (Texture2D)_styleIconBundles[style].texture;

                    if ((StyleTypes)styleType.enumValueIndex == StyleTypes.Simple)
                    {
                        var samplePaletteType = property.FindPropertyRelative("samplePalettes");
                        var palette           = (SamplePalettes)samplePaletteType.enumValueIndex;
                        thumbnailTexture = (Texture2D)_paletteIconBundles[palette].texture;
                    }

                    string descriptionLabel = EnumExtensions.Description(style);
                    EditorGUILayout.LabelField(new GUIContent(" ", thumbnailTexture), Constants.GUI.Styles.EDITOR_TEXTURE_THUMBNAIL_STYLE, GUILayout.Height(60), GUILayout.Width(EditorGUIUtility.labelWidth - 60));
                    EditorGUILayout.TextArea(descriptionLabel, (GUIStyle)"wordWrappedLabel");

                    GUILayout.EndHorizontal();

                    switch ((StyleTypes)styleType.enumValueIndex)
                    {
                    case StyleTypes.Simple:
                        var samplePaletteType      = property.FindPropertyRelative("samplePalettes");
                        var samplePaletteTypeLabel = new GUIContent {
                            text = "Palette Type", tooltip = "Palette type for procedural colorization; choose from sample palettes or create your own by choosing Custom. "
                        };

                        GUIContent[] samplePaletteTypeGuiContent = new GUIContent[samplePaletteType.enumDisplayNames.Length];
                        for (int i = 0; i < samplePaletteType.enumDisplayNames.Length; i++)
                        {
                            samplePaletteTypeGuiContent[i] = new GUIContent
                            {
                                text = samplePaletteType.enumDisplayNames[i]
                            };
                        }
                        samplePaletteType.enumValueIndex = EditorGUILayout.Popup(samplePaletteTypeLabel, samplePaletteType.enumValueIndex, samplePaletteTypeGuiContent);
                        EditorHelper.CheckForModifiedProperty(samplePaletteType, materialOptions);
                        break;

                    case StyleTypes.Light:
                        property.FindPropertyRelative("lightStyleOpacity").floatValue = EditorGUILayout.Slider("Opacity", property.FindPropertyRelative("lightStyleOpacity").floatValue, 0.0f, 1.0f);
                        EditorHelper.CheckForModifiedProperty(property.FindPropertyRelative("lightStyleOpacity"), materialOptions);
                        break;

                    case StyleTypes.Dark:
                        property.FindPropertyRelative("darkStyleOpacity").floatValue = EditorGUILayout.Slider("Opacity", property.FindPropertyRelative("darkStyleOpacity").floatValue, 0.0f, 1.0f);
                        EditorHelper.CheckForModifiedProperty(property.FindPropertyRelative("darkStyleOpacity"), materialOptions);
                        break;

                    case StyleTypes.Color:
                        property.FindPropertyRelative("colorStyleColor").colorValue = EditorGUILayout.ColorField("Color", property.FindPropertyRelative("colorStyleColor").colorValue);
                        EditorHelper.CheckForModifiedProperty(property.FindPropertyRelative("colorStyleColor"), materialOptions);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    var texturingType = property.FindPropertyRelative("texturingType");

                    int valIndex         = texturingType.enumValueIndex == 0 ? 0 : texturingType.enumValueIndex + 1;
                    var texturingTypeGUI = new GUIContent {
                        text = "Texturing Type", tooltip = EnumExtensions.Description((UvMapType)valIndex)
                    };

                    EditorGUILayout.PropertyField(texturingType, texturingTypeGUI);
                    EditorHelper.CheckForModifiedProperty(texturingType, materialOptions);

                    var matList = property.FindPropertyRelative("materials");
                    if (matList.arraySize == 0)
                    {
                        matList.arraySize = 2;
                    }
                    GUILayout.Space(-lineHeight);

                    EditorGUILayout.PropertyField(matList.GetArrayElementAtIndex(0), new GUIContent {
                        text = "Top Material", tooltip = "Unity material to use for extruded top/roof mesh. "
                    });
                    EditorHelper.CheckForModifiedProperty(matList.GetArrayElementAtIndex(0), materialOptions);

                    GUILayout.Space(-lineHeight);

                    EditorGUILayout.PropertyField(matList.GetArrayElementAtIndex(1), new GUIContent {
                        text = "Side Material", tooltip = "Unity material to use for extruded side/wall mesh. "
                    });
                    EditorHelper.CheckForModifiedProperty(matList.GetArrayElementAtIndex(1), materialOptions);

                    if ((UvMapType)texturingType.enumValueIndex + 1 == UvMapType.Atlas)
                    {
                        var atlasInfo = property.FindPropertyRelative("atlasInfo");
                        EditorGUILayout.ObjectField(atlasInfo, new GUIContent {
                            text = "Altas Info", tooltip = "Atlas information scriptable object, this defines how the texture roof and wall texture atlases will be used.  "
                        });
                        EditorHelper.CheckForModifiedProperty(atlasInfo, materialOptions);
                    }
                    if ((UvMapType)texturingType.enumValueIndex + 1 == UvMapType.AtlasWithColorPalette)
                    {
                        var atlasInfo = property.FindPropertyRelative("atlasInfo");
                        EditorGUILayout.ObjectField(atlasInfo, new GUIContent {
                            text = "Altas Info", tooltip = "Atlas information scriptable object, this defines how the texture roof and wall texture atlases will be used.  "
                        });
                        EditorHelper.CheckForModifiedProperty(atlasInfo, materialOptions);

                        var colorPalette = property.FindPropertyRelative("colorPalette");
                        EditorGUILayout.ObjectField(colorPalette, new GUIContent {
                            text = "Color Palette", tooltip = "Color palette scriptable object, allows texture features to be procedurally colored at runtime. Requires materials that use the MapboxPerRenderer shader. "
                        });
                        EditorHelper.CheckForModifiedProperty(colorPalette, materialOptions);

                        EditorGUILayout.LabelField(new GUIContent {
                            text = "Note: Atlas With Color Palette requires materials that use the MapboxPerRenderer shader."
                        }, Constants.GUI.Styles.EDITOR_NOTE_STYLE);
                    }
                }
                EditorGUI.indentLevel--;
                EditorGUI.EndProperty();
            }
        }