Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 124 additions & 22 deletions sdkproject/Assets/Mapbox/Unity/Editor/MapManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine;
using UnityEditor;
using Mapbox.Unity.Map;
using Mapbox.VectorTile.ExtensionMethods;

[CustomEditor(typeof(AbstractMap))]
[CanEditMultipleObjects]
Expand Down Expand Up @@ -53,6 +54,23 @@ bool ShowTerrain
EditorPrefs.SetBool("MapManagerEditor_showTerrain", value);
}
}

/// <summary>
/// Gets or sets a value to show or hide Map Layers section <see cref="T:Mapbox.Editor.MapManagerEditor"/> show features.
/// </summary>
/// <value><c>true</c> if show features; otherwise, <c>false</c>.</value>
bool ShowMapLayers
{
get
{
return EditorPrefs.GetBool("MapManagerEditor_showMapLayers");
}
set
{
EditorPrefs.SetBool("MapManagerEditor_showMapLayers", value);
}
}

/// <summary>
/// Gets or sets a value to show or hide Vector section <see cref="T:Mapbox.Editor.MapManagerEditor"/>.
/// </summary>
Expand All @@ -73,7 +91,7 @@ bool ShowLocationPrefabs
/// Gets or sets a value to show or hide Vector section <see cref="T:Mapbox.Editor.MapManagerEditor"/>.
/// </summary>
/// <value><c>true</c> if show vector; otherwise, <c>false</c>.</value>
bool ShowVector
bool ShowFeatures
{
get
{
Expand All @@ -98,12 +116,27 @@ bool ShowPosition
}
}

private GUIContent _mapIdGui = new GUIContent
private GUIContent _requiredMapIdGui = new GUIContent
{
text = "Required Map Id",
tooltip = "For location prefabs to spawn the \"streets-v7\" tileset needs to be a part of the Vector data source"
};

private GUIContent mapIdGui = new GUIContent
{
text = "Map Id",
tooltip = "Map Id corresponding to the tileset."
};

string CustomSourceMapId
{
get { return EditorPrefs.GetString("VectorLayerProperties_customSourceMapId"); }
set { EditorPrefs.SetString("VectorLayerProperties_customSourceMapId", value); }
}

bool _isGUIContentSet = false;
GUIContent[] _sourceTypeContent;

public override void OnInspectorGUI()
{
serializedObject.Update();
Expand Down Expand Up @@ -135,38 +168,107 @@ public override void OnInspectorGUI()

ShowSepartor();

ShowLocationPrefabs = EditorGUILayout.Foldout(ShowLocationPrefabs, "LOCATION PREFABS");
if (ShowLocationPrefabs)
ShowMapLayers = EditorGUILayout.Foldout(ShowMapLayers, "MAP LAYERS");
if (ShowMapLayers)
{
EditorGUI.indentLevel++;
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;
var sourceTypeProperty = layerProperty.FindPropertyRelative("_sourceType");
VectorSourceType sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
string streets_v7 = MapboxDefaultVector.GetParameters(VectorSourceType.MapboxStreets).Id;
string layerString = layerProperty.FindPropertyRelative("sourceOptions.layerSource.Id").stringValue;
var layerSourceId = layerProperty.FindPropertyRelative("sourceOptions.layerSource.Id");
string layerString = layerSourceId.stringValue;
var isActiveProperty = layerSourceProperty.FindPropertyRelative("isActive");

if(sourceTypeValue != VectorSourceType.None && layerString.Contains(streets_v7))
var displayNames = sourceTypeProperty.enumDisplayNames;
int count = sourceTypeProperty.enumDisplayNames.Length;
if (!_isGUIContentSet)
{
GUI.enabled = false;
EditorGUILayout.TextField(_mapIdGui, streets_v7);
GUI.enabled = true;
ShowSection(vectorDataProperty, "_locationPrefabsLayerProperties");
_sourceTypeContent = new GUIContent[count];
for (int extIdx = 0; extIdx < count; extIdx++)
{
_sourceTypeContent[extIdx] = new GUIContent
{
text = displayNames[extIdx],
tooltip = ((VectorSourceType)extIdx).Description(),
};
}

_isGUIContentSet = true;
}
else

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

sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;

switch (sourceTypeValue)
{
EditorGUILayout.HelpBox("In order to place location prefabs please add \"mapbox.mapbox-streets-v7\" to the data source in the Vector section.",MessageType.Error);
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:
layerSourceId.stringValue = CustomSourceMapId;
EditorGUILayout.PropertyField(layerSourceProperty, mapIdGui);
CustomSourceMapId = layerSourceId.stringValue;
isActiveProperty.boolValue = true;
break;
case VectorSourceType.None:
isActiveProperty.boolValue = false;
break;
default:
isActiveProperty.boolValue = false;
break;
}
}

ShowSepartor();
if (sourceTypeValue != VectorSourceType.None)
{
var isStyleOptimized = layerProperty.FindPropertyRelative("useOptimizedStyle");
EditorGUILayout.PropertyField(isStyleOptimized);

ShowVector = EditorGUILayout.Foldout(ShowVector, "VECTOR");
if (ShowVector)
{
ShowSection(serializedObject.FindProperty("_vectorData"), "_layerProperty");
if (isStyleOptimized.boolValue)
{
EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("optimizedStyle"), new GUIContent("Style Options"));
}

EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("performanceOptions"), new GUIContent("Perfomance Options"));
}
EditorGUILayout.Space();
ShowSepartor();

ShowLocationPrefabs = EditorGUILayout.Foldout(ShowLocationPrefabs, "POINTS OF INTEREST");
if (ShowLocationPrefabs)
{
if (sourceTypeValue != VectorSourceType.None && layerString.Contains(streets_v7))
{
GUI.enabled = false;
EditorGUILayout.TextField(_requiredMapIdGui, 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.", MessageType.Error);
}
}
ShowSepartor();
ShowFeatures = EditorGUILayout.Foldout(ShowFeatures, "FEATURES");
if (ShowFeatures)
{
ShowSection(serializedObject.FindProperty("_vectorData"), "_layerProperty");
}
EditorGUI.indentLevel--;
}
GUILayout.EndVertical();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class LayerPerformanceOptionsDrawer : PropertyDrawer
{
static float lineHeight = EditorGUIUtility.singleLineHeight;

static int checkBoxOffset = 15;
SerializedProperty isActiveProperty;

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
Expand All @@ -18,6 +18,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
EditorGUI.BeginProperty(position, label, property);
position.height = lineHeight;
var typePosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Enable Coroutines"));
typePosition.x -= checkBoxOffset;
isActiveProperty.boolValue = EditorGUI.Toggle(typePosition, isActiveProperty.boolValue);

if (isActiveProperty.boolValue == true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
EditorGUI.BeginProperty(position, label, property);
position.height = _lineHeight;
GUILayout.Space(-_lineHeight);

var prefabItemArray = property.FindPropertyRelative("locationPrefabList");
var layersRect = GUILayoutUtility.GetRect(0, 500, Mathf.Max(prefabItemArray.arraySize + 1, 1) * _lineHeight, (prefabItemArray.arraySize + 1) * _lineHeight);
layerTreeView.Layers = prefabItemArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
GUILayout.Label(prefabLocationsTitle);

//FindBy drop down
EditorGUI.indentLevel--;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel(findByDropDown);
var findByProp = property.FindPropertyRelative("findByType");
Expand All @@ -84,6 +85,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
default:
break;
}
EditorGUI.indentLevel++;

EditorGUI.EndProperty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
public class VectorLayerPropertiesDrawer : PropertyDrawer
{
static float _lineHeight = EditorGUIUtility.singleLineHeight;
GUIContent[] _sourceTypeContent;
bool _isGUIContentSet = false;

bool ShowPosition
{
Expand All @@ -36,18 +34,6 @@ int SelectionIndex
set { EditorPrefs.SetInt("VectorLayerProperties_selectionIndex", value); }
}

string CustomSourceMapId
{
get { return EditorPrefs.GetString("VectorLayerProperties_customSourceMapId"); }
set { EditorPrefs.SetString("VectorLayerProperties_customSourceMapId", value); }
}

private GUIContent _mapIdGui = new GUIContent
{
text = "Map Id",
tooltip = "Map Id corresponding to the tileset."
};

VectorSubLayerTreeView layerTreeView = new VectorSubLayerTreeView(new TreeViewState());
IList<int> selectedLayers = new List<int>();

Expand All @@ -56,84 +42,12 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
EditorGUI.BeginProperty(position, label, property);
position.height = _lineHeight;

GUILayout.Space(-_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",
Expand All @@ -144,12 +58,10 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
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.
Expand Down Expand Up @@ -280,6 +192,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

void DrawLayerVisualizerProperties(VectorSourceType sourceType, SerializedProperty layerProperty)
{
EditorGUI.indentLevel--;
var subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions");
EditorGUI.indentLevel++;
GUILayout.Label(subLayerCoreOptions.FindPropertyRelative("sublayerName").stringValue + " Properties");
Expand Down Expand Up @@ -332,6 +245,7 @@ void DrawLayerVisualizerProperties(VectorSourceType sourceType, SerializedProper
EditorGUI.indentLevel--;
GUILayout.EndVertical();
EditorGUI.indentLevel--;
EditorGUI.indentLevel++;
}

void DrawModifiers(SerializedProperty property, GUIContent label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ protected override void RenameEnded(RenameEndedArgs args)

protected override void RowGUI (RowGUIArgs args)
{
EditorGUI.indentLevel--;
Rect toggleRect = args.rowRect;
toggleRect.width = kToggleWidth;

var item = Layers.GetArrayElementAtIndex(args.item.id);
item.FindPropertyRelative("coreOptions.isActive").boolValue = EditorGUI.Toggle(toggleRect, item.FindPropertyRelative("coreOptions.isActive").boolValue);
args.item.displayName = item.FindPropertyRelative("coreOptions.sublayerName").stringValue;

base.RowGUI(args);

EditorGUI.indentLevel++;
}
}
}
Loading