From cdc8c5b2bc6c4c9d39231de1164a00071db80fae Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Fri, 3 Nov 2017 16:33:57 -0400 Subject: [PATCH 01/10] WIP Allow per builder material --- Assets/Editor/FilterStyleEditor.cs | 7 +-- Assets/Editor/LayerStyleEditor.cs | 84 +++++++++++++++++++++++--- Assets/Editor/PolygonBuilderEditor.cs | 2 + Assets/Editor/PolylineBuilderEditor.cs | 5 ++ Assets/Mapzen/Unity/FeatureStyle.cs | 67 +++++++++++++------- Assets/Mapzen/Unity/TileTask.cs | 18 ++++-- 6 files changed, 139 insertions(+), 44 deletions(-) diff --git a/Assets/Editor/FilterStyleEditor.cs b/Assets/Editor/FilterStyleEditor.cs index ae7b2220..266568c1 100644 --- a/Assets/Editor/FilterStyleEditor.cs +++ b/Assets/Editor/FilterStyleEditor.cs @@ -82,12 +82,7 @@ private void AddLayerStyleLayout(FeatureStyle.FilterStyle filterStyle, string na } else { - var layerStyle = new FeatureStyle.LayerStyle(name); - - // Default configuration for the layer - layerStyle.PolygonBuilderOptions = PolygonBuilderEditor.DefaultOptions(); - layerStyle.PolylineBuilderOptions = PolylineBuilderEditor.DefaultOptions(); - layerStyle.Material = new Material(Shader.Find("Diffuse")); + var layerStyle = new FeatureStyle.LayerStyle(name); filterStyle.LayerStyles.Add(layerStyle); diff --git a/Assets/Editor/LayerStyleEditor.cs b/Assets/Editor/LayerStyleEditor.cs index da8b0387..36e0129b 100644 --- a/Assets/Editor/LayerStyleEditor.cs +++ b/Assets/Editor/LayerStyleEditor.cs @@ -3,19 +3,25 @@ using Mapzen.Unity; using UnityEditor; using UnityEngine; +using System.Collections.Generic; [SerializeField] public class LayerStyleEditor : EditorBase { - [SerializeField] - private PolygonBuilderEditor polygonBuilderEditor; + private enum BuilderType { + polygon, + polyline, + }; [SerializeField] - private PolylineBuilderEditor polylineBuilderEditor; + private List builderEditors; [SerializeField] private FeatureStyle.LayerStyle layerStyle; + [SerializeField] + private BuilderType selectedBuilderType; + public FeatureStyle.LayerStyle LayerStyle { get { return layerStyle; } @@ -24,20 +30,78 @@ public FeatureStyle.LayerStyle LayerStyle public LayerStyleEditor(FeatureStyle.LayerStyle layerStyle) : base() { - this.polygonBuilderEditor = new PolygonBuilderEditor(); - this.polylineBuilderEditor = new PolylineBuilderEditor(); this.layerStyle = layerStyle; + this.builderEditors = new List(); + + foreach (var editorData in layerStyle.PolygonBuilderEditorDatas) + { + var editor = new PolygonBuilderEditor(); + editorData.editorGUID = editor.GUID; + this.builderEditors.Add(editor); + } + + foreach (var editorData in layerStyle.PolylineBuilderEditorDatas) + { + var editor = new PolylineBuilderEditor(); + editorData.editorGUID = editor.GUID; + this.builderEditors.Add(editor); + } } public void OnInspectorGUI() { - EditorGUI.indentLevel++; + EditorGUILayout.BeginHorizontal(); + { + selectedBuilderType = (BuilderType)EditorGUILayout.EnumPopup("Add builder", selectedBuilderType); - layerStyle.PolygonBuilderOptions = polygonBuilderEditor.OnInspectorGUI(layerStyle.PolygonBuilderOptions); - layerStyle.PolylineBuilderOptions = polylineBuilderEditor.OnInspectorGUI(layerStyle.PolylineBuilderOptions); + EditorConfig.SetColor(EditorConfig.AddButtonColor); + if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) + { + EditorBase editor = null; + switch (selectedBuilderType) + { + case BuilderType.polygon: { + editor = new PolygonBuilderEditor(); + FeatureStyle.LayerStyle.PolygonBuilderEditorData editorData + = new FeatureStyle.LayerStyle.PolygonBuilderEditorData(); + editorData.editorGUID = editor.GUID; + editorData.option = PolygonBuilderEditor.DefaultOptions(); + layerStyle.PolygonBuilderEditorDatas.Add(editorData); + } break; + case BuilderType.polyline: { + editor = new PolylineBuilderEditor(); + FeatureStyle.LayerStyle.PolylineBuilderEditorData editorData + = new FeatureStyle.LayerStyle.PolylineBuilderEditorData(); + editorData.editorGUID = editor.GUID; + editorData.option = PolylineBuilderEditor.DefaultOptions(); + layerStyle.PolylineBuilderEditorDatas.Add(editorData); + } break; + } + + builderEditors.Add(editor); + } + EditorConfig.ResetColor(); + } + EditorGUILayout.EndHorizontal(); + EditorGUI.indentLevel++; + foreach (var builderEditor in builderEditors) + { + if (builderEditor is PolygonBuilderEditor) + { + var editorData = layerStyle.PolygonBuilderEditorDatas.Find(data => data.editorGUID == builderEditor.GUID); + if (editorData != null) { + editorData.option = ((PolygonBuilderEditor)builderEditor).OnInspectorGUI(editorData.option); + } + } + else if (builderEditor is PolylineBuilderEditor) + { + var editorData = layerStyle.PolylineBuilderEditorDatas.Find(data => data.editorGUID == builderEditor.GUID); + if (editorData != null) { + editorData.option = ((PolylineBuilderEditor)builderEditor).OnInspectorGUI(editorData.option); + } + } + } EditorGUI.indentLevel--; - - layerStyle.Material = EditorGUILayout.ObjectField("Material:", layerStyle.Material, typeof(Material)) as Material; } } diff --git a/Assets/Editor/PolygonBuilderEditor.cs b/Assets/Editor/PolygonBuilderEditor.cs index c7215229..ac0b53d0 100644 --- a/Assets/Editor/PolygonBuilderEditor.cs +++ b/Assets/Editor/PolygonBuilderEditor.cs @@ -24,6 +24,7 @@ public static PolygonBuilder.Options DefaultOptions() defaultOptions.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; defaultOptions.Enabled = true; defaultOptions.MaxHeight = 0.0f; + defaultOptions.Material = new Material(Shader.Find("Diffuse")); return defaultOptions; } @@ -52,6 +53,7 @@ public PolygonBuilder.Options OnInspectorGUI(PolygonBuilder.Options options) options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); + options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); SavePreferences(); diff --git a/Assets/Editor/PolylineBuilderEditor.cs b/Assets/Editor/PolylineBuilderEditor.cs index 16340cb9..2885e989 100644 --- a/Assets/Editor/PolylineBuilderEditor.cs +++ b/Assets/Editor/PolylineBuilderEditor.cs @@ -26,6 +26,7 @@ public static PolylineBuilder.Options DefaultOptions() defaultOptions.MaxHeight = 3.0f; defaultOptions.MiterLimit = 3.0f; defaultOptions.Width = 15.0f; + defaultOptions.Material = new Material(Shader.Find("Diffuse")); return defaultOptions; } @@ -55,6 +56,10 @@ public PolylineBuilder.Options OnInspectorGUI(PolylineBuilder.Options options) options.Width = EditorGUILayout.FloatField("Width: ", options.Width); options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); + options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; + if (options.Material.name != "Legacy Shaders/Diffuse") { + int breakhere = 0; + } options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); SavePreferences(); diff --git a/Assets/Mapzen/Unity/FeatureStyle.cs b/Assets/Mapzen/Unity/FeatureStyle.cs index 5dc9c230..198e8d91 100644 --- a/Assets/Mapzen/Unity/FeatureStyle.cs +++ b/Assets/Mapzen/Unity/FeatureStyle.cs @@ -17,9 +17,21 @@ public class LayerStyle [SerializeField] private string layerName; - public Material Material; - public PolygonBuilder.Options PolygonBuilderOptions; - public PolylineBuilder.Options PolylineBuilderOptions; + [Serializable] + public class PolygonBuilderEditorData { + public Guid editorGUID; + public PolygonBuilder.Options option; + } + + [Serializable] + public class PolylineBuilderEditorData { + public Guid editorGUID; + public PolylineBuilder.Options option; + } + + public List PolygonBuilderEditorDatas; + + public List PolylineBuilderEditorDatas; public string LayerName { @@ -29,39 +41,50 @@ public string LayerName public LayerStyle(string layerName) { this.layerName = layerName; + this.PolygonBuilderEditorDatas = new List(); + this.PolylineBuilderEditorDatas = new List(); } - public PolygonBuilder.Options GetPolygonOptions(Feature feature, float inverseTileScale) + public List GetPolygonOptions(Feature feature, float inverseTileScale) { - var options = PolygonBuilderOptions; + List polygonBuilderOptions = new List(); - options.Material = this.Material; + foreach (var editorData in PolygonBuilderEditorDatas) { + var options = editorData.option; - if (options.MaxHeight > 0.0f) - { - options.MaxHeight *= inverseTileScale; - } - else - { - object heightValue; - if (feature.TryGetProperty("height", out heightValue) && heightValue is double) + if (options.MaxHeight > 0.0f) { - options.MaxHeight = (float)((double)heightValue * inverseTileScale); + options.MaxHeight *= inverseTileScale; } + else + { + object heightValue; + if (feature.TryGetProperty("height", out heightValue) && heightValue is double) + { + options.MaxHeight = (float)((double)heightValue * inverseTileScale); + } + } + + polygonBuilderOptions.Add(options); } - return options; + return polygonBuilderOptions; } - public PolylineBuilder.Options GetPolylineOptions(Feature feature, float inverseTileScale) + public List GetPolylineOptions(Feature feature, float inverseTileScale) { - var options = PolylineBuilderOptions; + List polylineBuilderOptions = new List(); - options.Material = this.Material; - options.Width *= inverseTileScale; - options.MaxHeight *= inverseTileScale; + foreach (var editorData in PolylineBuilderEditorDatas) { + var options = editorData.option; + + options.Width *= inverseTileScale; + options.MaxHeight *= inverseTileScale; + + polylineBuilderOptions.Add(options); + } - return options; + return polylineBuilderOptions; } } diff --git a/Assets/Mapzen/Unity/TileTask.cs b/Assets/Mapzen/Unity/TileTask.cs index d8e5e2a1..40e99995 100644 --- a/Assets/Mapzen/Unity/TileTask.cs +++ b/Assets/Mapzen/Unity/TileTask.cs @@ -73,10 +73,13 @@ public void Start(List featureStyling, SceneGroup root) if (feature.Type == GeometryType.Polygon || feature.Type == GeometryType.MultiPolygon) { - var polygonOptions = layerStyle.GetPolygonOptions(feature, inverseTileScale); - - if (polygonOptions.Enabled) + foreach (var polygonOptions in layerStyle.GetPolygonOptions(feature, inverseTileScale)) { + if (!polygonOptions.Enabled) + { + continue; + } + var builder = new PolygonBuilder(leaf.meshData, polygonOptions, transform); feature.HandleGeometry(builder); } @@ -84,10 +87,13 @@ public void Start(List featureStyling, SceneGroup root) if (feature.Type == GeometryType.LineString || feature.Type == GeometryType.MultiLineString) { - var polylineOptions = layerStyle.GetPolylineOptions(feature, inverseTileScale); - - if (polylineOptions.Enabled) + foreach (var polylineOptions in layerStyle.GetPolylineOptions(feature, inverseTileScale)) { + if (!polylineOptions.Enabled) + { + continue; + } + var builder = new PolylineBuilder(leaf.meshData, polylineOptions, transform); feature.HandleGeometry(builder); } From 592504423e5e7b61d34cc2877ffaa671ca633402 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Mon, 6 Nov 2017 11:35:02 -0500 Subject: [PATCH 02/10] Cleanup and renaming --- Assets/Editor/LayerStyleEditor.cs | 46 ++++++++++++++++------------- Assets/Mapzen/Unity/FeatureStyle.cs | 41 +++++++++++++------------ 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/Assets/Editor/LayerStyleEditor.cs b/Assets/Editor/LayerStyleEditor.cs index 36e0129b..77b6e19a 100644 --- a/Assets/Editor/LayerStyleEditor.cs +++ b/Assets/Editor/LayerStyleEditor.cs @@ -33,14 +33,14 @@ public LayerStyleEditor(FeatureStyle.LayerStyle layerStyle) this.layerStyle = layerStyle; this.builderEditors = new List(); - foreach (var editorData in layerStyle.PolygonBuilderEditorDatas) + foreach (var editorData in layerStyle.PolygonBuilderEditorOptions) { var editor = new PolygonBuilderEditor(); editorData.editorGUID = editor.GUID; this.builderEditors.Add(editor); } - foreach (var editorData in layerStyle.PolylineBuilderEditorDatas) + foreach (var editorData in layerStyle.PolylineBuilderEditorOptions) { var editor = new PolylineBuilderEditor(); editorData.editorGUID = editor.GUID; @@ -62,19 +62,23 @@ public void OnInspectorGUI() { case BuilderType.polygon: { editor = new PolygonBuilderEditor(); - FeatureStyle.LayerStyle.PolygonBuilderEditorData editorData - = new FeatureStyle.LayerStyle.PolygonBuilderEditorData(); - editorData.editorGUID = editor.GUID; - editorData.option = PolygonBuilderEditor.DefaultOptions(); - layerStyle.PolygonBuilderEditorDatas.Add(editorData); + + var editorOption = new FeatureStyle.PolygonBuilderEditorOption(); + + editorOption.editorGUID = editor.GUID; + editorOption.option = PolygonBuilderEditor.DefaultOptions(); + + layerStyle.PolygonBuilderEditorOptions.Add(editorOption); } break; case BuilderType.polyline: { editor = new PolylineBuilderEditor(); - FeatureStyle.LayerStyle.PolylineBuilderEditorData editorData - = new FeatureStyle.LayerStyle.PolylineBuilderEditorData(); - editorData.editorGUID = editor.GUID; - editorData.option = PolylineBuilderEditor.DefaultOptions(); - layerStyle.PolylineBuilderEditorDatas.Add(editorData); + + var editorOption = new FeatureStyle.PolylineBuilderEditorOption(); + + editorOption.editorGUID = editor.GUID; + editorOption.option = PolylineBuilderEditor.DefaultOptions(); + + layerStyle.PolylineBuilderEditorOptions.Add(editorOption); } break; } @@ -85,20 +89,20 @@ FeatureStyle.LayerStyle.PolylineBuilderEditorData editorData EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel++; - foreach (var builderEditor in builderEditors) + foreach (var builderEditor in builderEditors) { - if (builderEditor is PolygonBuilderEditor) + if (builderEditor is PolygonBuilderEditor) { - var editorData = layerStyle.PolygonBuilderEditorDatas.Find(data => data.editorGUID == builderEditor.GUID); - if (editorData != null) { - editorData.option = ((PolygonBuilderEditor)builderEditor).OnInspectorGUI(editorData.option); + var editorOption = layerStyle.PolygonBuilderEditorOptions.Find(data => data.editorGUID == builderEditor.GUID); + if (editorOption != null) { + editorOption.option = ((PolygonBuilderEditor)builderEditor).OnInspectorGUI(editorOption.option); } - } + } else if (builderEditor is PolylineBuilderEditor) { - var editorData = layerStyle.PolylineBuilderEditorDatas.Find(data => data.editorGUID == builderEditor.GUID); - if (editorData != null) { - editorData.option = ((PolylineBuilderEditor)builderEditor).OnInspectorGUI(editorData.option); + var editorOption = layerStyle.PolylineBuilderEditorOptions.Find(data => data.editorGUID == builderEditor.GUID); + if (editorOption != null) { + editorOption.option = ((PolylineBuilderEditor)builderEditor).OnInspectorGUI(editorOption.option); } } } diff --git a/Assets/Mapzen/Unity/FeatureStyle.cs b/Assets/Mapzen/Unity/FeatureStyle.cs index 198e8d91..c5f497c2 100644 --- a/Assets/Mapzen/Unity/FeatureStyle.cs +++ b/Assets/Mapzen/Unity/FeatureStyle.cs @@ -11,27 +11,26 @@ namespace Mapzen.Unity [CreateAssetMenu(menuName = "Mapzen/Style")] public class FeatureStyle : ScriptableObject { + [Serializable] + public class PolygonBuilderEditorOption { + public Guid editorGUID; + public PolygonBuilder.Options option; + } + + [Serializable] + public class PolylineBuilderEditorOption { + public Guid editorGUID; + public PolylineBuilder.Options option; + } + [Serializable] public class LayerStyle { [SerializeField] private string layerName; - [Serializable] - public class PolygonBuilderEditorData { - public Guid editorGUID; - public PolygonBuilder.Options option; - } - - [Serializable] - public class PolylineBuilderEditorData { - public Guid editorGUID; - public PolylineBuilder.Options option; - } - - public List PolygonBuilderEditorDatas; - - public List PolylineBuilderEditorDatas; + public List PolygonBuilderEditorOptions; + public List PolylineBuilderEditorOptions; public string LayerName { @@ -41,16 +40,16 @@ public string LayerName public LayerStyle(string layerName) { this.layerName = layerName; - this.PolygonBuilderEditorDatas = new List(); - this.PolylineBuilderEditorDatas = new List(); + this.PolygonBuilderEditorOptions = new List(); + this.PolylineBuilderEditorOptions = new List(); } public List GetPolygonOptions(Feature feature, float inverseTileScale) { List polygonBuilderOptions = new List(); - foreach (var editorData in PolygonBuilderEditorDatas) { - var options = editorData.option; + foreach (var editorOption in PolygonBuilderEditorOptions) { + var options = editorOption.option; if (options.MaxHeight > 0.0f) { @@ -75,8 +74,8 @@ public LayerStyle(string layerName) { List polylineBuilderOptions = new List(); - foreach (var editorData in PolylineBuilderEditorDatas) { - var options = editorData.option; + foreach (var editorOption in PolylineBuilderEditorOptions) { + var options = editorOption.option; options.Width *= inverseTileScale; options.MaxHeight *= inverseTileScale; From 3cfbf6130199892b3b6122e60c275dc129a902f2 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 7 Nov 2017 11:37:47 -0500 Subject: [PATCH 03/10] Add editor namespace and IEditor interface --- Assets/Editor/EditorBase.cs | 31 +-- Assets/Editor/EditorConfig.cs | 58 +++--- Assets/Editor/FeatureStyleEditor.cs | 37 ++-- Assets/Editor/FilterStyleEditor.cs | 235 +++++++++++------------ Assets/Editor/FoldoutEditor.cs | 73 ++++---- Assets/Editor/IEditor.cs | 8 + Assets/Editor/IEditor.cs.meta | 12 ++ Assets/Editor/LayerStyleEditor.cs | 131 ++++++------- Assets/Editor/MapzenMapEditor.cs | 249 +++++++++++++------------ Assets/Editor/MatcherEditor.cs | 195 +++++++++---------- Assets/Editor/PolygonBuilderEditor.cs | 90 +++++---- Assets/Editor/PolylineBuilderEditor.cs | 99 +++++----- Assets/Editor/StyleEditor.cs | 127 +++++++------ 13 files changed, 687 insertions(+), 658 deletions(-) create mode 100644 Assets/Editor/IEditor.cs create mode 100644 Assets/Editor/IEditor.cs.meta diff --git a/Assets/Editor/EditorBase.cs b/Assets/Editor/EditorBase.cs index 0af0295a..151fcb0b 100644 --- a/Assets/Editor/EditorBase.cs +++ b/Assets/Editor/EditorBase.cs @@ -1,20 +1,25 @@ using System; -/// -/// Base class for editor, each editor has a unique guid used -/// for saving custom preferences in the Unity editor prefs. -/// -public class EditorBase +namespace PluginEditor { - protected Guid guid; - - public EditorBase() + /// + /// Base class for editor, each editor has a unique guid used + /// for saving custom preferences in the Unity editor prefs. + /// + public abstract class EditorBase : IEditor { - guid = Guid.NewGuid(); - } + protected Guid guid; - public Guid GUID - { - get { return guid; } + public EditorBase() + { + guid = Guid.NewGuid(); + } + + public Guid GUID + { + get { return guid; } + } + + public abstract void OnInspectorGUI(); } } diff --git a/Assets/Editor/EditorConfig.cs b/Assets/Editor/EditorConfig.cs index b3b62f00..ddb95baa 100644 --- a/Assets/Editor/EditorConfig.cs +++ b/Assets/Editor/EditorConfig.cs @@ -2,43 +2,45 @@ using UnityEditor; using UnityEngine; -/// -/// Styling configuration for the editor. -/// -public class EditorConfig +namespace PluginEditor { - public static Color AddButtonColor = new Color(0.8f, 0.8f, 0.8f); + /// + /// Styling configuration for the editor. + /// + public class EditorConfig + { + public static Color AddButtonColor = new Color(0.8f, 0.8f, 0.8f); - public static Color DownloadButtonEnabledColor = new Color(0.35f, 0.80f, 0.30f); + public static Color DownloadButtonEnabledColor = new Color(0.35f, 0.80f, 0.30f); - public static Color DownloadButtonDisabledColor = new Color(0.45f, 0.45f, 0.45f); + public static Color DownloadButtonDisabledColor = new Color(0.45f, 0.45f, 0.45f); - public static Color RemoveButtonColor = new Color(0.5f, 0.5f, 0.5f); + public static Color RemoveButtonColor = new Color(0.5f, 0.5f, 0.5f); - public static GUILayoutOption SmallButtonWidth = GUILayout.Width(50.0f); + public static GUILayoutOption SmallButtonWidth = GUILayout.Width(50.0f); - public static GUIContent AddButtonContent = new GUIContent("+", "Add"); + public static GUIContent AddButtonContent = new GUIContent("+", "Add"); - public static GUIContent RemoveButtonContent = new GUIContent("-", "Remove"); + public static GUIContent RemoveButtonContent = new GUIContent("-", "Remove"); - public static Color DefaultColor; + public static Color DefaultColor; - /// - /// Globally sets the color of the GUI, saves the current color. - /// - /// Color. - public static void SetColor(Color color) - { - DefaultColor = GUI.color; - GUI.color = color; - } + /// + /// Globally sets the color of the GUI, saves the current color. + /// + /// Color. + public static void SetColor(Color color) + { + DefaultColor = GUI.color; + GUI.color = color; + } - /// - /// Globally resets the color of the GUI to its previous state. - /// - public static void ResetColor() - { - GUI.color = DefaultColor; + /// + /// Globally resets the color of the GUI to its previous state. + /// + public static void ResetColor() + { + GUI.color = DefaultColor; + } } } - diff --git a/Assets/Editor/FeatureStyleEditor.cs b/Assets/Editor/FeatureStyleEditor.cs index 4ddbdb2a..df326c5f 100644 --- a/Assets/Editor/FeatureStyleEditor.cs +++ b/Assets/Editor/FeatureStyleEditor.cs @@ -4,28 +4,31 @@ using Mapzen; using Mapzen.Unity; -[CustomEditor(typeof(FeatureStyle))] -public class FeatureStyleEditor : Editor +namespace PluginEditor { - private FeatureStyle featureStyle; - private StyleEditor styleEditor; - - void OnEnable() + [CustomEditor(typeof(FeatureStyle))] + public class FeatureStyleEditor : Editor { - featureStyle = (FeatureStyle)target; - styleEditor = featureStyle.Editor as StyleEditor; + private FeatureStyle featureStyle; + private StyleEditor styleEditor; - if (styleEditor == null) + void OnEnable() { - styleEditor = new StyleEditor(featureStyle); - featureStyle.Editor = styleEditor; + featureStyle = (FeatureStyle)target; + styleEditor = featureStyle.Editor as StyleEditor; + + if (styleEditor == null) + { + styleEditor = new StyleEditor(featureStyle); + featureStyle.Editor = styleEditor; + } } - } - public override void OnInspectorGUI() - { - styleEditor.OnInspectorGUI(); + public override void OnInspectorGUI() + { + styleEditor.OnInspectorGUI(); - EditorUtility.SetDirty(featureStyle); + EditorUtility.SetDirty(featureStyle); + } } -} \ No newline at end of file +} diff --git a/Assets/Editor/FilterStyleEditor.cs b/Assets/Editor/FilterStyleEditor.cs index 266568c1..9a4e6357 100644 --- a/Assets/Editor/FilterStyleEditor.cs +++ b/Assets/Editor/FilterStyleEditor.cs @@ -7,160 +7,163 @@ using UnityEditor; using UnityEngine; -[Serializable] -public class FilterStyleEditor : EditorBase +namespace PluginEditor { - private static List defaultLayers = new List(new string[] - { - "boundaries", - "buildings", - "earth", - "landuse", - "places", - "pois", - "roads", - "transit", - "water", - }); - - [SerializeField] - private string customFeatureCollection = ""; - - [SerializeField] - private int selectedLayer; - - [SerializeField] - private FeatureStyle.Matcher.Type selectedMatcherType; + [Serializable] + public class FilterStyleEditor : EditorBase + { + private static List defaultLayers = new List(new string[] + { + "boundaries", + "buildings", + "earth", + "landuse", + "places", + "pois", + "roads", + "transit", + "water", + }); - [SerializeField] - private List layerStyleEditors; + [SerializeField] + private string customFeatureCollection = ""; - [SerializeField] - private MatcherEditor matcherEditor; + [SerializeField] + private int selectedLayer; - [SerializeField] - private FeatureStyle.FilterStyle filterStyle; + [SerializeField] + private FeatureStyle.Matcher.Type selectedMatcherType; - public FeatureStyle.FilterStyle FilterStyle - { - get { return filterStyle; } - } + [SerializeField] + private List layerStyleEditors; - public FilterStyleEditor(FeatureStyle.FilterStyle filterStyle) - : base() - { - this.filterStyle = filterStyle; - this.layerStyleEditors = new List(); + [SerializeField] + private MatcherEditor matcherEditor; - foreach (var layerStyle in filterStyle.LayerStyles) - { - layerStyleEditors.Add(new LayerStyleEditor(layerStyle)); - } + [SerializeField] + private FeatureStyle.FilterStyle filterStyle; - if (filterStyle.Matcher != null) + public FeatureStyle.FilterStyle FilterStyle { - selectedMatcherType = filterStyle.Matcher.MatcherType; - this.matcherEditor = new MatcherEditor(filterStyle.Matcher); + get { return filterStyle; } } - } - private void AddLayerStyleLayout(FeatureStyle.FilterStyle filterStyle, string name) - { - EditorConfig.SetColor(EditorConfig.AddButtonColor); - if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) + public FilterStyleEditor(FeatureStyle.FilterStyle filterStyle) + : base() { - // Layers within a filter are identifier by their layer name - var queryLayer = filterStyle.LayerStyles.Where(layerStyle => name == layerStyle.LayerName); + this.filterStyle = filterStyle; + this.layerStyleEditors = new List(); - if (name.Length == 0) - { - Debug.LogError("Layer name can't be empty"); - } - else if (queryLayer.Count() > 0) - { - Debug.LogError("A layer with name " + name + " already exists"); - } - else + foreach (var layerStyle in filterStyle.LayerStyles) { - var layerStyle = new FeatureStyle.LayerStyle(name); - - filterStyle.LayerStyles.Add(layerStyle); - - // Create the associated layer editor layerStyleEditors.Add(new LayerStyleEditor(layerStyle)); } - } - EditorConfig.ResetColor(); - } - public void OnInspectorGUI() - { - // Default layers - EditorGUILayout.BeginHorizontal(); - { - selectedLayer = EditorGUILayout.Popup("Default layer:", selectedLayer, defaultLayers.ToArray()); - AddLayerStyleLayout(filterStyle, defaultLayers[selectedLayer]); + if (filterStyle.Matcher != null) + { + selectedMatcherType = filterStyle.Matcher.MatcherType; + this.matcherEditor = new MatcherEditor(filterStyle.Matcher); + } } - EditorGUILayout.EndHorizontal(); - // Custom layer entry - EditorGUILayout.BeginHorizontal(); + private void AddLayerStyleLayout(FeatureStyle.FilterStyle filterStyle, string name) { - customFeatureCollection = EditorGUILayout.TextField("Custom layer:", customFeatureCollection); - AddLayerStyleLayout(filterStyle, customFeatureCollection); + EditorConfig.SetColor(EditorConfig.AddButtonColor); + if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) + { + // Layers within a filter are identifier by their layer name + var queryLayer = filterStyle.LayerStyles.Where(layerStyle => name == layerStyle.LayerName); + + if (name.Length == 0) + { + Debug.LogError("Layer name can't be empty"); + } + else if (queryLayer.Count() > 0) + { + Debug.LogError("A layer with name " + name + " already exists"); + } + else + { + var layerStyle = new FeatureStyle.LayerStyle(name); + + filterStyle.LayerStyles.Add(layerStyle); + + // Create the associated layer editor + layerStyleEditors.Add(new LayerStyleEditor(layerStyle)); + } + } + EditorConfig.ResetColor(); } - EditorGUILayout.EndHorizontal(); - - EditorGUI.indentLevel++; - for (int i = layerStyleEditors.Count - 1; i >= 0; i--) + public override void OnInspectorGUI() { - var editor = layerStyleEditors[i]; - var layerStyling = editor.LayerStyle; - - var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), layerStyling.LayerName); + // Default layers + EditorGUILayout.BeginHorizontal(); + { + selectedLayer = EditorGUILayout.Popup("Default layer:", selectedLayer, defaultLayers.ToArray()); + AddLayerStyleLayout(filterStyle, defaultLayers[selectedLayer]); + } + EditorGUILayout.EndHorizontal(); - if (state.show) + // Custom layer entry + EditorGUILayout.BeginHorizontal(); { - editor.OnInspectorGUI(); + customFeatureCollection = EditorGUILayout.TextField("Custom layer:", customFeatureCollection); + AddLayerStyleLayout(filterStyle, customFeatureCollection); } + EditorGUILayout.EndHorizontal(); + + EditorGUI.indentLevel++; - if (state.markedForDeletion) + for (int i = layerStyleEditors.Count - 1; i >= 0; i--) { - // Remove the layer from the filter styles - filterStyle.LayerStyles.Remove(layerStyling); + var editor = layerStyleEditors[i]; + var layerStyling = editor.LayerStyle; + + var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), layerStyling.LayerName); + + if (state.show) + { + editor.OnInspectorGUI(); + } + + if (state.markedForDeletion) + { + // Remove the layer from the filter styles + filterStyle.LayerStyles.Remove(layerStyling); - // Remove the associated layer editor - layerStyleEditors.RemoveAt(i); + // Remove the associated layer editor + layerStyleEditors.RemoveAt(i); + } } - } - EditorGUI.indentLevel--; + EditorGUI.indentLevel--; - var matcherTypeList = Enum.GetValues(typeof(FeatureStyle.Matcher.Type)).Cast(); - var matcherTypeStringList = matcherTypeList.Select(type => type.ToString()); - var oldType = selectedMatcherType; + var matcherTypeList = Enum.GetValues(typeof(FeatureStyle.Matcher.Type)).Cast(); + var matcherTypeStringList = matcherTypeList.Select(type => type.ToString()); + var oldType = selectedMatcherType; - selectedMatcherType = (FeatureStyle.Matcher.Type)EditorGUILayout.Popup("Matcher:", - (int)selectedMatcherType, matcherTypeStringList.ToArray()); + selectedMatcherType = (FeatureStyle.Matcher.Type)EditorGUILayout.Popup("Matcher:", + (int)selectedMatcherType, matcherTypeStringList.ToArray()); - if (selectedMatcherType != oldType) - { - matcherEditor = new MatcherEditor(new FeatureStyle.Matcher(selectedMatcherType)); - } - else - { - if (selectedMatcherType == FeatureStyle.Matcher.Type.None) + if (selectedMatcherType != oldType) { - matcherEditor = null; + matcherEditor = new MatcherEditor(new FeatureStyle.Matcher(selectedMatcherType)); + } + else + { + if (selectedMatcherType == FeatureStyle.Matcher.Type.None) + { + matcherEditor = null; + } } - } - if (matcherEditor != null) - { - matcherEditor.OnInspectorGUI(); + if (matcherEditor != null) + { + matcherEditor.OnInspectorGUI(); - filterStyle.Matcher = matcherEditor.Matcher; + filterStyle.Matcher = matcherEditor.Matcher; + } } } } diff --git a/Assets/Editor/FoldoutEditor.cs b/Assets/Editor/FoldoutEditor.cs index e20c1436..e3644276 100644 --- a/Assets/Editor/FoldoutEditor.cs +++ b/Assets/Editor/FoldoutEditor.cs @@ -2,53 +2,56 @@ using UnityEditor; using UnityEngine; -public class FoldoutEditor +namespace PluginEditor { - public class State + public class FoldoutEditor { - // Whether the foldout panel is shown - public bool show; - // Whether the foldout panel is marked for deletion - public bool markedForDeletion; - - public State() + public class State { - this.markedForDeletion = false; - this.show = false; - } - } - - public static bool LoadPreferences(string editorIdentifier) - { - return EditorPrefs.GetBool(editorIdentifier + ".show"); - } + // Whether the foldout panel is shown + public bool show; + // Whether the foldout panel is marked for deletion + public bool markedForDeletion; - public static void SavePrefences(string editorIdentifier, bool show) - { - EditorPrefs.SetBool(editorIdentifier + ".show", show); - } + public State() + { + this.markedForDeletion = false; + this.show = false; + } + } - public static State OnInspectorGUI(string editorIdentifier, string foldoutName) - { - var state = new State(); + public static bool LoadPreferences(string editorIdentifier) + { + return EditorPrefs.GetBool(editorIdentifier + ".show"); + } - state.show = LoadPreferences(editorIdentifier); + public static void SavePrefences(string editorIdentifier, bool show) + { + EditorPrefs.SetBool(editorIdentifier + ".show", show); + } - EditorGUILayout.BeginHorizontal(); + public static State OnInspectorGUI(string editorIdentifier, string foldoutName) { - state.show = EditorGUILayout.Foldout(state.show, foldoutName); + var state = new State(); + + state.show = LoadPreferences(editorIdentifier); - EditorConfig.SetColor(EditorConfig.RemoveButtonColor); - if (GUILayout.Button(EditorConfig.RemoveButtonContent, EditorConfig.SmallButtonWidth)) + EditorGUILayout.BeginHorizontal(); { - state.markedForDeletion = true; + state.show = EditorGUILayout.Foldout(state.show, foldoutName); + + EditorConfig.SetColor(EditorConfig.RemoveButtonColor); + if (GUILayout.Button(EditorConfig.RemoveButtonContent, EditorConfig.SmallButtonWidth)) + { + state.markedForDeletion = true; + } + EditorConfig.ResetColor(); } - EditorConfig.ResetColor(); - } - EditorGUILayout.EndHorizontal(); + EditorGUILayout.EndHorizontal(); - SavePrefences(editorIdentifier, state.show); + SavePrefences(editorIdentifier, state.show); - return state; + return state; + } } } diff --git a/Assets/Editor/IEditor.cs b/Assets/Editor/IEditor.cs new file mode 100644 index 00000000..33eeb512 --- /dev/null +++ b/Assets/Editor/IEditor.cs @@ -0,0 +1,8 @@ + +namespace PluginEditor +{ + public interface IEditor + { + void OnInspectorGUI(); + } +} diff --git a/Assets/Editor/IEditor.cs.meta b/Assets/Editor/IEditor.cs.meta new file mode 100644 index 00000000..e059ba2c --- /dev/null +++ b/Assets/Editor/IEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 8ee11d146df90412b947c6adffc3fa22 +timeCreated: 1509997026 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/LayerStyleEditor.cs b/Assets/Editor/LayerStyleEditor.cs index 77b6e19a..68551107 100644 --- a/Assets/Editor/LayerStyleEditor.cs +++ b/Assets/Editor/LayerStyleEditor.cs @@ -5,107 +5,80 @@ using UnityEngine; using System.Collections.Generic; -[SerializeField] -public class LayerStyleEditor : EditorBase +namespace PluginEditor { - private enum BuilderType { - polygon, - polyline, - }; - [SerializeField] - private List builderEditors; + public class LayerStyleEditor : EditorBase + { + private enum BuilderType { + polygon, + polyline, + }; - [SerializeField] - private FeatureStyle.LayerStyle layerStyle; + [SerializeField] + private List builderEditors; - [SerializeField] - private BuilderType selectedBuilderType; + [SerializeField] + private FeatureStyle.LayerStyle layerStyle; - public FeatureStyle.LayerStyle LayerStyle - { - get { return layerStyle; } - } + [SerializeField] + private BuilderType selectedBuilderType; - public LayerStyleEditor(FeatureStyle.LayerStyle layerStyle) - : base() - { - this.layerStyle = layerStyle; - this.builderEditors = new List(); - - foreach (var editorData in layerStyle.PolygonBuilderEditorOptions) + public FeatureStyle.LayerStyle LayerStyle { - var editor = new PolygonBuilderEditor(); - editorData.editorGUID = editor.GUID; - this.builderEditors.Add(editor); + get { return layerStyle; } } - foreach (var editorData in layerStyle.PolylineBuilderEditorOptions) + public LayerStyleEditor(FeatureStyle.LayerStyle layerStyle) + : base() { - var editor = new PolylineBuilderEditor(); - editorData.editorGUID = editor.GUID; - this.builderEditors.Add(editor); - } - } - - public void OnInspectorGUI() - { - EditorGUILayout.BeginHorizontal(); - { - selectedBuilderType = (BuilderType)EditorGUILayout.EnumPopup("Add builder", selectedBuilderType); + this.layerStyle = layerStyle; + this.builderEditors = new List(); - EditorConfig.SetColor(EditorConfig.AddButtonColor); - if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) + foreach (var options in layerStyle.PolygonBuilderOptions) { - EditorBase editor = null; - switch (selectedBuilderType) - { - case BuilderType.polygon: { - editor = new PolygonBuilderEditor(); - - var editorOption = new FeatureStyle.PolygonBuilderEditorOption(); - - editorOption.editorGUID = editor.GUID; - editorOption.option = PolygonBuilderEditor.DefaultOptions(); - - layerStyle.PolygonBuilderEditorOptions.Add(editorOption); - } break; - case BuilderType.polyline: { - editor = new PolylineBuilderEditor(); - - var editorOption = new FeatureStyle.PolylineBuilderEditorOption(); - - editorOption.editorGUID = editor.GUID; - editorOption.option = PolylineBuilderEditor.DefaultOptions(); + this.builderEditors.Add(new PolygonBuilderEditor(options)); + } - layerStyle.PolylineBuilderEditorOptions.Add(editorOption); - } break; - } - - builderEditors.Add(editor); + foreach (var options in layerStyle.PolylineBuilderOptions) + { + this.builderEditors.Add(new PolylineBuilderEditor(options)); } - EditorConfig.ResetColor(); } - EditorGUILayout.EndHorizontal(); - EditorGUI.indentLevel++; - foreach (var builderEditor in builderEditors) + public override void OnInspectorGUI() { - if (builderEditor is PolygonBuilderEditor) + EditorGUILayout.BeginHorizontal(); { - var editorOption = layerStyle.PolygonBuilderEditorOptions.Find(data => data.editorGUID == builderEditor.GUID); - if (editorOption != null) { - editorOption.option = ((PolygonBuilderEditor)builderEditor).OnInspectorGUI(editorOption.option); + selectedBuilderType = (BuilderType)EditorGUILayout.EnumPopup("Add builder", selectedBuilderType); + + EditorConfig.SetColor(EditorConfig.AddButtonColor); + if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) + { + switch (selectedBuilderType) + { + case BuilderType.polygon: { + var editor = new PolygonBuilderEditor(); + layerStyle.PolygonBuilderOptions.Add(editor.Options); + builderEditors.Add(editor); + } break; + case BuilderType.polyline: { + var editor = new PolylineBuilderEditor(); + layerStyle.PolylineBuilderOptions.Add(editor.Options); + builderEditors.Add(editor); + } break; + } } + EditorConfig.ResetColor(); } - else if (builderEditor is PolylineBuilderEditor) + EditorGUILayout.EndHorizontal(); + + EditorGUI.indentLevel++; + foreach (var builderEditor in builderEditors) { - var editorOption = layerStyle.PolylineBuilderEditorOptions.Find(data => data.editorGUID == builderEditor.GUID); - if (editorOption != null) { - editorOption.option = ((PolylineBuilderEditor)builderEditor).OnInspectorGUI(editorOption.option); - } + builderEditor.OnInspectorGUI(); } + EditorGUI.indentLevel--; } - EditorGUI.indentLevel--; } } diff --git a/Assets/Editor/MapzenMapEditor.cs b/Assets/Editor/MapzenMapEditor.cs index 55fedeb2..76e21589 100644 --- a/Assets/Editor/MapzenMapEditor.cs +++ b/Assets/Editor/MapzenMapEditor.cs @@ -4,174 +4,177 @@ using Mapzen; using UnityEditor; -[CustomEditor(typeof(MapzenMap))] -public class MapzenMapEditor : Editor +namespace PluginEditor { - private MapzenMap mapzenMap; - private bool showTileDataFoldout = false; - private bool showRegionScaleRatioFoldout = false; - - void OnEnable() + [CustomEditor(typeof(MapzenMap))] + public class MapzenMapEditor : Editor { - this.mapzenMap = (MapzenMap)target; - } + private MapzenMap mapzenMap; + private bool showTileDataFoldout = false; + private bool showRegionScaleRatioFoldout = false; - public override void OnInspectorGUI() - { - LoadPreferences(); + void OnEnable() + { + this.mapzenMap = (MapzenMap)target; + } - TileDataFoldout(); + public override void OnInspectorGUI() + { + LoadPreferences(); - RegionScaleRatioFoldout(); + TileDataFoldout(); - base.OnInspectorGUI(); + RegionScaleRatioFoldout(); - bool valid = IsValid(); + base.OnInspectorGUI(); - EditorConfig.SetColor(valid ? - EditorConfig.DownloadButtonEnabledColor : - EditorConfig.DownloadButtonDisabledColor); + bool valid = IsValid(); - if (GUILayout.Button("Download")) - { - if (valid) - { - LogWarnings(); + EditorConfig.SetColor(valid ? + EditorConfig.DownloadButtonEnabledColor : + EditorConfig.DownloadButtonDisabledColor); - mapzenMap.DownloadTiles(); - } - else + if (GUILayout.Button("Download")) { - LogErrors(); + if (valid) + { + LogWarnings(); + + mapzenMap.DownloadTiles(); + } + else + { + LogErrors(); + } } - } - EditorConfig.ResetColor(); + EditorConfig.ResetColor(); - SavePreferences(); - } + SavePreferences(); + } - private void SceneGroupToggle(MapzenMap mapzenMap, SceneGroup.Type type) - { - bool isSet = SceneGroup.Test(type, mapzenMap.GroupOptions); - isSet = EditorGUILayout.Toggle(type.ToString(), isSet); + private void SceneGroupToggle(MapzenMap mapzenMap, SceneGroup.Type type) + { + bool isSet = SceneGroup.Test(type, mapzenMap.GroupOptions); + isSet = EditorGUILayout.Toggle(type.ToString(), isSet); - mapzenMap.GroupOptions = isSet ? - mapzenMap.GroupOptions | type : - mapzenMap.GroupOptions & ~type; - } + mapzenMap.GroupOptions = isSet ? + mapzenMap.GroupOptions | type : + mapzenMap.GroupOptions & ~type; + } - private void TileDataFoldout() - { - showTileDataFoldout = EditorGUILayout.Foldout(showTileDataFoldout, "Tile data"); - if (!showTileDataFoldout) + private void TileDataFoldout() { - return; - } + showTileDataFoldout = EditorGUILayout.Foldout(showTileDataFoldout, "Tile data"); + if (!showTileDataFoldout) + { + return; + } - GUILayout.Label("Group by:"); + GUILayout.Label("Group by:"); - EditorGUI.indentLevel++; + EditorGUI.indentLevel++; - EditorGUILayout.BeginHorizontal(); - SceneGroupToggle(mapzenMap, SceneGroup.Type.Feature); - SceneGroupToggle(mapzenMap, SceneGroup.Type.Filter); - EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + SceneGroupToggle(mapzenMap, SceneGroup.Type.Feature); + SceneGroupToggle(mapzenMap, SceneGroup.Type.Filter); + EditorGUILayout.EndHorizontal(); - EditorGUILayout.BeginHorizontal(); - SceneGroupToggle(mapzenMap, SceneGroup.Type.Layer); - SceneGroupToggle(mapzenMap, SceneGroup.Type.Tile); - EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + SceneGroupToggle(mapzenMap, SceneGroup.Type.Layer); + SceneGroupToggle(mapzenMap, SceneGroup.Type.Tile); + EditorGUILayout.EndHorizontal(); - EditorGUI.indentLevel--; - } + EditorGUI.indentLevel--; + } - private void UnitScaleToggle(MapzenMap mapzenMap, RegionScaleUnits.Units unit) - { - bool isSet = RegionScaleUnits.Test(unit, mapzenMap.RegionScaleUnit); - isSet = EditorGUILayout.Toggle(unit.ToString(), isSet); + private void UnitScaleToggle(MapzenMap mapzenMap, RegionScaleUnits.Units unit) + { + bool isSet = RegionScaleUnits.Test(unit, mapzenMap.RegionScaleUnit); + isSet = EditorGUILayout.Toggle(unit.ToString(), isSet); - mapzenMap.RegionScaleUnit = isSet ? unit : mapzenMap.RegionScaleUnit; - } + mapzenMap.RegionScaleUnit = isSet ? unit : mapzenMap.RegionScaleUnit; + } - private void RegionScaleRatioFoldout() - { - showRegionScaleRatioFoldout = EditorGUILayout.Foldout(showRegionScaleRatioFoldout, "Region Scale Ratio"); - if (!showRegionScaleRatioFoldout) + private void RegionScaleRatioFoldout() { - return; - } + showRegionScaleRatioFoldout = EditorGUILayout.Foldout(showRegionScaleRatioFoldout, "Region Scale Ratio"); + if (!showRegionScaleRatioFoldout) + { + return; + } - mapzenMap.RegionScaleRatio = EditorGUILayout.FloatField("Scale: ", mapzenMap.RegionScaleRatio); - GUILayout.Label("Choose world scale units: "); - EditorGUI.indentLevel++; + mapzenMap.RegionScaleRatio = EditorGUILayout.FloatField("Scale: ", mapzenMap.RegionScaleRatio); + GUILayout.Label("Choose world scale units: "); + EditorGUI.indentLevel++; - EditorGUILayout.BeginHorizontal(); - UnitScaleToggle(mapzenMap, RegionScaleUnits.Units.Meters); - UnitScaleToggle(mapzenMap, RegionScaleUnits.Units.KiloMeters); - EditorGUILayout.EndHorizontal(); - EditorGUILayout.BeginHorizontal(); - UnitScaleToggle(mapzenMap, RegionScaleUnits.Units.Miles); - UnitScaleToggle(mapzenMap, RegionScaleUnits.Units.Feet); - EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + UnitScaleToggle(mapzenMap, RegionScaleUnits.Units.Meters); + UnitScaleToggle(mapzenMap, RegionScaleUnits.Units.KiloMeters); + EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + UnitScaleToggle(mapzenMap, RegionScaleUnits.Units.Miles); + UnitScaleToggle(mapzenMap, RegionScaleUnits.Units.Feet); + EditorGUILayout.EndHorizontal(); - EditorGUI.indentLevel--; - } + EditorGUI.indentLevel--; + } - private void LoadPreferences() - { - string key = typeof(MapzenMapEditor).Name; - showTileDataFoldout = EditorPrefs.GetBool(key + ".showTileDataFoldout"); - showRegionScaleRatioFoldout = EditorPrefs.GetBool(key + ".showRegionScaleRatioFoldout"); - } + private void LoadPreferences() + { + string key = typeof(MapzenMapEditor).Name; + showTileDataFoldout = EditorPrefs.GetBool(key + ".showTileDataFoldout"); + showRegionScaleRatioFoldout = EditorPrefs.GetBool(key + ".showRegionScaleRatioFoldout"); + } - private void SavePreferences() - { - string key = typeof(MapzenMapEditor).Name; - EditorPrefs.SetBool(key + ".showTileDataFoldout", showTileDataFoldout); - EditorPrefs.SetBool(key + ".showRegionScaleRatioFoldout", showRegionScaleRatioFoldout); - } + private void SavePreferences() + { + string key = typeof(MapzenMapEditor).Name; + EditorPrefs.SetBool(key + ".showTileDataFoldout", showTileDataFoldout); + EditorPrefs.SetBool(key + ".showRegionScaleRatioFoldout", showRegionScaleRatioFoldout); + } - private bool IsValid() - { - return mapzenMap.RegionName.Length > 0 && mapzenMap.FeatureStyling.Count > 0; - } + private bool IsValid() + { + return mapzenMap.RegionName.Length > 0 && mapzenMap.FeatureStyling.Count > 0; + } - private void LogWarnings() - { - foreach (var style in mapzenMap.FeatureStyling) + private void LogWarnings() { - if (style == null) + foreach (var style in mapzenMap.FeatureStyling) { - Debug.LogWarning("'Null' style provided in feature styling collection"); - continue; - } + if (style == null) + { + Debug.LogWarning("'Null' style provided in feature styling collection"); + continue; + } - if (style.FilterStyles.Count == 0) - { - Debug.LogWarning("The style " + style.name + " has no filter"); - } + if (style.FilterStyles.Count == 0) + { + Debug.LogWarning("The style " + style.name + " has no filter"); + } - foreach (var filterStyle in style.FilterStyles) - { - if (filterStyle.GetFilter().CollectionNameSet.Count == 0) + foreach (var filterStyle in style.FilterStyles) { - Debug.LogWarning("The style " + style.name + " has a filter selecting no layer"); + if (filterStyle.GetFilter().CollectionNameSet.Count == 0) + { + Debug.LogWarning("The style " + style.name + " has a filter selecting no layer"); + } } } } - } - private void LogErrors() - { - if (mapzenMap.RegionName.Length == 0) + private void LogErrors() { - Debug.LogError("Make sure to give a region name"); - } + if (mapzenMap.RegionName.Length == 0) + { + Debug.LogError("Make sure to give a region name"); + } - if (mapzenMap.FeatureStyling.Count == 0) - { - Debug.LogError("Make sure to create at least one style"); + if (mapzenMap.FeatureStyling.Count == 0) + { + Debug.LogError("Make sure to create at least one style"); + } } } } diff --git a/Assets/Editor/MatcherEditor.cs b/Assets/Editor/MatcherEditor.cs index 7cb388f1..897c9b3b 100644 --- a/Assets/Editor/MatcherEditor.cs +++ b/Assets/Editor/MatcherEditor.cs @@ -7,128 +7,129 @@ using UnityEditor; using UnityEngine; -[Serializable] -public class MatcherEditor : EditorBase +namespace PluginEditor { - [SerializeField] - private FeatureStyle.Matcher.Type selectedMatcherType; - - [SerializeField] - private FeatureStyle.Matcher matcher; - - [SerializeField] - private List matcherEditors; - - public FeatureStyle.Matcher Matcher + [Serializable] + public class MatcherEditor : EditorBase { - get { return matcher; } - } + [SerializeField] + private FeatureStyle.Matcher.Type selectedMatcherType; - public MatcherEditor(FeatureStyle.Matcher matcher) - : base() - { - this.matcher = matcher; - this.matcherEditors = new List(); + [SerializeField] + private FeatureStyle.Matcher matcher; + + [SerializeField] + private List matcherEditors; - foreach (var matcherChild in matcher.Matchers) + public FeatureStyle.Matcher Matcher { - this.matcherEditors.Add(new MatcherEditor(matcherChild)); + get { return matcher; } } - } - - private MatcherEditor AddMatcherLayout() - { - MatcherEditor editor = null; - EditorGUILayout.BeginHorizontal(); + public MatcherEditor(FeatureStyle.Matcher matcher) + : base() { - var matcherTypeList = Enum.GetValues(typeof(FeatureStyle.Matcher.Type)).Cast(); - var matcherTypeStringList = matcherTypeList.Select(type => type.ToString()); - - selectedMatcherType = (FeatureStyle.Matcher.Type)EditorGUILayout.Popup("Matcher:", - (int)selectedMatcherType, matcherTypeStringList.ToArray()); + this.matcher = matcher; + this.matcherEditors = new List(); - EditorConfig.SetColor(EditorConfig.AddButtonColor); - if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth) - && selectedMatcherType != FeatureStyle.Matcher.Type.None) + foreach (var matcherChild in matcher.Matchers) { - var matcherType = (FeatureStyle.Matcher.Type)selectedMatcherType; - var newMatcher = new FeatureStyle.Matcher(matcherType); - - editor = new MatcherEditor(newMatcher); - matcher.Matchers.Add(newMatcher); + this.matcherEditors.Add(new MatcherEditor(matcherChild)); } - EditorConfig.ResetColor(); } - EditorGUILayout.EndHorizontal(); - - return editor; - } - - public void OnInspectorGUI() - { - EditorGUI.indentLevel++; - if (matcher.IsCompound()) + private MatcherEditor AddMatcherLayout() { - var editor = AddMatcherLayout(); - if (editor != null) - { - matcherEditors.Add(editor); - } - } - else - { - switch (matcher.MatcherType) + MatcherEditor editor = null; + + EditorGUILayout.BeginHorizontal(); { - case FeatureStyle.Matcher.Type.Property: - matcher.HasProperty = EditorGUILayout.TextField("Has property:", matcher.HasProperty); - break; - - case FeatureStyle.Matcher.Type.PropertyRange: - matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty); - EditorGUILayout.BeginHorizontal(); - matcher.MinRange = EditorGUILayout.FloatField("min:", matcher.MinRange); - matcher.MinRangeEnabled = EditorGUILayout.Toggle(matcher.MinRangeEnabled); - EditorGUILayout.EndHorizontal(); - EditorGUILayout.BeginHorizontal(); - matcher.MaxRange = EditorGUILayout.FloatField("max:", matcher.MaxRange); - matcher.MaxRangeEnabled = EditorGUILayout.Toggle(matcher.MaxRangeEnabled); - EditorGUILayout.EndHorizontal(); - break; - - case FeatureStyle.Matcher.Type.PropertyValue: - matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty); - matcher.PropertyValue = EditorGUILayout.TextField("Property value:", matcher.PropertyValue); - break; - - case FeatureStyle.Matcher.Type.PropertyRegex: - matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty); - matcher.RegexPattern = EditorGUILayout.TextField("Regex:", matcher.RegexPattern); - break; + var matcherTypeList = Enum.GetValues(typeof(FeatureStyle.Matcher.Type)).Cast(); + var matcherTypeStringList = matcherTypeList.Select(type => type.ToString()); + + selectedMatcherType = (FeatureStyle.Matcher.Type)EditorGUILayout.Popup("Matcher:", + (int)selectedMatcherType, matcherTypeStringList.ToArray()); + + EditorConfig.SetColor(EditorConfig.AddButtonColor); + if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth) + && selectedMatcherType != FeatureStyle.Matcher.Type.None) + { + var matcherType = (FeatureStyle.Matcher.Type)selectedMatcherType; + var newMatcher = new FeatureStyle.Matcher(matcherType); + + editor = new MatcherEditor(newMatcher); + matcher.Matchers.Add(newMatcher); + } + EditorConfig.ResetColor(); } + EditorGUILayout.EndHorizontal(); + + return editor; } - for (int i = matcherEditors.Count - 1; i >= 0; i--) + public override void OnInspectorGUI() { - var editor = matcherEditors[i]; - - var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), editor.Matcher.MatcherType.ToString()); + EditorGUI.indentLevel++; - if (state.show) + if (matcher.IsCompound()) + { + var editor = AddMatcherLayout(); + if (editor != null) + { + matcherEditors.Add(editor); + } + } + else { - editor.OnInspectorGUI(); + switch (matcher.MatcherType) + { + case FeatureStyle.Matcher.Type.Property: + matcher.HasProperty = EditorGUILayout.TextField("Has property:", matcher.HasProperty); + break; + + case FeatureStyle.Matcher.Type.PropertyRange: + matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty); + EditorGUILayout.BeginHorizontal(); + matcher.MinRange = EditorGUILayout.FloatField("min:", matcher.MinRange); + matcher.MinRangeEnabled = EditorGUILayout.Toggle(matcher.MinRangeEnabled); + EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + matcher.MaxRange = EditorGUILayout.FloatField("max:", matcher.MaxRange); + matcher.MaxRangeEnabled = EditorGUILayout.Toggle(matcher.MaxRangeEnabled); + EditorGUILayout.EndHorizontal(); + break; + + case FeatureStyle.Matcher.Type.PropertyValue: + matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty); + matcher.PropertyValue = EditorGUILayout.TextField("Property value:", matcher.PropertyValue); + break; + + case FeatureStyle.Matcher.Type.PropertyRegex: + matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty); + matcher.RegexPattern = EditorGUILayout.TextField("Regex:", matcher.RegexPattern); + break; + } } - if (state.markedForDeletion) + for (int i = matcherEditors.Count - 1; i >= 0; i--) { - matcher.Matchers.Remove(editor.Matcher); - matcherEditors.RemoveAt(i); + var editor = matcherEditors[i]; + + var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), editor.Matcher.MatcherType.ToString()); + + if (state.show) + { + editor.OnInspectorGUI(); + } + + if (state.markedForDeletion) + { + matcher.Matchers.Remove(editor.Matcher); + matcherEditors.RemoveAt(i); + } } - } - EditorGUI.indentLevel--; + EditorGUI.indentLevel--; + } } } - - diff --git a/Assets/Editor/PolygonBuilderEditor.cs b/Assets/Editor/PolygonBuilderEditor.cs index ac0b53d0..c631c0f8 100644 --- a/Assets/Editor/PolygonBuilderEditor.cs +++ b/Assets/Editor/PolygonBuilderEditor.cs @@ -5,59 +5,67 @@ using Mapzen.Unity; using System; -[Serializable] -public class PolygonBuilderEditor : EditorBase +namespace PluginEditor { - [SerializeField] - private bool show; - - public PolygonBuilderEditor() - : base() - { - this.show = false; - } - - public static PolygonBuilder.Options DefaultOptions() + [Serializable] + public class PolygonBuilderEditor : EditorBase { - var defaultOptions = new PolygonBuilder.Options(); + [SerializeField] + private bool show; - defaultOptions.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; - defaultOptions.Enabled = true; - defaultOptions.MaxHeight = 0.0f; - defaultOptions.Material = new Material(Shader.Find("Diffuse")); + [SerializeField] + private PolygonBuilder.Options options; - return defaultOptions; - } - - private void LoadPreferences() - { - show = EditorPrefs.GetBool(guid + ".show"); - } + public PolygonBuilder.Options Options + { + get { return options; } + } - private void SavePreferences() - { - EditorPrefs.SetBool(guid + ".show", show); - } + public PolygonBuilderEditor(PolygonBuilder.Options options) + : base() + { + this.show = false; + this.options = options; + } - public PolygonBuilder.Options OnInspectorGUI(PolygonBuilder.Options options) - { - LoadPreferences(); + public PolygonBuilderEditor() + : base() + { + this.show = false; + this.options = new PolygonBuilder.Options(); + this.options.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; + this.options.Enabled = true; + this.options.MaxHeight = 0.0f; + this.options.Material = new Material(Shader.Find("Diffuse")); + } - show = EditorGUILayout.Foldout(show, "Polygon builder options"); + private void LoadPreferences() + { + show = EditorPrefs.GetBool(guid + ".show"); + } - if (!show) + private void SavePreferences() { - SavePreferences(); - return options; + EditorPrefs.SetBool(guid + ".show", show); } - options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); - options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); - options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; - options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); + public override void OnInspectorGUI() + { + LoadPreferences(); + + show = EditorGUILayout.Foldout(show, "Polygon builder options"); - SavePreferences(); + if (!show) + { + SavePreferences(); + } - return options; + options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); + options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); + options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; + options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); + + SavePreferences(); + } } } diff --git a/Assets/Editor/PolylineBuilderEditor.cs b/Assets/Editor/PolylineBuilderEditor.cs index 2885e989..7453914f 100644 --- a/Assets/Editor/PolylineBuilderEditor.cs +++ b/Assets/Editor/PolylineBuilderEditor.cs @@ -5,65 +5,70 @@ using System.Linq; using System; -[Serializable] -public class PolylineBuilderEditor : EditorBase +namespace PluginEditor { - [SerializeField] - private bool show; - - public PolylineBuilderEditor() - : base() - { - this.show = false; - } - - public static PolylineBuilder.Options DefaultOptions() + [Serializable] + public class PolylineBuilderEditor : EditorBase { - var defaultOptions = new PolylineBuilder.Options(); + [SerializeField] + private bool show; - defaultOptions.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; - defaultOptions.Enabled = true; - defaultOptions.MaxHeight = 3.0f; - defaultOptions.MiterLimit = 3.0f; - defaultOptions.Width = 15.0f; - defaultOptions.Material = new Material(Shader.Find("Diffuse")); + [SerializeField] + private PolylineBuilder.Options options; - return defaultOptions; - } - - private void LoadPreferences() - { - show = EditorPrefs.GetBool(guid + ".show"); - } - - private void SavePreferences() - { - EditorPrefs.SetBool(guid + ".show", show); - } + public PolylineBuilder.Options Options + { + get { return options; } + } - public PolylineBuilder.Options OnInspectorGUI(PolylineBuilder.Options options) - { - LoadPreferences(); + public PolylineBuilderEditor(PolylineBuilder.Options options) + : base() + { + this.show = false; + this.options = options; + } - show = EditorGUILayout.Foldout(show, "Polyline builder options"); + public PolylineBuilderEditor() + : base() + { + this.show = false; + this.options = new PolylineBuilder.Options(); + this.options.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; + this.options.Enabled = true; + this.options.MaxHeight = 3.0f; + this.options.MiterLimit = 3.0f; + this.options.Width = 15.0f; + this.options.Material = new Material(Shader.Find("Diffuse")); + } - if (!show) + private void LoadPreferences() { - SavePreferences(); - return options; + show = EditorPrefs.GetBool(guid + ".show"); } - options.Width = EditorGUILayout.FloatField("Width: ", options.Width); - options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); - options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); - options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; - if (options.Material.name != "Legacy Shaders/Diffuse") { - int breakhere = 0; + private void SavePreferences() + { + EditorPrefs.SetBool(guid + ".show", show); } - options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); - SavePreferences(); + public override void OnInspectorGUI() + { + LoadPreferences(); + + show = EditorGUILayout.Foldout(show, "Polyline builder options"); + + if (!show) + { + SavePreferences(); + } - return options; + options.Width = EditorGUILayout.FloatField("Width: ", options.Width); + options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); + options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); + options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; + options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); + + SavePreferences(); + } } } diff --git a/Assets/Editor/StyleEditor.cs b/Assets/Editor/StyleEditor.cs index b8d55fd4..b34c2cf1 100644 --- a/Assets/Editor/StyleEditor.cs +++ b/Assets/Editor/StyleEditor.cs @@ -7,89 +7,92 @@ using System.Linq; using System; -[Serializable] -public class StyleEditor : EditorBase +namespace PluginEditor { - [SerializeField] - private string filterName = ""; - - [SerializeField] - private List filterStyleEditors; - - [SerializeField] - private FeatureStyle style; - - public FeatureStyle Style + [Serializable] + public class StyleEditor : EditorBase { - get { return style; } - } + [SerializeField] + private string filterName = ""; - public StyleEditor(FeatureStyle style) - : base() - { - this.filterStyleEditors = new List(); - this.style = style; + [SerializeField] + private List filterStyleEditors; + + [SerializeField] + private FeatureStyle style; - foreach (var filterStyle in style.FilterStyles) + public FeatureStyle Style { - filterStyleEditors.Add(new FilterStyleEditor(filterStyle)); + get { return style; } } - } - public void OnInspectorGUI() - { - EditorGUILayout.BeginHorizontal(); + public StyleEditor(FeatureStyle style) + : base() { - filterName = EditorGUILayout.TextField("Filter name: ", filterName); + this.filterStyleEditors = new List(); + this.style = style; - EditorConfig.SetColor(EditorConfig.AddButtonColor); - if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) + foreach (var filterStyle in style.FilterStyles) { - // Filters within a style are identified by their filter name - var queryFilterStyleName = style.FilterStyles.Where(filterStyle => filterStyle.Name == filterName); + filterStyleEditors.Add(new FilterStyleEditor(filterStyle)); + } + } - if (filterName.Length == 0) - { - Debug.LogError("The filter name can't be empty"); - } - else if (queryFilterStyleName.Count() > 0) - { - Debug.LogError("Filter with name " + filterName + " already exists"); - } - else + public override void OnInspectorGUI() + { + EditorGUILayout.BeginHorizontal(); + { + filterName = EditorGUILayout.TextField("Filter name: ", filterName); + + EditorConfig.SetColor(EditorConfig.AddButtonColor); + if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) { - var filterStyle = new FeatureStyle.FilterStyle(filterName); - style.AddFilterStyle(filterStyle); - filterStyleEditors.Add(new FilterStyleEditor(filterStyle)); + // Filters within a style are identified by their filter name + var queryFilterStyleName = style.FilterStyles.Where(filterStyle => filterStyle.Name == filterName); + + if (filterName.Length == 0) + { + Debug.LogError("The filter name can't be empty"); + } + else if (queryFilterStyleName.Count() > 0) + { + Debug.LogError("Filter with name " + filterName + " already exists"); + } + else + { + var filterStyle = new FeatureStyle.FilterStyle(filterName); + style.AddFilterStyle(filterStyle); + filterStyleEditors.Add(new FilterStyleEditor(filterStyle)); + } } + EditorConfig.ResetColor(); } - EditorConfig.ResetColor(); - } - EditorGUILayout.EndHorizontal(); + EditorGUILayout.EndHorizontal(); - EditorGUI.indentLevel++; + EditorGUI.indentLevel++; - for (int i = filterStyleEditors.Count - 1; i >= 0; i--) - { - var editor = filterStyleEditors[i]; - var filterStyle = editor.FilterStyle; + for (int i = filterStyleEditors.Count - 1; i >= 0; i--) + { + var editor = filterStyleEditors[i]; + var filterStyle = editor.FilterStyle; - var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), filterStyle.Name); + var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), filterStyle.Name); - if (state.show) - { - editor.OnInspectorGUI(); - } + if (state.show) + { + editor.OnInspectorGUI(); + } - if (state.markedForDeletion) - { - style.RemoveFilterStyle(filterStyle); + if (state.markedForDeletion) + { + style.RemoveFilterStyle(filterStyle); - // Remove the editor for this filter - filterStyleEditors.RemoveAt(i); + // Remove the editor for this filter + filterStyleEditors.RemoveAt(i); + } } - } - EditorGUI.indentLevel--; + EditorGUI.indentLevel--; + } } } From 9a8d25a99c901710b645dbf6dd80692865c15f0c Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 7 Nov 2017 11:39:34 -0500 Subject: [PATCH 04/10] Refactor usage of polygon/polyline options - Use class instead of struct - Only use the options as readonly --- Assets/Mapzen/Unity/FeatureStyle.cs | 62 ++------------------------ Assets/Mapzen/Unity/PolygonBuilder.cs | 45 +++++++++++++++---- Assets/Mapzen/Unity/PolylineBuilder.cs | 15 ++++--- Assets/Mapzen/Unity/TileTask.cs | 21 ++++++--- 4 files changed, 64 insertions(+), 79 deletions(-) diff --git a/Assets/Mapzen/Unity/FeatureStyle.cs b/Assets/Mapzen/Unity/FeatureStyle.cs index c5f497c2..c082976c 100644 --- a/Assets/Mapzen/Unity/FeatureStyle.cs +++ b/Assets/Mapzen/Unity/FeatureStyle.cs @@ -11,26 +11,14 @@ namespace Mapzen.Unity [CreateAssetMenu(menuName = "Mapzen/Style")] public class FeatureStyle : ScriptableObject { - [Serializable] - public class PolygonBuilderEditorOption { - public Guid editorGUID; - public PolygonBuilder.Options option; - } - - [Serializable] - public class PolylineBuilderEditorOption { - public Guid editorGUID; - public PolylineBuilder.Options option; - } - [Serializable] public class LayerStyle { [SerializeField] private string layerName; - public List PolygonBuilderEditorOptions; - public List PolylineBuilderEditorOptions; + public List PolygonBuilderOptions; + public List PolylineBuilderOptions; public string LayerName { @@ -40,50 +28,8 @@ public string LayerName public LayerStyle(string layerName) { this.layerName = layerName; - this.PolygonBuilderEditorOptions = new List(); - this.PolylineBuilderEditorOptions = new List(); - } - - public List GetPolygonOptions(Feature feature, float inverseTileScale) - { - List polygonBuilderOptions = new List(); - - foreach (var editorOption in PolygonBuilderEditorOptions) { - var options = editorOption.option; - - if (options.MaxHeight > 0.0f) - { - options.MaxHeight *= inverseTileScale; - } - else - { - object heightValue; - if (feature.TryGetProperty("height", out heightValue) && heightValue is double) - { - options.MaxHeight = (float)((double)heightValue * inverseTileScale); - } - } - - polygonBuilderOptions.Add(options); - } - - return polygonBuilderOptions; - } - - public List GetPolylineOptions(Feature feature, float inverseTileScale) - { - List polylineBuilderOptions = new List(); - - foreach (var editorOption in PolylineBuilderEditorOptions) { - var options = editorOption.option; - - options.Width *= inverseTileScale; - options.MaxHeight *= inverseTileScale; - - polylineBuilderOptions.Add(options); - } - - return polylineBuilderOptions; + this.PolygonBuilderOptions = new List(); + this.PolylineBuilderOptions = new List(); } } diff --git a/Assets/Mapzen/Unity/PolygonBuilder.cs b/Assets/Mapzen/Unity/PolygonBuilder.cs index 256e05e0..39888577 100644 --- a/Assets/Mapzen/Unity/PolygonBuilder.cs +++ b/Assets/Mapzen/Unity/PolygonBuilder.cs @@ -17,7 +17,7 @@ public enum ExtrusionType } [Serializable] - public struct Options + public class Options { public Material Material; public ExtrusionType Extrusion; @@ -26,16 +26,20 @@ public struct Options public bool Enabled; } - public PolygonBuilder(MeshData outputMeshData, Options options, Matrix4x4 transform) + public PolygonBuilder(MeshData outputMeshData, Options options, Matrix4x4 transform, float inverseTileScale, float featureHeight) { this.transform = transform; this.outputMeshData = outputMeshData; this.options = options; + this.inverseTileScale = inverseTileScale; + this.featureHeight = featureHeight; } private Matrix4x4 transform; private MeshData outputMeshData; - private Options options; + private readonly Options options; + private float inverseTileScale; + private float featureHeight; // Values for the tesselator. private List coordinates = new List(); @@ -50,12 +54,35 @@ public PolygonBuilder(MeshData outputMeshData, Options options, Matrix4x4 transf private List polygonUVs = new List(); private List extrusionIndices = new List(); + private float GetMinHeight() + { + float minHeight = 0.0f; + if (options.MinHeight != 0.0f) + { + minHeight = options.MinHeight * inverseTileScale; + } + return minHeight; + } + + private float GetMaxHeight() + { + float maxHeight = featureHeight * inverseTileScale; + if (options.MaxHeight != 0.0f) + { + maxHeight = options.MaxHeight * inverseTileScale; + } + return maxHeight; + } + public void OnPoint(Point point) { bool buildWalls = options.Extrusion == ExtrusionType.TopAndSides || options.Extrusion == ExtrusionType.SidesOnly; + float minHeight = GetMinHeight(); + float maxHeight = GetMaxHeight(); + // For all but the first point in each ring, create a quad extending from the // previous point to the current point and from MinHeight to MaxHeight. if (buildWalls && pointsInRing > 0) @@ -65,10 +92,10 @@ public void OnPoint(Point point) var indexOffset = extrusionVertices.Count; - var v0 = new Vector3(p0.X, options.MaxHeight, p0.Y); - var v1 = new Vector3(p1.X, options.MaxHeight, p1.Y); - var v2 = new Vector3(p0.X, options.MinHeight, p0.Y); - var v3 = new Vector3(p1.X, options.MinHeight, p1.Y); + var v0 = new Vector3(p0.X, maxHeight, p0.Y); + var v1 = new Vector3(p1.X, maxHeight, p1.Y); + var v2 = new Vector3(p0.X, minHeight, p0.Y); + var v3 = new Vector3(p1.X, minHeight, p1.Y); v0 = this.transform.MultiplyPoint(v0); v1 = this.transform.MultiplyPoint(v1); @@ -145,6 +172,8 @@ public void OnBeginPolygon() public void OnEndPolygon() { + float maxHeight = GetMaxHeight(); + // First add vertices and indices for extrusions. outputMeshData.AddElements(extrusionVertices, extrusionUVs, extrusionIndices, options.Material); @@ -172,7 +201,7 @@ public void OnEndPolygon() for (int i = 0; i < coordinates.Count; i += 2) { - var v = new Vector3(coordinates[i], options.MaxHeight, coordinates[i + 1]); + var v = new Vector3(coordinates[i], maxHeight, coordinates[i + 1]); v = this.transform.MultiplyPoint(v); vertices.Add(v); } diff --git a/Assets/Mapzen/Unity/PolylineBuilder.cs b/Assets/Mapzen/Unity/PolylineBuilder.cs index 527c5c82..85d6c0ff 100644 --- a/Assets/Mapzen/Unity/PolylineBuilder.cs +++ b/Assets/Mapzen/Unity/PolylineBuilder.cs @@ -10,13 +10,13 @@ public class PolylineBuilder : IGeometryHandler { private PolygonBuilder polygonBuilder; private List polyline; - private Options options; + private readonly Options options; private float uvDistance; - + private float inverseTileScale; [Serializable] - public struct Options + public class Options { public Material Material; public PolygonBuilder.ExtrusionType Extrusion; @@ -27,9 +27,10 @@ public struct Options public bool Enabled; } - public PolylineBuilder(MeshData outputMeshData, Options options, Matrix4x4 transform) + public PolylineBuilder(MeshData outputMeshData, Options options, Matrix4x4 transform, float inverseTileScale, float featureHeight) { this.options = options; + this.inverseTileScale = inverseTileScale; var polygonOptions = new PolygonBuilder.Options(); polygonOptions.Material = options.Material; @@ -37,7 +38,7 @@ public PolylineBuilder(MeshData outputMeshData, Options options, Matrix4x4 trans polygonOptions.MinHeight = options.MinHeight; polygonOptions.MaxHeight = options.MaxHeight; - polygonBuilder = new PolygonBuilder(outputMeshData, polygonOptions, transform); + polygonBuilder = new PolygonBuilder(outputMeshData, polygonOptions, transform, inverseTileScale, featureHeight); polyline = new List(); uvDistance = 0.0f; } @@ -72,8 +73,8 @@ public void OnEndLineString() return; } - float extrude = options.Width * 0.5f; - float invWidth = 1.0f / options.Width; + float extrude = options.Width * inverseTileScale * 0.5f; + float invWidth = 1.0f / (options.Width * inverseTileScale); if (polyline.Count == 2) { diff --git a/Assets/Mapzen/Unity/TileTask.cs b/Assets/Mapzen/Unity/TileTask.cs index 40e99995..5eede7a1 100644 --- a/Assets/Mapzen/Unity/TileTask.cs +++ b/Assets/Mapzen/Unity/TileTask.cs @@ -61,8 +61,10 @@ public void Start(List featureStyling, SceneGroup root) { var layerStyle = filterStyle.LayerStyles.Find(ls => ls.LayerName == layer.Name); + float featureHeight = 0.0f; string featureName = ""; object identifier; + object heightValue; if (feature.TryGetProperty("id", out identifier)) { @@ -71,30 +73,37 @@ public void Start(List featureStyling, SceneGroup root) OnSceneGroupData(SceneGroup.Type.Feature, featureName, layerGroup, ref leaf); + if (feature.TryGetProperty("height", out heightValue) && heightValue is double) + { + featureHeight = (float)heightValue; + } + if (feature.Type == GeometryType.Polygon || feature.Type == GeometryType.MultiPolygon) { - foreach (var polygonOptions in layerStyle.GetPolygonOptions(feature, inverseTileScale)) + foreach (var polygonOptions in layerStyle.PolygonBuilderOptions) { - if (!polygonOptions.Enabled) + if (!polygonOptions.Enabled) { continue; } - var builder = new PolygonBuilder(leaf.meshData, polygonOptions, transform); + var builder = new PolygonBuilder(leaf.meshData, polygonOptions, + transform, inverseTileScale, featureHeight); feature.HandleGeometry(builder); } } if (feature.Type == GeometryType.LineString || feature.Type == GeometryType.MultiLineString) { - foreach (var polylineOptions in layerStyle.GetPolylineOptions(feature, inverseTileScale)) + foreach (var polylineOptions in layerStyle.PolylineBuilderOptions) { - if (!polylineOptions.Enabled) + if (!polylineOptions.Enabled) { continue; } - var builder = new PolylineBuilder(leaf.meshData, polylineOptions, transform); + var builder = new PolylineBuilder(leaf.meshData, polylineOptions, + transform, inverseTileScale, featureHeight); feature.HandleGeometry(builder); } } From c0f24d79e77caab08d09fda7bd9dd4e1117466f6 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Tue, 7 Nov 2017 17:31:18 -0500 Subject: [PATCH 05/10] Add editor builder, cleanup polygon and polyline builder --- Assets/Editor/EditorBase.cs | 9 +++++- Assets/Editor/LayerStyleEditor.cs | 37 +++++++++++++++++++------ Assets/Editor/PolygonBuilderEditor.cs | 38 +++++--------------------- Assets/Editor/PolylineBuilderEditor.cs | 36 ++++-------------------- 4 files changed, 50 insertions(+), 70 deletions(-) diff --git a/Assets/Editor/EditorBase.cs b/Assets/Editor/EditorBase.cs index 151fcb0b..7385c9f0 100644 --- a/Assets/Editor/EditorBase.cs +++ b/Assets/Editor/EditorBase.cs @@ -9,10 +9,17 @@ namespace PluginEditor public abstract class EditorBase : IEditor { protected Guid guid; + public string Name; public EditorBase() { - guid = Guid.NewGuid(); + this.guid = Guid.NewGuid(); + } + + public EditorBase(string name) + { + this.Name = name; + this.guid = Guid.NewGuid(); } public Guid GUID diff --git a/Assets/Editor/LayerStyleEditor.cs b/Assets/Editor/LayerStyleEditor.cs index 68551107..f2da13a4 100644 --- a/Assets/Editor/LayerStyleEditor.cs +++ b/Assets/Editor/LayerStyleEditor.cs @@ -16,7 +16,7 @@ private enum BuilderType { }; [SerializeField] - private List builderEditors; + private List builderEditors; [SerializeField] private FeatureStyle.LayerStyle layerStyle; @@ -33,16 +33,16 @@ public LayerStyleEditor(FeatureStyle.LayerStyle layerStyle) : base() { this.layerStyle = layerStyle; - this.builderEditors = new List(); + this.builderEditors = new List(); foreach (var options in layerStyle.PolygonBuilderOptions) { - this.builderEditors.Add(new PolygonBuilderEditor(options)); + this.builderEditors.Add(new PolygonBuilderEditor(options, "Polygon builder options")); } foreach (var options in layerStyle.PolylineBuilderOptions) { - this.builderEditors.Add(new PolylineBuilderEditor(options)); + this.builderEditors.Add(new PolylineBuilderEditor(options, "Polyline builder options")); } } @@ -58,12 +58,14 @@ public override void OnInspectorGUI() switch (selectedBuilderType) { case BuilderType.polygon: { - var editor = new PolygonBuilderEditor(); + var editor = new PolygonBuilderEditor("Polygon builder options"); + editor.OptionIndex = layerStyle.PolygonBuilderOptions.Count; layerStyle.PolygonBuilderOptions.Add(editor.Options); builderEditors.Add(editor); } break; case BuilderType.polyline: { - var editor = new PolylineBuilderEditor(); + var editor = new PolylineBuilderEditor("Polyline builder options"); + editor.OptionIndex = layerStyle.PolylineBuilderOptions.Count; layerStyle.PolylineBuilderOptions.Add(editor.Options); builderEditors.Add(editor); } break; @@ -74,9 +76,28 @@ public override void OnInspectorGUI() EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel++; - foreach (var builderEditor in builderEditors) + for (int i = builderEditors.Count - 1; i >= 0; --i) { - builderEditor.OnInspectorGUI(); + var editor = builderEditors[i]; + var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), editor.Name); + + if (state.show) + { + editor.OnInspectorGUI(); + } + + if (state.markedForDeletion) + { + // Remove the editor and its associated options + builderEditors.RemoveAt(i); + + if (editor is PolygonBuilderEditor) + layerStyle.PolygonBuilderOptions.RemoveAt(( + (PolygonBuilderEditor)editor).OptionIndex); + else if (editor is PolylineBuilderEditor) + layerStyle.PolylineBuilderOptions.RemoveAt(( + (PolylineBuilderEditor)editor).OptionIndex); + } } EditorGUI.indentLevel--; } diff --git a/Assets/Editor/PolygonBuilderEditor.cs b/Assets/Editor/PolygonBuilderEditor.cs index c631c0f8..7e33be81 100644 --- a/Assets/Editor/PolygonBuilderEditor.cs +++ b/Assets/Editor/PolygonBuilderEditor.cs @@ -10,9 +10,6 @@ namespace PluginEditor [Serializable] public class PolygonBuilderEditor : EditorBase { - [SerializeField] - private bool show; - [SerializeField] private PolygonBuilder.Options options; @@ -21,17 +18,17 @@ public PolygonBuilder.Options Options get { return options; } } - public PolygonBuilderEditor(PolygonBuilder.Options options) - : base() + public int OptionIndex; + + public PolygonBuilderEditor(PolygonBuilder.Options options, string name) + : base(name) { - this.show = false; this.options = options; } - public PolygonBuilderEditor() - : base() + public PolygonBuilderEditor(string name) + : base(name) { - this.show = false; this.options = new PolygonBuilder.Options(); this.options.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; this.options.Enabled = true; @@ -39,33 +36,12 @@ public PolygonBuilderEditor() this.options.Material = new Material(Shader.Find("Diffuse")); } - private void LoadPreferences() - { - show = EditorPrefs.GetBool(guid + ".show"); - } - - private void SavePreferences() - { - EditorPrefs.SetBool(guid + ".show", show); - } - public override void OnInspectorGUI() { - LoadPreferences(); - - show = EditorGUILayout.Foldout(show, "Polygon builder options"); - - if (!show) - { - SavePreferences(); - } - options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; - options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); - - SavePreferences(); + options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); } } } diff --git a/Assets/Editor/PolylineBuilderEditor.cs b/Assets/Editor/PolylineBuilderEditor.cs index 7453914f..adba67d3 100644 --- a/Assets/Editor/PolylineBuilderEditor.cs +++ b/Assets/Editor/PolylineBuilderEditor.cs @@ -10,28 +10,25 @@ namespace PluginEditor [Serializable] public class PolylineBuilderEditor : EditorBase { - [SerializeField] - private bool show; - [SerializeField] private PolylineBuilder.Options options; + public int OptionIndex; + public PolylineBuilder.Options Options { get { return options; } } - public PolylineBuilderEditor(PolylineBuilder.Options options) - : base() + public PolylineBuilderEditor(PolylineBuilder.Options options, string name) + : base(name) { - this.show = false; this.options = options; } - public PolylineBuilderEditor() - : base() + public PolylineBuilderEditor(string name) + : base(name) { - this.show = false; this.options = new PolylineBuilder.Options(); this.options.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; this.options.Enabled = true; @@ -41,34 +38,13 @@ public PolylineBuilderEditor() this.options.Material = new Material(Shader.Find("Diffuse")); } - private void LoadPreferences() - { - show = EditorPrefs.GetBool(guid + ".show"); - } - - private void SavePreferences() - { - EditorPrefs.SetBool(guid + ".show", show); - } - public override void OnInspectorGUI() { - LoadPreferences(); - - show = EditorGUILayout.Foldout(show, "Polyline builder options"); - - if (!show) - { - SavePreferences(); - } - options.Width = EditorGUILayout.FloatField("Width: ", options.Width); options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); - - SavePreferences(); } } } From 3e9a6b0083af564f23104c72e962061d8e979dd8 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 8 Nov 2017 11:39:06 -0500 Subject: [PATCH 06/10] Merge builder editors --- Assets/Editor/BuilderEditor.cs | 98 +++++++++++++++++++ ...erEditor.cs.meta => BuilderEditor.cs.meta} | 4 +- Assets/Editor/EditorBase.cs | 11 +-- Assets/Editor/IEditor.cs | 8 -- Assets/Editor/IEditor.cs.meta | 12 --- Assets/Editor/LayerStyleEditor.cs | 46 +++------ Assets/Editor/PolygonBuilderEditor.cs | 47 --------- Assets/Editor/PolygonBuilderEditor.cs.meta | 12 --- Assets/Editor/PolylineBuilderEditor.cs | 50 ---------- Assets/Mapzen/Unity/TileTask.cs | 2 +- 10 files changed, 115 insertions(+), 175 deletions(-) create mode 100644 Assets/Editor/BuilderEditor.cs rename Assets/Editor/{PolylineBuilderEditor.cs.meta => BuilderEditor.cs.meta} (76%) delete mode 100644 Assets/Editor/IEditor.cs delete mode 100644 Assets/Editor/IEditor.cs.meta delete mode 100644 Assets/Editor/PolygonBuilderEditor.cs delete mode 100644 Assets/Editor/PolygonBuilderEditor.cs.meta delete mode 100644 Assets/Editor/PolylineBuilderEditor.cs diff --git a/Assets/Editor/BuilderEditor.cs b/Assets/Editor/BuilderEditor.cs new file mode 100644 index 00000000..fb4c9ef8 --- /dev/null +++ b/Assets/Editor/BuilderEditor.cs @@ -0,0 +1,98 @@ +using UnityEngine; +using UnityEditor; +using Mapzen; +using Mapzen.Unity; +using System.Linq; +using System; + +namespace PluginEditor +{ + [Serializable] + public class BuilderEditor : EditorBase + { + public enum BuilderType + { + Polygons, + Polylines, + } + + [SerializeField] + private PolygonBuilder.Options polygonBuilderOptions; + + [SerializeField] + private PolylineBuilder.Options polylineBuilderOptions; + + public string Name; + public BuilderType Type; + + public PolylineBuilder.Options PolylineBuilderOptions + { + get { return polylineBuilderOptions; } + } + + public PolygonBuilder.Options PolygonBuilderOptions + { + get { return polygonBuilderOptions; } + } + + public BuilderEditor(PolylineBuilder.Options options) + : base() + { + this.polylineBuilderOptions = options; + this.Type = BuilderType.Polylines; + this.Name = this.Type.ToString(); + } + + public BuilderEditor(PolygonBuilder.Options options) + : base() + { + this.polygonBuilderOptions = options; + this.Type = BuilderType.Polygons; + this.Name = this.Type.ToString(); + } + + public BuilderEditor(BuilderType type) + : base() + { + this.Type = type; + switch (Type) { + case BuilderType.Polylines: + this.polylineBuilderOptions = new PolylineBuilder.Options(); + this.polylineBuilderOptions.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; + this.polylineBuilderOptions.Enabled = true; + this.polylineBuilderOptions.MaxHeight = 3.0f; + this.polylineBuilderOptions.MiterLimit = 3.0f; + this.polylineBuilderOptions.Width = 15.0f; + this.polylineBuilderOptions.Material = new Material(Shader.Find("Diffuse")); + break; + case BuilderType.Polygons: + this.polygonBuilderOptions = new PolygonBuilder.Options(); + this.polygonBuilderOptions.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; + this.polygonBuilderOptions.Enabled = true; + this.polygonBuilderOptions.MaxHeight = 0.0f; + this.polygonBuilderOptions.Material = new Material(Shader.Find("Diffuse")); + break; + } + this.Name = this.Type.ToString(); + } + + public override void OnInspectorGUI() + { + switch (Type) { + case BuilderType.Polylines: + polylineBuilderOptions.Width = EditorGUILayout.FloatField("Width: ", polylineBuilderOptions.Width); + polylineBuilderOptions.MaxHeight = EditorGUILayout.FloatField("Max Height: ", polylineBuilderOptions.MaxHeight); + polylineBuilderOptions.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", polylineBuilderOptions.Extrusion); + polylineBuilderOptions.Material = EditorGUILayout.ObjectField("Material:", polylineBuilderOptions.Material, typeof(Material)) as Material; + polylineBuilderOptions.Enabled = EditorGUILayout.Toggle("Enabled: ", polylineBuilderOptions.Enabled); + break; + case BuilderType.Polygons: + polygonBuilderOptions.MaxHeight = EditorGUILayout.FloatField("Max Height: ", polygonBuilderOptions.MaxHeight); + polygonBuilderOptions.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", polygonBuilderOptions.Extrusion); + polygonBuilderOptions.Material = EditorGUILayout.ObjectField("Material:", polygonBuilderOptions.Material, typeof(Material)) as Material; + polygonBuilderOptions.Enabled = EditorGUILayout.Toggle("Enabled: ", polygonBuilderOptions.Enabled); + break; + } + } + } +} diff --git a/Assets/Editor/PolylineBuilderEditor.cs.meta b/Assets/Editor/BuilderEditor.cs.meta similarity index 76% rename from Assets/Editor/PolylineBuilderEditor.cs.meta rename to Assets/Editor/BuilderEditor.cs.meta index 64dc3449..b1062f69 100644 --- a/Assets/Editor/PolylineBuilderEditor.cs.meta +++ b/Assets/Editor/BuilderEditor.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 0af68d1d0a17647b6a25209cd30b9bfe -timeCreated: 1500930794 +guid: f199b7cb07c4a4e8fb8a5dd23f85716f +timeCreated: 1510095082 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/Editor/EditorBase.cs b/Assets/Editor/EditorBase.cs index 7385c9f0..766fcd6d 100644 --- a/Assets/Editor/EditorBase.cs +++ b/Assets/Editor/EditorBase.cs @@ -6,22 +6,15 @@ namespace PluginEditor /// Base class for editor, each editor has a unique guid used /// for saving custom preferences in the Unity editor prefs. /// - public abstract class EditorBase : IEditor + public abstract class EditorBase { - protected Guid guid; - public string Name; + protected Guid guid; public EditorBase() { this.guid = Guid.NewGuid(); } - public EditorBase(string name) - { - this.Name = name; - this.guid = Guid.NewGuid(); - } - public Guid GUID { get { return guid; } diff --git a/Assets/Editor/IEditor.cs b/Assets/Editor/IEditor.cs deleted file mode 100644 index 33eeb512..00000000 --- a/Assets/Editor/IEditor.cs +++ /dev/null @@ -1,8 +0,0 @@ - -namespace PluginEditor -{ - public interface IEditor - { - void OnInspectorGUI(); - } -} diff --git a/Assets/Editor/IEditor.cs.meta b/Assets/Editor/IEditor.cs.meta deleted file mode 100644 index e059ba2c..00000000 --- a/Assets/Editor/IEditor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 8ee11d146df90412b947c6adffc3fa22 -timeCreated: 1509997026 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Editor/LayerStyleEditor.cs b/Assets/Editor/LayerStyleEditor.cs index f2da13a4..0e7affc7 100644 --- a/Assets/Editor/LayerStyleEditor.cs +++ b/Assets/Editor/LayerStyleEditor.cs @@ -10,19 +10,14 @@ namespace PluginEditor [SerializeField] public class LayerStyleEditor : EditorBase { - private enum BuilderType { - polygon, - polyline, - }; - [SerializeField] - private List builderEditors; + private List builderEditors; [SerializeField] private FeatureStyle.LayerStyle layerStyle; [SerializeField] - private BuilderType selectedBuilderType; + private BuilderEditor.BuilderType selectedBuilderType; public FeatureStyle.LayerStyle LayerStyle { @@ -33,16 +28,16 @@ public LayerStyleEditor(FeatureStyle.LayerStyle layerStyle) : base() { this.layerStyle = layerStyle; - this.builderEditors = new List(); + this.builderEditors = new List(); foreach (var options in layerStyle.PolygonBuilderOptions) { - this.builderEditors.Add(new PolygonBuilderEditor(options, "Polygon builder options")); + this.builderEditors.Add(new BuilderEditor(options)); } foreach (var options in layerStyle.PolylineBuilderOptions) { - this.builderEditors.Add(new PolylineBuilderEditor(options, "Polyline builder options")); + this.builderEditors.Add(new BuilderEditor(options)); } } @@ -50,26 +45,15 @@ public override void OnInspectorGUI() { EditorGUILayout.BeginHorizontal(); { - selectedBuilderType = (BuilderType)EditorGUILayout.EnumPopup("Add builder", selectedBuilderType); + selectedBuilderType = (BuilderEditor.BuilderType)EditorGUILayout.EnumPopup("Add builder", selectedBuilderType); EditorConfig.SetColor(EditorConfig.AddButtonColor); if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) { - switch (selectedBuilderType) - { - case BuilderType.polygon: { - var editor = new PolygonBuilderEditor("Polygon builder options"); - editor.OptionIndex = layerStyle.PolygonBuilderOptions.Count; - layerStyle.PolygonBuilderOptions.Add(editor.Options); - builderEditors.Add(editor); - } break; - case BuilderType.polyline: { - var editor = new PolylineBuilderEditor("Polyline builder options"); - editor.OptionIndex = layerStyle.PolylineBuilderOptions.Count; - layerStyle.PolylineBuilderOptions.Add(editor.Options); - builderEditors.Add(editor); - } break; - } + var editor = new BuilderEditor(selectedBuilderType); + layerStyle.PolygonBuilderOptions.Add(editor.PolygonBuilderOptions); + layerStyle.PolylineBuilderOptions.Add(editor.PolylineBuilderOptions); + builderEditors.Add(editor); } EditorConfig.ResetColor(); } @@ -88,15 +72,9 @@ public override void OnInspectorGUI() if (state.markedForDeletion) { - // Remove the editor and its associated options builderEditors.RemoveAt(i); - - if (editor is PolygonBuilderEditor) - layerStyle.PolygonBuilderOptions.RemoveAt(( - (PolygonBuilderEditor)editor).OptionIndex); - else if (editor is PolylineBuilderEditor) - layerStyle.PolylineBuilderOptions.RemoveAt(( - (PolylineBuilderEditor)editor).OptionIndex); + layerStyle.PolygonBuilderOptions.Remove(editor.PolygonBuilderOptions); + layerStyle.PolylineBuilderOptions.Remove(editor.PolylineBuilderOptions); } } EditorGUI.indentLevel--; diff --git a/Assets/Editor/PolygonBuilderEditor.cs b/Assets/Editor/PolygonBuilderEditor.cs deleted file mode 100644 index 7e33be81..00000000 --- a/Assets/Editor/PolygonBuilderEditor.cs +++ /dev/null @@ -1,47 +0,0 @@ -using UnityEngine; -using UnityEditor; -using Mapzen; -using System.Linq; -using Mapzen.Unity; -using System; - -namespace PluginEditor -{ - [Serializable] - public class PolygonBuilderEditor : EditorBase - { - [SerializeField] - private PolygonBuilder.Options options; - - public PolygonBuilder.Options Options - { - get { return options; } - } - - public int OptionIndex; - - public PolygonBuilderEditor(PolygonBuilder.Options options, string name) - : base(name) - { - this.options = options; - } - - public PolygonBuilderEditor(string name) - : base(name) - { - this.options = new PolygonBuilder.Options(); - this.options.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; - this.options.Enabled = true; - this.options.MaxHeight = 0.0f; - this.options.Material = new Material(Shader.Find("Diffuse")); - } - - public override void OnInspectorGUI() - { - options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); - options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); - options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; - options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); - } - } -} diff --git a/Assets/Editor/PolygonBuilderEditor.cs.meta b/Assets/Editor/PolygonBuilderEditor.cs.meta deleted file mode 100644 index c74acdfa..00000000 --- a/Assets/Editor/PolygonBuilderEditor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 380ea23500a1d4b37a07202fffb702fc -timeCreated: 1500930794 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Editor/PolylineBuilderEditor.cs b/Assets/Editor/PolylineBuilderEditor.cs deleted file mode 100644 index adba67d3..00000000 --- a/Assets/Editor/PolylineBuilderEditor.cs +++ /dev/null @@ -1,50 +0,0 @@ -using UnityEngine; -using UnityEditor; -using Mapzen; -using Mapzen.Unity; -using System.Linq; -using System; - -namespace PluginEditor -{ - [Serializable] - public class PolylineBuilderEditor : EditorBase - { - [SerializeField] - private PolylineBuilder.Options options; - - public int OptionIndex; - - public PolylineBuilder.Options Options - { - get { return options; } - } - - public PolylineBuilderEditor(PolylineBuilder.Options options, string name) - : base(name) - { - this.options = options; - } - - public PolylineBuilderEditor(string name) - : base(name) - { - this.options = new PolylineBuilder.Options(); - this.options.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; - this.options.Enabled = true; - this.options.MaxHeight = 3.0f; - this.options.MiterLimit = 3.0f; - this.options.Width = 15.0f; - this.options.Material = new Material(Shader.Find("Diffuse")); - } - - public override void OnInspectorGUI() - { - options.Width = EditorGUILayout.FloatField("Width: ", options.Width); - options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); - options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); - options.Material = EditorGUILayout.ObjectField("Material:", options.Material, typeof(Material)) as Material; - options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); - } - } -} diff --git a/Assets/Mapzen/Unity/TileTask.cs b/Assets/Mapzen/Unity/TileTask.cs index 5eede7a1..d08feb42 100644 --- a/Assets/Mapzen/Unity/TileTask.cs +++ b/Assets/Mapzen/Unity/TileTask.cs @@ -75,7 +75,7 @@ public void Start(List featureStyling, SceneGroup root) if (feature.TryGetProperty("height", out heightValue) && heightValue is double) { - featureHeight = (float)heightValue; + featureHeight = (float)((double)heightValue); } if (feature.Type == GeometryType.Polygon || feature.Type == GeometryType.MultiPolygon) From 4be6cf9d7c8313e9265e708291d22d0c663db92c Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Wed, 8 Nov 2017 11:39:21 -0500 Subject: [PATCH 07/10] Update default style --- Assets/Scenes/DefaultScene.unity | 12 +-- Assets/Scenes/DefaultStyle.asset | 170 ++++++++++++------------------- 2 files changed, 72 insertions(+), 110 deletions(-) diff --git a/Assets/Scenes/DefaultScene.unity b/Assets/Scenes/DefaultScene.unity index c3e057c0..a79e698b 100644 --- a/Assets/Scenes/DefaultScene.unity +++ b/Assets/Scenes/DefaultScene.unity @@ -38,11 +38,11 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44659358, g: 0.49642974, b: 0.574825, a: 1} + m_IndirectSpecularColor: {r: 0.4465934, g: 0.49642956, b: 0.57482487, a: 1} --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 - serializedVersion: 9 + serializedVersion: 11 m_GIWorkflowMode: 0 m_GISettings: serializedVersion: 2 @@ -54,7 +54,7 @@ LightmapSettings: m_EnableBakedLightmaps: 1 m_EnableRealtimeLightmaps: 1 m_LightmapEditorSettings: - serializedVersion: 8 + serializedVersion: 9 m_Resolution: 2 m_BakeResolution: 40 m_TextureWidth: 1024 @@ -87,7 +87,7 @@ LightmapSettings: m_PVRFilteringAtrousNormalSigma: 1 m_PVRFilteringAtrousPositionSigma: 1 m_LightingDataAsset: {fileID: 0} - m_ShadowMaskMode: 2 + m_UseShadowmask: 1 --- !u!196 &4 NavMeshSettings: serializedVersion: 2 @@ -139,7 +139,6 @@ MonoBehaviour: IsStatic: 0 GeneratePhysicMeshCollider: 0 PhysicMaterial: {fileID: 0} - regionScaleRatio: 0.01 ApiKey: mapzen-MTyWgFy Area: min: @@ -151,8 +150,9 @@ MonoBehaviour: zoom: 16 RegionName: region_0 featureStyling: - - {fileID: 11400000, guid: fc13486fe526f434c97435d16023999a, type: 2} + - {fileID: 11400000, guid: 9d2ae5fd813fc4063b3c14204f61380c, type: 2} groupOptions: 4 + regionScaleUnit: 1 --- !u!4 &349009245 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/DefaultStyle.asset b/Assets/Scenes/DefaultStyle.asset index f61b78d9..283491d6 100644 --- a/Assets/Scenes/DefaultStyle.asset +++ b/Assets/Scenes/DefaultStyle.asset @@ -15,46 +15,22 @@ MonoBehaviour: - name: filter_0 layerStyles: - layerName: roads - Material: {fileID: 2100000, guid: ca945bef7446a48c3a7e6c2241195361, type: 2} PolygonBuilderOptions: - Material: {fileID: 0} - Extrusion: 2 + - Material: {fileID: 0} + Extrusion: 0 MinHeight: 0 MaxHeight: 0 Enabled: 0 PolylineBuilderOptions: - Material: {fileID: 0} + - Material: {fileID: 0} Extrusion: 2 MinHeight: 0 MaxHeight: 3 Width: 15 MiterLimit: 3 Enabled: 1 - filter: - CollectionNameSet: [] - Matcher: - type: 7 - matchers: [] - HasProperty: kind - PropertyValue: major_road - RegexPattern: - MinRange: 0 - MaxRange: 0 - MinRangeEnabled: 1 - MaxRangeEnabled: 1 - - name: filter_1 - layerStyles: - - layerName: roads - Material: {fileID: 2100000, guid: ce1f4d2f66c614a9489e5ee52bbe34da, type: 2} - PolygonBuilderOptions: - Material: {fileID: 0} - Extrusion: 0 - MinHeight: 0 - MaxHeight: 0 - Enabled: 0 - PolylineBuilderOptions: - Material: {fileID: 0} - Extrusion: 0 + - Material: {fileID: 2100000, guid: ce1f4d2f66c614a9489e5ee52bbe34da, type: 2} + Extrusion: 1 MinHeight: 0 MaxHeight: 3 Width: 15 @@ -74,70 +50,14 @@ MonoBehaviour: MaxRangeEnabled: 1 - name: filter_2 layerStyles: - - layerName: boundaries - Material: {fileID: 2100000, guid: 7f88baed2a0f94bb3a42f7bc45b5fcf8, type: 2} - PolygonBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 0 - Enabled: 0 - PolylineBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 1 - - layerName: water - Material: {fileID: 2100000, guid: bb0267789bf4345c7916b57b125fc6ca, type: 2} - PolygonBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 0 - Enabled: 1 - PolylineBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 0 - - layerName: earth - Material: {fileID: 2100000, guid: 0cdfce05273914dd4823f77af6b71663, type: 2} - PolygonBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 0 - Enabled: 1 - PolylineBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 0 - layerName: buildings - Material: {fileID: 2100000, guid: 7f88baed2a0f94bb3a42f7bc45b5fcf8, type: 2} PolygonBuilderOptions: - Material: {fileID: 0} + - Material: {fileID: 10302, guid: 0000000000000000f000000000000000, type: 0} Extrusion: 1 MinHeight: 0 MaxHeight: 0 Enabled: 1 - PolylineBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 1 + PolylineBuilderOptions: [] filter: CollectionNameSet: [] Matcher: @@ -162,21 +82,13 @@ MonoBehaviour: - name: filter_3 layerStyles: - layerName: buildings - Material: {fileID: 2100000, guid: c583580183f69476bbe6cda2361da21e, type: 2} PolygonBuilderOptions: - Material: {fileID: 0} + - Material: {fileID: 2100000, guid: c583580183f69476bbe6cda2361da21e, type: 2} Extrusion: 1 MinHeight: 0 MaxHeight: 0 Enabled: 1 - PolylineBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 1 + PolylineBuilderOptions: [] filter: CollectionNameSet: [] Matcher: @@ -192,19 +104,25 @@ MonoBehaviour: - name: filter_4 layerStyles: - layerName: roads - Material: {fileID: 2100000, guid: f776709bfa7fa4d3a88a6b24cd6c7429, type: 2} PolygonBuilderOptions: - Material: {fileID: 0} - Extrusion: 1 + - Material: {fileID: 0} + Extrusion: 0 MinHeight: 0 MaxHeight: 0 - Enabled: 1 + Enabled: 0 PolylineBuilderOptions: - Material: {fileID: 0} + - Material: {fileID: 2100000, guid: ca945bef7446a48c3a7e6c2241195361, type: 2} + Extrusion: 2 + MinHeight: 0 + MaxHeight: 3 + Width: 15 + MiterLimit: 3 + Enabled: 1 + - Material: {fileID: 2100000, guid: f776709bfa7fa4d3a88a6b24cd6c7429, type: 2} Extrusion: 0 MinHeight: 0 - MaxHeight: 1 - Width: 10 + MaxHeight: 3 + Width: 15 MiterLimit: 3 Enabled: 1 filter: @@ -219,3 +137,47 @@ MonoBehaviour: MaxRange: 0 MinRangeEnabled: 1 MaxRangeEnabled: 1 + - name: filter_1 + layerStyles: + - layerName: earth + PolygonBuilderOptions: + - Material: {fileID: 2100000, guid: 0cdfce05273914dd4823f77af6b71663, type: 2} + Extrusion: 1 + MinHeight: 0 + MaxHeight: 0 + Enabled: 1 + PolylineBuilderOptions: + - Material: {fileID: 0} + Extrusion: 0 + MinHeight: 0 + MaxHeight: 0 + Width: 0 + MiterLimit: 0 + Enabled: 0 + - layerName: water + PolygonBuilderOptions: + - Material: {fileID: 2100000, guid: bb0267789bf4345c7916b57b125fc6ca, type: 2} + Extrusion: 1 + MinHeight: 0 + MaxHeight: 0 + Enabled: 1 + PolylineBuilderOptions: + - Material: {fileID: 0} + Extrusion: 0 + MinHeight: 0 + MaxHeight: 0 + Width: 0 + MiterLimit: 0 + Enabled: 0 + filter: + CollectionNameSet: [] + Matcher: + type: 0 + matchers: [] + HasProperty: + PropertyValue: + RegexPattern: + MinRange: 0 + MaxRange: 0 + MinRangeEnabled: 0 + MaxRangeEnabled: 0 From 4ed23cc2fd0e1adb87b82f02fe3fc2e49f1fead7 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Fri, 10 Nov 2017 12:39:22 -0500 Subject: [PATCH 08/10] Post merge fixes --- Assets/Editor/BuilderEditor.cs | 2 + Assets/Editor/FilterStyleEditor.cs | 44 ++++++++++++--- Assets/Editor/PolygonBuilderEditor.cs | 63 ---------------------- Assets/Editor/PolygonBuilderEditor.cs.meta | 12 ----- 4 files changed, 38 insertions(+), 83 deletions(-) delete mode 100644 Assets/Editor/PolygonBuilderEditor.cs delete mode 100644 Assets/Editor/PolygonBuilderEditor.cs.meta diff --git a/Assets/Editor/BuilderEditor.cs b/Assets/Editor/BuilderEditor.cs index fb4c9ef8..77d3ace6 100644 --- a/Assets/Editor/BuilderEditor.cs +++ b/Assets/Editor/BuilderEditor.cs @@ -69,6 +69,7 @@ public BuilderEditor(BuilderType type) this.polygonBuilderOptions = new PolygonBuilder.Options(); this.polygonBuilderOptions.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; this.polygonBuilderOptions.Enabled = true; + this.polygonBuilderOptions.UVMode = UVMode.Tile; this.polygonBuilderOptions.MaxHeight = 0.0f; this.polygonBuilderOptions.Material = new Material(Shader.Find("Diffuse")); break; @@ -90,6 +91,7 @@ public override void OnInspectorGUI() polygonBuilderOptions.MaxHeight = EditorGUILayout.FloatField("Max Height: ", polygonBuilderOptions.MaxHeight); polygonBuilderOptions.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", polygonBuilderOptions.Extrusion); polygonBuilderOptions.Material = EditorGUILayout.ObjectField("Material:", polygonBuilderOptions.Material, typeof(Material)) as Material; + polygonBuilderOptions.UVMode = (UVMode)EditorGUILayout.EnumPopup("UV Mode:", polygonBuilderOptions.UVMode); polygonBuilderOptions.Enabled = EditorGUILayout.Toggle("Enabled: ", polygonBuilderOptions.Enabled); break; } diff --git a/Assets/Editor/FilterStyleEditor.cs b/Assets/Editor/FilterStyleEditor.cs index ebeb33aa..a7a708fb 100644 --- a/Assets/Editor/FilterStyleEditor.cs +++ b/Assets/Editor/FilterStyleEditor.cs @@ -9,6 +9,7 @@ namespace PluginEditor { + [SerializeField] public class FilterStyleEditor : EditorBase { [SerializeField] @@ -45,6 +46,41 @@ public FilterStyleEditor(FeatureStyle.FilterStyle filterStyle) { layerStyleEditors.Add(new LayerStyleEditor(layerStyle)); } + + if (filterStyle.Matcher != null) + { + selectedMatcherType = filterStyle.Matcher.MatcherType; + this.matcherEditor = new MatcherEditor(filterStyle.Matcher); + } + } + + private void AddLayerStyleLayout(FeatureStyle.FilterStyle filterStyle, string name) + { + EditorConfig.SetColor(EditorConfig.AddButtonColor); + if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)) + { + // Layers within a filter are identifier by their layer name + var queryLayer = filterStyle.LayerStyles.Where(layerStyle => name == layerStyle.LayerName); + + if (name.Length == 0) + { + Debug.LogError("Layer name can't be empty"); + } + else if (queryLayer.Count() > 0) + { + Debug.LogError("A layer with name " + name + " already exists"); + } + else + { + var layerStyle = new FeatureStyle.LayerStyle(name); + + filterStyle.LayerStyles.Add(layerStyle); + + // Create the associated layer editor + layerStyleEditors.Add(new LayerStyleEditor(layerStyle)); + } + } + EditorConfig.ResetColor(); } public override void OnInspectorGUI() @@ -57,14 +93,6 @@ public override void OnInspectorGUI() } EditorGUILayout.EndHorizontal(); - // Custom layer entry - EditorGUILayout.BeginHorizontal(); - { - customFeatureCollection = EditorGUILayout.TextField("Custom layer:", customFeatureCollection); - AddLayerStyleLayout(filterStyle, customFeatureCollection); - } - EditorGUILayout.EndHorizontal(); - EditorGUI.indentLevel++; for (int i = layerStyleEditors.Count - 1; i >= 0; i--) diff --git a/Assets/Editor/PolygonBuilderEditor.cs b/Assets/Editor/PolygonBuilderEditor.cs deleted file mode 100644 index 52811c47..00000000 --- a/Assets/Editor/PolygonBuilderEditor.cs +++ /dev/null @@ -1,63 +0,0 @@ -using UnityEngine; -using UnityEditor; -using Mapzen; -using System.Linq; -using Mapzen.Unity; -using System; - -[Serializable] -public class PolygonBuilderEditor : EditorBase -{ - [SerializeField] - private bool show; - - public PolygonBuilderEditor() - : base() - { - this.show = false; - } - - public static PolygonBuilder.Options DefaultOptions() - { - var defaultOptions = new PolygonBuilder.Options(); - - defaultOptions.Extrusion = PolygonBuilder.ExtrusionType.TopAndSides; - defaultOptions.UVMode = UVMode.Tile; - defaultOptions.Enabled = true; - defaultOptions.MaxHeight = 0.0f; - - return defaultOptions; - } - - private void LoadPreferences() - { - show = EditorPrefs.GetBool(guid + ".show"); - } - - private void SavePreferences() - { - EditorPrefs.SetBool(guid + ".show", show); - } - - public PolygonBuilder.Options OnInspectorGUI(PolygonBuilder.Options options) - { - LoadPreferences(); - - show = EditorGUILayout.Foldout(show, "Polygon builder options"); - - if (!show) - { - SavePreferences(); - return options; - } - - options.MaxHeight = EditorGUILayout.FloatField("Max Height: ", options.MaxHeight); - options.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", options.Extrusion); - options.UVMode = (UVMode)EditorGUILayout.EnumPopup("UV Mode:", options.UVMode); - options.Enabled = EditorGUILayout.Toggle("Enabled: ", options.Enabled); - - SavePreferences(); - - return options; - } -} diff --git a/Assets/Editor/PolygonBuilderEditor.cs.meta b/Assets/Editor/PolygonBuilderEditor.cs.meta deleted file mode 100644 index e2c1ca58..00000000 --- a/Assets/Editor/PolygonBuilderEditor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 380ea23500a1d4b37a07202fffb702fc -timeCreated: 1510334931 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From 8bd307298c2ce48f9d09cb0cc28fa2c497cc7228 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Fri, 10 Nov 2017 13:11:02 -0500 Subject: [PATCH 09/10] Update default style asset --- Assets/Scenes/DefaultStyle.asset | 188 +++++++++++++++++++------------ 1 file changed, 116 insertions(+), 72 deletions(-) diff --git a/Assets/Scenes/DefaultStyle.asset b/Assets/Scenes/DefaultStyle.asset index 069321b6..473b8044 100644 --- a/Assets/Scenes/DefaultStyle.asset +++ b/Assets/Scenes/DefaultStyle.asset @@ -15,24 +15,34 @@ MonoBehaviour: - name: filter_0 layerStyles: - layerName: roads - PolygonBuilderEditorDatas: [] - PolylineBuilderEditorDatas: - - option: - Material: {fileID: 2100000, guid: ca945bef7446a48c3a7e6c2241195361, type: 2} - Extrusion: 2 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 1 - - option: - Material: {fileID: 2100000, guid: ce1f4d2f66c614a9489e5ee52bbe34da, type: 2} - Extrusion: 0 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 1 + PolygonBuilderOptions: + - Material: {fileID: 0} + Extrusion: 0 + UVMode: 0 + MinHeight: 0 + MaxHeight: 0 + Enabled: 0 + - Material: {fileID: 0} + Extrusion: 0 + UVMode: 0 + MinHeight: 0 + MaxHeight: 0 + Enabled: 0 + PolylineBuilderOptions: + - Material: {fileID: 2100000, guid: ca945bef7446a48c3a7e6c2241195361, type: 2} + Extrusion: 2 + MinHeight: 0 + MaxHeight: 3 + Width: 15 + MiterLimit: 3 + Enabled: 1 + - Material: {fileID: 2100000, guid: ce1f4d2f66c614a9489e5ee52bbe34da, type: 2} + Extrusion: 0 + MinHeight: 0 + MaxHeight: 3 + Width: 15 + MiterLimit: 3 + Enabled: 1 filter: CollectionNameSet: [] Matcher: @@ -48,15 +58,21 @@ MonoBehaviour: - name: filter_2 layerStyles: - layerName: buildings - PolygonBuilderEditorDatas: - - option: - Material: {fileID: 10302, guid: 0000000000000000f000000000000000, type: 0} - Extrusion: 1 - UVMode: 1 - MinHeight: 0 - MaxHeight: 0 - Enabled: 1 - PolylineBuilderEditorDatas: [] + PolygonBuilderOptions: + - Material: {fileID: 10302, guid: 0000000000000000f000000000000000, type: 0} + Extrusion: 1 + UVMode: 1 + MinHeight: 0 + MaxHeight: 0 + Enabled: 1 + PolylineBuilderOptions: + - Material: {fileID: 0} + Extrusion: 0 + MinHeight: 0 + MaxHeight: 0 + Width: 0 + MiterLimit: 0 + Enabled: 0 filter: CollectionNameSet: [] Matcher: @@ -81,15 +97,21 @@ MonoBehaviour: - name: filter_3 layerStyles: - layerName: buildings - PolygonBuilderEditorDatas: - - option: - Material: {fileID: 2100000, guid: c583580183f69476bbe6cda2361da21e, type: 2} - Extrusion: 1 - UVMode: 1 - MinHeight: 0 - MaxHeight: 0 - Enabled: 1 - PolylineBuilderEditorDatas: [] + PolygonBuilderOptions: + - Material: {fileID: 2100000, guid: c583580183f69476bbe6cda2361da21e, type: 2} + Extrusion: 1 + UVMode: 1 + MinHeight: 0 + MaxHeight: 0 + Enabled: 1 + PolylineBuilderOptions: + - Material: {fileID: 0} + Extrusion: 0 + MinHeight: 0 + MaxHeight: 0 + Width: 0 + MiterLimit: 0 + Enabled: 0 filter: CollectionNameSet: [] Matcher: @@ -105,24 +127,34 @@ MonoBehaviour: - name: filter_4 layerStyles: - layerName: roads - PolygonBuilderEditorDatas: [] - PolylineBuilderEditorDatas: - - option: - Material: {fileID: 2100000, guid: ca945bef7446a48c3a7e6c2241195361, type: 2} - Extrusion: 2 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 1 - - option: - Material: {fileID: 2100000, guid: f776709bfa7fa4d3a88a6b24cd6c7429, type: 2} - Extrusion: 1 - MinHeight: 0 - MaxHeight: 3 - Width: 15 - MiterLimit: 3 - Enabled: 1 + PolygonBuilderOptions: + - Material: {fileID: 0} + Extrusion: 0 + UVMode: 0 + MinHeight: 0 + MaxHeight: 0 + Enabled: 0 + - Material: {fileID: 0} + Extrusion: 0 + UVMode: 0 + MinHeight: 0 + MaxHeight: 0 + Enabled: 0 + PolylineBuilderOptions: + - Material: {fileID: 2100000, guid: ca945bef7446a48c3a7e6c2241195361, type: 2} + Extrusion: 2 + MinHeight: 0 + MaxHeight: 3 + Width: 15 + MiterLimit: 3 + Enabled: 1 + - Material: {fileID: 2100000, guid: f776709bfa7fa4d3a88a6b24cd6c7429, type: 2} + Extrusion: 0 + MinHeight: 0 + MaxHeight: 3 + Width: 15 + MiterLimit: 3 + Enabled: 1 filter: CollectionNameSet: [] Matcher: @@ -138,25 +170,37 @@ MonoBehaviour: - name: filter_1 layerStyles: - layerName: earth - PolygonBuilderEditorDatas: - - option: - Material: {fileID: 2100000, guid: 0cdfce05273914dd4823f77af6b71663, type: 2} - Extrusion: 1 - UVMode: 1 - MinHeight: 0 - MaxHeight: 0 - Enabled: 1 - PolylineBuilderEditorDatas: [] + PolygonBuilderOptions: + - Material: {fileID: 2100000, guid: 0cdfce05273914dd4823f77af6b71663, type: 2} + Extrusion: 1 + UVMode: 1 + MinHeight: 0 + MaxHeight: 0 + Enabled: 1 + PolylineBuilderOptions: + - Material: {fileID: 0} + Extrusion: 0 + MinHeight: 0 + MaxHeight: 0 + Width: 0 + MiterLimit: 0 + Enabled: 0 - layerName: water - PolygonBuilderEditorDatas: - - option: - Material: {fileID: 2100000, guid: bb0267789bf4345c7916b57b125fc6ca, type: 2} - Extrusion: 1 - UVMode: 1 - MinHeight: 0 - MaxHeight: 0 - Enabled: 1 - PolylineBuilderEditorDatas: [] + PolygonBuilderOptions: + - Material: {fileID: 2100000, guid: bb0267789bf4345c7916b57b125fc6ca, type: 2} + Extrusion: 1 + UVMode: 1 + MinHeight: 0 + MaxHeight: 0 + Enabled: 1 + PolylineBuilderOptions: + - Material: {fileID: 0} + Extrusion: 0 + MinHeight: 0 + MaxHeight: 0 + Width: 0 + MiterLimit: 0 + Enabled: 0 filter: CollectionNameSet: [] Matcher: From 2ded08eea9b51bfd042b22366b46c71d2c7ced39 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Fri, 10 Nov 2017 13:21:00 -0500 Subject: [PATCH 10/10] Add Mapzen.Editor namespace and move it to appropriate folder --- Assets/{ => Mapzen}/Editor.meta | 4 ++-- Assets/{ => Mapzen}/Editor/BuilderEditor.cs | 4 ++-- Assets/{ => Mapzen}/Editor/BuilderEditor.cs.meta | 0 Assets/{ => Mapzen}/Editor/EditorBase.cs | 4 ++-- Assets/{ => Mapzen}/Editor/EditorBase.cs.meta | 0 Assets/{ => Mapzen}/Editor/EditorConfig.cs | 2 +- Assets/{ => Mapzen}/Editor/EditorConfig.cs.meta | 0 Assets/{ => Mapzen}/Editor/FeatureStyleEditor.cs | 4 ++-- Assets/{ => Mapzen}/Editor/FeatureStyleEditor.cs.meta | 0 Assets/{ => Mapzen}/Editor/FilterStyleEditor.cs | 2 +- Assets/{ => Mapzen}/Editor/FilterStyleEditor.cs.meta | 0 Assets/{ => Mapzen}/Editor/FoldoutEditor.cs | 2 +- Assets/{ => Mapzen}/Editor/FoldoutEditor.cs.meta | 0 Assets/{ => Mapzen}/Editor/LayerStyleEditor.cs | 2 +- Assets/{ => Mapzen}/Editor/LayerStyleEditor.cs.meta | 0 Assets/{ => Mapzen}/Editor/MapzenMapEditor.cs | 4 ++-- Assets/{ => Mapzen}/Editor/MapzenMapEditor.cs.meta | 0 Assets/{ => Mapzen}/Editor/MatcherEditor.cs | 2 +- Assets/{ => Mapzen}/Editor/MatcherEditor.cs.meta | 0 Assets/{ => Mapzen}/Editor/StyleEditor.cs | 2 +- Assets/{ => Mapzen}/Editor/StyleEditor.cs.meta | 0 21 files changed, 16 insertions(+), 16 deletions(-) rename Assets/{ => Mapzen}/Editor.meta (67%) rename Assets/{ => Mapzen}/Editor/BuilderEditor.cs (98%) rename Assets/{ => Mapzen}/Editor/BuilderEditor.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/EditorBase.cs (89%) rename Assets/{ => Mapzen}/Editor/EditorBase.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/EditorConfig.cs (98%) rename Assets/{ => Mapzen}/Editor/EditorConfig.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/FeatureStyleEditor.cs (89%) rename Assets/{ => Mapzen}/Editor/FeatureStyleEditor.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/FilterStyleEditor.cs (99%) rename Assets/{ => Mapzen}/Editor/FilterStyleEditor.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/FoldoutEditor.cs (98%) rename Assets/{ => Mapzen}/Editor/FoldoutEditor.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/LayerStyleEditor.cs (99%) rename Assets/{ => Mapzen}/Editor/LayerStyleEditor.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/MapzenMapEditor.cs (98%) rename Assets/{ => Mapzen}/Editor/MapzenMapEditor.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/MatcherEditor.cs (99%) rename Assets/{ => Mapzen}/Editor/MatcherEditor.cs.meta (100%) rename Assets/{ => Mapzen}/Editor/StyleEditor.cs (99%) rename Assets/{ => Mapzen}/Editor/StyleEditor.cs.meta (100%) diff --git a/Assets/Editor.meta b/Assets/Mapzen/Editor.meta similarity index 67% rename from Assets/Editor.meta rename to Assets/Mapzen/Editor.meta index 2049bdaf..744c12a4 100644 --- a/Assets/Editor.meta +++ b/Assets/Mapzen/Editor.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: f41e6076f043149d091a13c6cd03e61c +guid: ba408ee1922154c97aa65fe76a04c4c8 folderAsset: yes -timeCreated: 1499454478 +timeCreated: 1510337917 licenseType: Free DefaultImporter: userData: diff --git a/Assets/Editor/BuilderEditor.cs b/Assets/Mapzen/Editor/BuilderEditor.cs similarity index 98% rename from Assets/Editor/BuilderEditor.cs rename to Assets/Mapzen/Editor/BuilderEditor.cs index 77d3ace6..a2a69dd4 100644 --- a/Assets/Editor/BuilderEditor.cs +++ b/Assets/Mapzen/Editor/BuilderEditor.cs @@ -5,7 +5,7 @@ using System.Linq; using System; -namespace PluginEditor +namespace Mapzen.Editor { [Serializable] public class BuilderEditor : EditorBase @@ -92,7 +92,7 @@ public override void OnInspectorGUI() polygonBuilderOptions.Extrusion = (PolygonBuilder.ExtrusionType)EditorGUILayout.EnumPopup("Extrusion type: ", polygonBuilderOptions.Extrusion); polygonBuilderOptions.Material = EditorGUILayout.ObjectField("Material:", polygonBuilderOptions.Material, typeof(Material)) as Material; polygonBuilderOptions.UVMode = (UVMode)EditorGUILayout.EnumPopup("UV Mode:", polygonBuilderOptions.UVMode); - polygonBuilderOptions.Enabled = EditorGUILayout.Toggle("Enabled: ", polygonBuilderOptions.Enabled); + polygonBuilderOptions.Enabled = EditorGUILayout.Toggle("Enabled: ", polygonBuilderOptions.Enabled); break; } } diff --git a/Assets/Editor/BuilderEditor.cs.meta b/Assets/Mapzen/Editor/BuilderEditor.cs.meta similarity index 100% rename from Assets/Editor/BuilderEditor.cs.meta rename to Assets/Mapzen/Editor/BuilderEditor.cs.meta diff --git a/Assets/Editor/EditorBase.cs b/Assets/Mapzen/Editor/EditorBase.cs similarity index 89% rename from Assets/Editor/EditorBase.cs rename to Assets/Mapzen/Editor/EditorBase.cs index 766fcd6d..af555acd 100644 --- a/Assets/Editor/EditorBase.cs +++ b/Assets/Mapzen/Editor/EditorBase.cs @@ -1,6 +1,6 @@ using System; -namespace PluginEditor +namespace Mapzen.Editor { /// /// Base class for editor, each editor has a unique guid used @@ -8,7 +8,7 @@ namespace PluginEditor /// public abstract class EditorBase { - protected Guid guid; + protected Guid guid; public EditorBase() { diff --git a/Assets/Editor/EditorBase.cs.meta b/Assets/Mapzen/Editor/EditorBase.cs.meta similarity index 100% rename from Assets/Editor/EditorBase.cs.meta rename to Assets/Mapzen/Editor/EditorBase.cs.meta diff --git a/Assets/Editor/EditorConfig.cs b/Assets/Mapzen/Editor/EditorConfig.cs similarity index 98% rename from Assets/Editor/EditorConfig.cs rename to Assets/Mapzen/Editor/EditorConfig.cs index ddb95baa..9a4fd39a 100644 --- a/Assets/Editor/EditorConfig.cs +++ b/Assets/Mapzen/Editor/EditorConfig.cs @@ -2,7 +2,7 @@ using UnityEditor; using UnityEngine; -namespace PluginEditor +namespace Mapzen.Editor { /// /// Styling configuration for the editor. diff --git a/Assets/Editor/EditorConfig.cs.meta b/Assets/Mapzen/Editor/EditorConfig.cs.meta similarity index 100% rename from Assets/Editor/EditorConfig.cs.meta rename to Assets/Mapzen/Editor/EditorConfig.cs.meta diff --git a/Assets/Editor/FeatureStyleEditor.cs b/Assets/Mapzen/Editor/FeatureStyleEditor.cs similarity index 89% rename from Assets/Editor/FeatureStyleEditor.cs rename to Assets/Mapzen/Editor/FeatureStyleEditor.cs index df326c5f..da684d76 100644 --- a/Assets/Editor/FeatureStyleEditor.cs +++ b/Assets/Mapzen/Editor/FeatureStyleEditor.cs @@ -4,10 +4,10 @@ using Mapzen; using Mapzen.Unity; -namespace PluginEditor +namespace Mapzen.Editor { [CustomEditor(typeof(FeatureStyle))] - public class FeatureStyleEditor : Editor + public class FeatureStyleEditor : UnityEditor.Editor { private FeatureStyle featureStyle; private StyleEditor styleEditor; diff --git a/Assets/Editor/FeatureStyleEditor.cs.meta b/Assets/Mapzen/Editor/FeatureStyleEditor.cs.meta similarity index 100% rename from Assets/Editor/FeatureStyleEditor.cs.meta rename to Assets/Mapzen/Editor/FeatureStyleEditor.cs.meta diff --git a/Assets/Editor/FilterStyleEditor.cs b/Assets/Mapzen/Editor/FilterStyleEditor.cs similarity index 99% rename from Assets/Editor/FilterStyleEditor.cs rename to Assets/Mapzen/Editor/FilterStyleEditor.cs index a7a708fb..99904316 100644 --- a/Assets/Editor/FilterStyleEditor.cs +++ b/Assets/Mapzen/Editor/FilterStyleEditor.cs @@ -7,7 +7,7 @@ using UnityEditor; using UnityEngine; -namespace PluginEditor +namespace Mapzen.Editor { [SerializeField] public class FilterStyleEditor : EditorBase diff --git a/Assets/Editor/FilterStyleEditor.cs.meta b/Assets/Mapzen/Editor/FilterStyleEditor.cs.meta similarity index 100% rename from Assets/Editor/FilterStyleEditor.cs.meta rename to Assets/Mapzen/Editor/FilterStyleEditor.cs.meta diff --git a/Assets/Editor/FoldoutEditor.cs b/Assets/Mapzen/Editor/FoldoutEditor.cs similarity index 98% rename from Assets/Editor/FoldoutEditor.cs rename to Assets/Mapzen/Editor/FoldoutEditor.cs index e3644276..d5a6e025 100644 --- a/Assets/Editor/FoldoutEditor.cs +++ b/Assets/Mapzen/Editor/FoldoutEditor.cs @@ -2,7 +2,7 @@ using UnityEditor; using UnityEngine; -namespace PluginEditor +namespace Mapzen.Editor { public class FoldoutEditor { diff --git a/Assets/Editor/FoldoutEditor.cs.meta b/Assets/Mapzen/Editor/FoldoutEditor.cs.meta similarity index 100% rename from Assets/Editor/FoldoutEditor.cs.meta rename to Assets/Mapzen/Editor/FoldoutEditor.cs.meta diff --git a/Assets/Editor/LayerStyleEditor.cs b/Assets/Mapzen/Editor/LayerStyleEditor.cs similarity index 99% rename from Assets/Editor/LayerStyleEditor.cs rename to Assets/Mapzen/Editor/LayerStyleEditor.cs index 0e7affc7..a0e98993 100644 --- a/Assets/Editor/LayerStyleEditor.cs +++ b/Assets/Mapzen/Editor/LayerStyleEditor.cs @@ -5,7 +5,7 @@ using UnityEngine; using System.Collections.Generic; -namespace PluginEditor +namespace Mapzen.Editor { [SerializeField] public class LayerStyleEditor : EditorBase diff --git a/Assets/Editor/LayerStyleEditor.cs.meta b/Assets/Mapzen/Editor/LayerStyleEditor.cs.meta similarity index 100% rename from Assets/Editor/LayerStyleEditor.cs.meta rename to Assets/Mapzen/Editor/LayerStyleEditor.cs.meta diff --git a/Assets/Editor/MapzenMapEditor.cs b/Assets/Mapzen/Editor/MapzenMapEditor.cs similarity index 98% rename from Assets/Editor/MapzenMapEditor.cs rename to Assets/Mapzen/Editor/MapzenMapEditor.cs index 76e21589..0982c97c 100644 --- a/Assets/Editor/MapzenMapEditor.cs +++ b/Assets/Mapzen/Editor/MapzenMapEditor.cs @@ -4,10 +4,10 @@ using Mapzen; using UnityEditor; -namespace PluginEditor +namespace Mapzen.Editor { [CustomEditor(typeof(MapzenMap))] - public class MapzenMapEditor : Editor + public class MapzenMapEditor : UnityEditor.Editor { private MapzenMap mapzenMap; private bool showTileDataFoldout = false; diff --git a/Assets/Editor/MapzenMapEditor.cs.meta b/Assets/Mapzen/Editor/MapzenMapEditor.cs.meta similarity index 100% rename from Assets/Editor/MapzenMapEditor.cs.meta rename to Assets/Mapzen/Editor/MapzenMapEditor.cs.meta diff --git a/Assets/Editor/MatcherEditor.cs b/Assets/Mapzen/Editor/MatcherEditor.cs similarity index 99% rename from Assets/Editor/MatcherEditor.cs rename to Assets/Mapzen/Editor/MatcherEditor.cs index 897c9b3b..5c518c94 100644 --- a/Assets/Editor/MatcherEditor.cs +++ b/Assets/Mapzen/Editor/MatcherEditor.cs @@ -7,7 +7,7 @@ using UnityEditor; using UnityEngine; -namespace PluginEditor +namespace Mapzen.Editor { [Serializable] public class MatcherEditor : EditorBase diff --git a/Assets/Editor/MatcherEditor.cs.meta b/Assets/Mapzen/Editor/MatcherEditor.cs.meta similarity index 100% rename from Assets/Editor/MatcherEditor.cs.meta rename to Assets/Mapzen/Editor/MatcherEditor.cs.meta diff --git a/Assets/Editor/StyleEditor.cs b/Assets/Mapzen/Editor/StyleEditor.cs similarity index 99% rename from Assets/Editor/StyleEditor.cs rename to Assets/Mapzen/Editor/StyleEditor.cs index b34c2cf1..c6214415 100644 --- a/Assets/Editor/StyleEditor.cs +++ b/Assets/Mapzen/Editor/StyleEditor.cs @@ -7,7 +7,7 @@ using System.Linq; using System; -namespace PluginEditor +namespace Mapzen.Editor { [Serializable] public class StyleEditor : EditorBase diff --git a/Assets/Editor/StyleEditor.cs.meta b/Assets/Mapzen/Editor/StyleEditor.cs.meta similarity index 100% rename from Assets/Editor/StyleEditor.cs.meta rename to Assets/Mapzen/Editor/StyleEditor.cs.meta