Skip to content

Commit 300a5d0

Browse files
authored
Api ui integration (#1030)
* add a proof of concept for partial layer updates * Replaced bare EditorHelper.CheckForModifiedProperty calls with EditorGUILayout.Popup-centric Begin/EndChangeCheck-encapsulated EditorHelper.CheckForModifiedProperty calls. * - Added property.serializedObject.Update() calls to beginning of OnGUI calls in vector-centric property drawers. - Wrapped CheckForModifiedProperty calls in EndChangeCheck conditional checks. Added color-coded debug message for Vector layer in AbstractMap. - Added System.EventHandler LayerVisualizerHasChanged and OnUpdateLayerVisualizer method to LayerVisualizerBase. - Added System.EventHandler TileFactoryHasChanged and UpdateTileFactory method to AbstractTileFactory. - Chain of EventHandlers = VectorLayerVisualizer -> VectorTileFactory -> VectorLayer -> AbstractMap * Temporarily disabled Vector Update business in abstract map. * Adding/removing mesh and/or gameplay modifiers now triggers change events. * Removed unused EndChangeCheck call in BehaviorModifiersSectionDrawer; moved tile factory update/change event vars/methods into events section. * Added support for change events in vector filter section. * Fix ui errors vector section (#1011) * Fix PropertyDrawer errors when adding new layer. * Fix errors on adding filters. * Removed commented/dead property.serializedObject.Update() calls. * Added UI update checks for Behavior Modifier section. * Removed unused delegate and method. * Removed property.serializedObject.Update call at beginning of OnGUI. * Adding/removing map features now triggers update event. * Enabling/disabling map feature checkboxes now fires UI update events. * Changing DataSource in map features section now triggers update. For some reason, this is not working with EditorHelper.CheckForModifiedProperty; setting HasChanged manually does work. * VectorUpdate is now working; map redraws vector section on vector-centric UI changes. - Sequential Vector UI changes will cause over/re-registration for event handlers. We need to fix this. - Added debug message and comment re: register/unregistering for EventHandlers... * hook terrain layer property to property changed event. * Use the variable to set collider. * Add helper methods * Add update methods to MapboxDataProperty * Use new methods in MapboxDataProperty. * Remove SerializedObject.update * Add ChangeCheck for Vector DataSource. * Add NeedsForceUpdate override * Switch to UpdateProperty * Change Active from field to Property. * Update signature for NotifyUpdateLayer * Add ChangeImagery method to test. * Add VectorLayerUpdateArgs + overload for NotifyUpdateLayer * Hook to UpdateTileFactory event * Add hooks to UpdateModifier Event * Add abstract SublayerProperty * Add UnregisterTilesFromLayer method * Add method to change texturing type. * Remove static MapboxDefaultStyle class. * Add event hookup to modifiers * Add layer args for vector layers * Add events for Add/Remove layer * Add events for modifiers. * Change HasChanged to virtual, add overrides * Add event hookup to modifiers * Code cleanup * Trigger Collider option change from UI * Add a method to re-intialize stack. * Clean out stacks before recreating the layer. * Add events to trigger SubLayerAdded from UI * Remove Layer API and hooks * Add missing property * Add function to unbind properties from modifier. * UpdateVector method now unbinds all modifiers. * remove SnapTerrain and CombineMeshes from points. * Add UpdateMap call to trigger when UI is changed. * extract lineGeometryOptions to its own class (with drawer) change line mesh modifier to use new lineGeometryOptions data container object add line feature event bindings to VectorLayerVisualizer * add update event support to poi layer * extract lineGeometryOptions to its own class (with drawer) change line mesh modifier to use new lineGeometryOptions data container object add line feature event bindings to VectorLayerVisualizer * add update event support to poi layer * fix a bug where prefab modifier rupdate event registration wasn't firing after an update * fix filtering poi category by none with a hacky solution * Remove hack with a fix for POILayer being set to None. * Add map update logic to General section UI events. * Add property to trigger separate events for extentType & Extent property change. * Property drawer changes for extentOptions * Add API methods for General Section functionality. * Add APi method for snapMapToZero. * add api methods to terrain and imagery layers * Fix typo. * Fix typo * add update system functionality to add/remove poi layers on data property change (#1022) * fix an issue where poi layer didn't create prefab modifier for name and latlng settings (#1028) * Add multiple property methods (#1026) * add two SetProperties methods to terrain and image layer to set multiple properties at once * add comments to SetProperties methods * Move poi methods (#1023) * move poi api methods to vector layer add basic comments for terrain/image factory api methods * fix a broken method reference * change poi api methods to fire update events and work with runtime calls * POI section : Add Layer, Remove Selected, Enabled toggle all trigger change events. * Added change checks to PointsOfInterestSubLayerPropertiesDrawer. * Further work on getting POI UI changes to trigger updates. Removed Application.isPlaying check for density slider in PrefabItemOptionsDrawer. Events are firing corectly, but map is not redrawing with POI changes correctly, may need to apply modified properties early. * Change check for SpawnPrefabOptionsDrawer. * Removed unused change check. * Refactored EditorHelper.CheckForModifiedProperties to allow HasChanged to be brute force set to true. * Refactored GeocodeAttributeSearchWindow to accept an object to update in Open(), thus allowing classes that derive from MapboxDataProperty to be passed, thus allowing for direct calls to EditorHelper.CheckForModifiedProperty<T>(SerializedProperty property, T targetObject, bool forceHasChanged = false), thus eliminating the need for bool updateAbstractMap = false. Refactored relevant drawer code to reflect this change; refactored relevant drawer code with correct change check structure. * TEMP: Added comments to show what class is being modified on HasChanged = true sets. * Removed unused variable and conditional check. * Changed change check code to call OnSunlayerPropertiesAdded and OnSubLayerPropertyRemoved instead of generic HasChanged = true set. * Change default style for roads + layerName for custom. * Removed true argument from CheckForModifiedProperty. * add default poi prefab and use it on new poi layers * Fix bug which caused events to unbind when layer was added. * Remove unused variable * Removing prefab- comes in broken for older versions * Remove meta file
1 parent 6a68f3a commit 300a5d0

File tree

76 files changed

+2749
-890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2749
-890
lines changed

sdkproject/Assets/ApiTest.cs

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using Mapbox.Unity.Map;
5+
using Mapbox.Unity.MeshGeneration.Interfaces;
6+
using UnityEngine;
7+
8+
public class ApiTest : MonoBehaviour
9+
{
10+
private AbstractMap _abstractMap;
11+
public ImagerySourceType imagerySource = ImagerySourceType.MapboxStreets;
12+
13+
public LocationPrefabCategories LocationPrefabCategories;
14+
public GameObject PoiPrefab;
15+
16+
readonly StyleTypes[] testStyles = new StyleTypes[3] { StyleTypes.Fantasy, StyleTypes.Realistic, StyleTypes.Simple };
17+
int styleId = -1;
18+
void Start()
19+
{
20+
_abstractMap = FindObjectOfType<AbstractMap>();
21+
}
22+
23+
[ContextMenu("ChangeExtentType")]
24+
public void ChangeExtentType()
25+
{
26+
_abstractMap.SetExtent(MapExtentType.CameraBounds);
27+
}
28+
29+
[ContextMenu("ChangeExtentOptions")]
30+
public void ChangeExtentOptions()
31+
{
32+
_abstractMap.SetExtentOptions(new RangeTileProviderOptions { east = 2, west = 3, north = 0, south = 1 });
33+
}
34+
35+
36+
[ContextMenu("EnableTerrainColliders")]
37+
public void EnableTerrainColliders()
38+
{
39+
_abstractMap.Terrain.EnableCollider(true);
40+
}
41+
42+
[ContextMenu("DisableTerrainColliders")]
43+
public void DisableTerrainColliders()
44+
{
45+
_abstractMap.Terrain.EnableCollider(false);
46+
}
47+
48+
[ContextMenu("IncreaseTerrainExagguration")]
49+
public void IncreaseTerrainExagguration()
50+
{
51+
_abstractMap.Terrain.SetExaggerationFactor(_abstractMap.Terrain.LayerProperty.requiredOptions.exaggerationFactor + 0.5f);
52+
}
53+
54+
[ContextMenu("SetTerrainLayer")]
55+
public void SetTerrainLayer()
56+
{
57+
_abstractMap.Terrain.SetLayer(LayerMask.NameToLayer("Water"));
58+
}
59+
60+
[ContextMenu("SetTerrainDataSource")]
61+
public void SetTerrainDataSource()
62+
{
63+
if (_abstractMap.Terrain.LayerProperty.sourceType == ElevationSourceType.MapboxTerrain)
64+
{
65+
_abstractMap.Terrain.SetDataSource(ElevationSourceType.None);
66+
}
67+
else
68+
{
69+
_abstractMap.Terrain.SetDataSource(ElevationSourceType.MapboxTerrain);
70+
}
71+
}
72+
73+
[ContextMenu("EnableVectorColliders")]
74+
public void EnableVectorColliders()
75+
{
76+
var layer = _abstractMap.VectorData.LayerProperty.FindFeatureLayerWithName("ExtrudedBuildings");
77+
layer.colliderOptions.colliderType = ColliderType.MeshCollider;
78+
layer.colliderOptions.HasChanged = true;
79+
}
80+
81+
[ContextMenu("DisableVectorColliders")]
82+
public void DisableVectorColliders()
83+
{
84+
var layer = _abstractMap.VectorData.LayerProperty.FindFeatureLayerWithName("ExtrudedBuildings");
85+
layer.colliderOptions.colliderType = ColliderType.None;
86+
layer.colliderOptions.HasChanged = true;
87+
}
88+
89+
[ContextMenu("ChangeImagery")]
90+
public void ChangeImagery()
91+
{
92+
imagerySource = (imagerySource == ImagerySourceType.MapboxSatelliteStreet) ? ImagerySourceType.MapboxStreets : imagerySource + 1;
93+
_abstractMap.ImageLayer.SetLayerSource(imagerySource);
94+
}
95+
[ContextMenu("DisableLayer")]
96+
public void DisableLayer()
97+
{
98+
var layer = _abstractMap.VectorData.LayerProperty.FindFeatureLayerWithName("ExtrudedBuildings");
99+
if (layer != null)
100+
{
101+
layer.SetActive(false);
102+
}
103+
else
104+
{
105+
Debug.Log("Layer not found");
106+
}
107+
}
108+
109+
[ContextMenu("ChangeBuildingMaterial")]
110+
public void ChangeBuildingMaterial()
111+
{
112+
styleId = (styleId == 2) ? 0 : styleId + 1;
113+
var layer = _abstractMap.VectorData.LayerProperty.FindFeatureLayerWithName("ExtrudedBuildings");
114+
if (layer != null)
115+
{
116+
layer.SetTexturingType(testStyles[styleId]);
117+
}
118+
else
119+
{
120+
Debug.Log("Layer not found");
121+
}
122+
}
123+
124+
[ContextMenu("AddLayer")]
125+
public void AddLayer()
126+
{
127+
VectorSubLayerProperties subLayerProperties = new VectorSubLayerProperties();
128+
subLayerProperties.coreOptions.geometryType = VectorPrimitiveType.Polygon;
129+
subLayerProperties.coreOptions.layerName = "building";
130+
131+
_abstractMap.VectorData.LayerProperty.AddVectorLayer(subLayerProperties);
132+
}
133+
134+
[ContextMenu("AddPoiLayer")]
135+
public void AddPoiLayer()
136+
{
137+
var prefabItemOptions = new PrefabItemOptions();
138+
prefabItemOptions.categories = LocationPrefabCategories;
139+
prefabItemOptions.spawnPrefabOptions = new SpawnPrefabOptions();
140+
prefabItemOptions.spawnPrefabOptions.prefab = PoiPrefab;
141+
142+
_abstractMap.VectorData.LayerProperty.AddPoiLayer(prefabItemOptions);
143+
}
144+
145+
[ContextMenu("RemoveLayer")]
146+
public void RemoveLayer()
147+
{
148+
_abstractMap.VectorData.LayerProperty.RemoveFeatureLayerWithName("ExtrudedBuildings");
149+
}
150+
151+
[ContextMenu("RemovePoiLayer")]
152+
public void RemovePoiLayer()
153+
{
154+
_abstractMap.VectorData.LayerProperty.RemovePoiLayerWithName("loc");
155+
}
156+
157+
[ContextMenu("IncreaseRoadHeight")]
158+
public void IncreaseRoadHeight()
159+
{
160+
var roads = _abstractMap.VectorData.LayerProperty.FindFeatureLayerWithName("Roads");
161+
roads.extrusionOptions.maximumHeight = roads.extrusionOptions.maximumHeight + 2;
162+
roads.extrusionOptions.HasChanged = true;
163+
}
164+
165+
[ContextMenu("IncreaseRoadWidth")]
166+
public void IncreaseRoadWidth()
167+
{
168+
var roads = _abstractMap.VectorData.LayerProperty.FindFeatureLayerWithName("Roads");
169+
roads.lineGeometryOptions.Width = roads.lineGeometryOptions.Width + 2;
170+
roads.lineGeometryOptions.HasChanged = true;
171+
}
172+
173+
[ContextMenu("ChangePoiCategory")]
174+
public void ChangePoiCategory()
175+
{
176+
var pois = _abstractMap.VectorData.LayerProperty.FindPoiLayerWithName("loc");
177+
pois.categories = LocationPrefabCategories;
178+
Debug.Log("ChangePoiCategory ---> " + pois.GetType().ToString()); //PrefabItemOptions
179+
pois.HasChanged = true;
180+
}
181+
182+
[ContextMenu("ChangePoiPrefab")]
183+
public void ChangePoiPrefab()
184+
{
185+
var pois = _abstractMap.VectorData.LayerProperty.FindPoiLayerWithName("loc");
186+
pois.spawnPrefabOptions.prefab = PoiPrefab;
187+
Debug.Log("ChangePoiPrefab ---> " + pois.spawnPrefabOptions.GetType().ToString());//SpawnPrefabOptions
188+
pois.spawnPrefabOptions.HasChanged = true;
189+
}
190+
191+
[ContextMenu("ChangeToPoiByName")]
192+
public void ChangeToPoiByName()
193+
{
194+
var pois = _abstractMap.VectorData.LayerProperty.FindPoiLayerWithName("loc");
195+
pois.findByType = LocationPrefabFindBy.POIName;
196+
pois.nameString = "yerba";
197+
Debug.Log("ChangeToPoiByName ---> " + pois.GetType().ToString());//PrefabItemOptions
198+
pois.HasChanged = true;
199+
}
200+
201+
[ContextMenu("ChangeToCategory")]
202+
public void ChangeToCategory()
203+
{
204+
var pois = _abstractMap.VectorData.LayerProperty.FindPoiLayerWithName("loc");
205+
pois.findByType = LocationPrefabFindBy.MapboxCategory;
206+
Debug.Log("ChangeToCategory ---> " + pois.GetType().ToString());//PrefabItemOptions
207+
pois.HasChanged = true;
208+
}
209+
210+
[ContextMenu("TestPoiCategoryApi")]
211+
public void TestPoiCategoryApi()
212+
{
213+
_abstractMap.VectorData.SpawnPrefabByCategory(PoiPrefab, LocationPrefabCategories);
214+
}
215+
}

sdkproject/Assets/ApiTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)