20240422
This commit is contained in:
commit
e0afef912e
1285 files changed
+83219
No files matched your search
@@ -0,0 +1,56 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomPropertyDrawer(typeof(AddMonoBehavioursModifierType))]
|
||||
class AddMonoBehavioursModifierDrawer : PropertyDrawer
|
||||
{
|
||||
const int _offset = 40;
|
||||
MonoScript _monoscript;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
var scriptRect = new Rect(position.x, position.y, position.width, position.height - _offset);
|
||||
var helpRect = new Rect(position.x, position.y + _offset / 2, position.width, _offset);
|
||||
var typeStringProperty = property.FindPropertyRelative("_typeString");
|
||||
var monoscriptProperty = property.FindPropertyRelative("_script");
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
_monoscript = monoscriptProperty.objectReferenceValue as MonoScript;
|
||||
_monoscript = EditorGUI.ObjectField(scriptRect, _monoscript, typeof(MonoScript), false) as MonoScript;
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
var type = _monoscript.GetClass();
|
||||
if (type != null && type.IsSubclassOf(typeof(MonoBehaviour)))
|
||||
{
|
||||
monoscriptProperty.objectReferenceValue = _monoscript;
|
||||
typeStringProperty.stringValue = _monoscript.GetClass().ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
monoscriptProperty.objectReferenceValue = null;
|
||||
typeStringProperty.stringValue = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (monoscriptProperty.objectReferenceValue == null)
|
||||
{
|
||||
EditorGUI.HelpBox(helpRect, "Selected object is not a MonoBehaviour!", MessageType.Error);
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return base.GetPropertyHeight(property, label) + _offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46a3e6ae0815b434c88985c91af9364d
|
||||
timeCreated: 1499902265
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,339 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using System.IO;
|
||||
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
|
||||
class AtlasTemplateGenerator : EditorWindow
|
||||
{
|
||||
[MenuItem("Mapbox/Atlas Template Generator")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
EditorWindow.GetWindow(typeof(AtlasTemplateGenerator));
|
||||
}
|
||||
|
||||
public class PixelRect
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public int xx;
|
||||
public int yy;
|
||||
}
|
||||
|
||||
public string m_saveFileName = "AtlasTemplate";
|
||||
|
||||
public Texture2D m_texture;
|
||||
|
||||
public AtlasInfo m_atlasInfo;
|
||||
|
||||
public Color[] m_colors;
|
||||
|
||||
public int m_textureResolution = 2048;
|
||||
|
||||
public bool m_generateFacadesTemplate = true;
|
||||
public bool m_generateRoofsTemplate = false;
|
||||
|
||||
private int _drawCount;
|
||||
|
||||
private const int _DEFAULT_TEX_SIZE = 2048;
|
||||
private const int _MIN_TEX_SIZE = 512;
|
||||
private const int _MAX_TEX_SIZE = 2048;
|
||||
|
||||
private const float _cellRatioMargin = 0.01f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
CreateTexture();
|
||||
}
|
||||
|
||||
private void CreateTexture()
|
||||
{
|
||||
m_texture = new Texture2D(m_textureResolution, m_textureResolution, TextureFormat.ARGB32, false);
|
||||
m_texture.filterMode = FilterMode.Point;
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.Space(20);
|
||||
|
||||
GUIStyle titleStyle = new GUIStyle(EditorStyles.label);
|
||||
|
||||
titleStyle.fontSize = 32;
|
||||
titleStyle.normal.textColor = Color.white;
|
||||
titleStyle.fontStyle = FontStyle.Bold;
|
||||
|
||||
titleStyle.stretchWidth = true;
|
||||
titleStyle.stretchHeight = true;
|
||||
|
||||
titleStyle.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
EditorGUILayout.LabelField("Mapbox Atlas Template Generator", titleStyle, GUILayout.Height(100));
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical(GUILayout.MinWidth(200), GUILayout.MaxWidth(300));
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
m_atlasInfo = EditorGUILayout.ObjectField("Atlas info:", m_atlasInfo, typeof(AtlasInfo), true) as Mapbox.Unity.MeshGeneration.Data.AtlasInfo;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
m_generateFacadesTemplate = EditorGUILayout.Toggle("Create Facades", m_generateFacadesTemplate);
|
||||
m_generateRoofsTemplate = EditorGUILayout.Toggle("Create Roofs", m_generateRoofsTemplate);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
if (m_atlasInfo != null)
|
||||
{
|
||||
int facadeCount = m_generateFacadesTemplate ? m_atlasInfo.Textures.Count : 0;
|
||||
int roofCount = m_generateRoofsTemplate ? m_atlasInfo.Roofs.Count : 0;
|
||||
|
||||
int textureCount = facadeCount + roofCount;
|
||||
|
||||
m_colors = new Color[textureCount];
|
||||
|
||||
float hueIncrement = (float)1.0f / textureCount;
|
||||
float hue = 0.0f;
|
||||
|
||||
for (int i = 0; i < textureCount; i++)
|
||||
{
|
||||
m_colors[i] = Color.HSVToRGB(hue, 1.0f, 1.0f);
|
||||
hue += hueIncrement;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_colors = new Color[0];
|
||||
CreateTexture();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
m_textureResolution = Mathf.Clamp(EditorGUILayout.IntField("Texture resolution:", m_textureResolution), _MIN_TEX_SIZE, _MAX_TEX_SIZE);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
CreateTexture();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (m_colors != null)
|
||||
{
|
||||
for (int i = 0; i < m_colors.Length; i++)
|
||||
{
|
||||
string colorFieldName = string.Format("Color {0}", i);
|
||||
m_colors[i] = EditorGUILayout.ColorField(colorFieldName, m_colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Generate Template"))
|
||||
{
|
||||
if (m_atlasInfo == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Atlas Template Generator", "Error: No AtlasInfo object selected.", "Ok");
|
||||
return;
|
||||
}
|
||||
if (!m_generateFacadesTemplate && !m_generateRoofsTemplate)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Atlas Template Generator", "Error: Template generation requires Create Facades and/or Create Roofs to be enabled.", "Ok");
|
||||
return;
|
||||
}
|
||||
GenerateTemplate();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (GUILayout.Button("Save to file"))
|
||||
{
|
||||
SaveTextureAsPNG();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUIStyle boxStyle = new GUIStyle();
|
||||
|
||||
boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
|
||||
GUILayout.Box(m_texture, boxStyle, GUILayout.Width(300), GUILayout.Height(300), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.Space(20);
|
||||
}
|
||||
|
||||
private int GetPixelCoorFromAtlasRatio(float ratio)
|
||||
{
|
||||
return (int)(m_textureResolution * ratio);
|
||||
}
|
||||
|
||||
private PixelRect ConvertUVRectToPixelRect(Rect atlasRect)
|
||||
{
|
||||
PixelRect pixelRect = new PixelRect();
|
||||
pixelRect.x = GetPixelCoorFromAtlasRatio(atlasRect.x);
|
||||
pixelRect.y = GetPixelCoorFromAtlasRatio(atlasRect.y);
|
||||
pixelRect.xx = GetPixelCoorFromAtlasRatio(atlasRect.x + atlasRect.width);
|
||||
pixelRect.yy = GetPixelCoorFromAtlasRatio(atlasRect.y + atlasRect.height);
|
||||
return pixelRect;
|
||||
}
|
||||
|
||||
private void DrawRect(PixelRect pr, Color color)
|
||||
{
|
||||
for (int i = pr.x; i < pr.xx; i++)
|
||||
{
|
||||
for (int j = pr.y; j < pr.yy; j++)
|
||||
{
|
||||
m_texture.SetPixel(i, j, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawWatermark(int x, int y)
|
||||
{
|
||||
m_texture.SetPixel(x, y, Color.black);
|
||||
m_texture.SetPixel(x + 3, y, Color.black);
|
||||
m_texture.SetPixel(x, y + 3, Color.black);
|
||||
m_texture.SetPixel(x + 3, y + 3, Color.black);
|
||||
|
||||
m_texture.SetPixel(x + 1, y + 1, Color.black);
|
||||
m_texture.SetPixel(x + 2, y + 1, Color.black);
|
||||
m_texture.SetPixel(x + 1, y + 2, Color.black);
|
||||
m_texture.SetPixel(x + 2, y + 2, Color.black);
|
||||
}
|
||||
|
||||
private void DrawCornerWatermarks(PixelRect pr)
|
||||
{
|
||||
DrawWatermark(pr.x, pr.y);
|
||||
DrawWatermark(pr.xx - 4, pr.y);
|
||||
DrawWatermark(pr.x, pr.yy - 4);
|
||||
DrawWatermark(pr.xx - 4, pr.yy - 4);
|
||||
}
|
||||
|
||||
private void DrawDebugCross(PixelRect pr)
|
||||
{
|
||||
int centerX = (pr.x + pr.xx) / 2;
|
||||
int centerY = (pr.y + pr.yy) / 2;
|
||||
|
||||
m_texture.SetPixel(centerX, centerY, Color.black);
|
||||
|
||||
for (int x = pr.x; x < pr.xx; x++)
|
||||
{
|
||||
m_texture.SetPixel(x, centerY, Color.black);
|
||||
m_texture.SetPixel(x, centerY - 1, Color.black);
|
||||
m_texture.SetPixel(x, centerY + 1, Color.black);
|
||||
}
|
||||
|
||||
for (int y = pr.y; y < pr.yy; y++)
|
||||
{
|
||||
m_texture.SetPixel(centerX, y, Color.black);
|
||||
m_texture.SetPixel(centerX - 1, y, Color.black);
|
||||
m_texture.SetPixel(centerX + 1, y, Color.black);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawAtlasEntityData(List<AtlasEntity> aeList)
|
||||
{
|
||||
for (int i = 0; i < aeList.Count; i++)
|
||||
{
|
||||
AtlasEntity ae = aeList[i];
|
||||
|
||||
Rect baseRect = ae.TextureRect;
|
||||
|
||||
float topRatio = ae.TopSectionRatio * baseRect.height;
|
||||
float bottomRatio = ae.BottomSectionRatio * baseRect.height;
|
||||
float middleRatio = baseRect.height - (topRatio + bottomRatio);
|
||||
|
||||
Rect groundFloorRect = new Rect(baseRect.x, baseRect.y, baseRect.width, bottomRatio);
|
||||
Rect topFloorRect = new Rect(baseRect.x, baseRect.y + baseRect.height - topRatio, baseRect.width, topRatio);
|
||||
|
||||
PixelRect basePixelRect = ConvertUVRectToPixelRect(baseRect);
|
||||
PixelRect groundFloorPixelRect = ConvertUVRectToPixelRect(groundFloorRect);
|
||||
PixelRect topFloorPixelRect = ConvertUVRectToPixelRect(topFloorRect);
|
||||
|
||||
Color color = m_colors[_drawCount];
|
||||
Color colorLight = (color + Color.white) / 2;
|
||||
Color colorDark = (color + Color.black) / 2;
|
||||
|
||||
DrawRect(basePixelRect, color);
|
||||
DrawRect(groundFloorPixelRect, colorLight);
|
||||
DrawRect(topFloorPixelRect, colorDark);
|
||||
|
||||
DrawDebugCross(groundFloorPixelRect);
|
||||
DrawDebugCross(topFloorPixelRect);
|
||||
|
||||
int numColumns = (int)ae.ColumnCount;
|
||||
int numMidFloors = ae.MidFloorCount;
|
||||
|
||||
float colWidth = baseRect.width / numColumns;
|
||||
float floorHeight = middleRatio / numMidFloors;
|
||||
|
||||
float midFloorBase = baseRect.y + bottomRatio;
|
||||
|
||||
float mrgn = _cellRatioMargin;
|
||||
float halfMrgn = mrgn / 2;
|
||||
|
||||
for (int j = 0; j < numMidFloors; j++)
|
||||
{
|
||||
float floorStart = midFloorBase + (floorHeight * j);
|
||||
|
||||
for (int k = 0; k < numColumns; k++)
|
||||
{
|
||||
float columnStart = baseRect.x + (colWidth * k);
|
||||
|
||||
Rect cellRect = new Rect(columnStart + halfMrgn, floorStart + halfMrgn, colWidth - mrgn, floorHeight - mrgn);
|
||||
PixelRect cellPixelRect = ConvertUVRectToPixelRect(cellRect);
|
||||
|
||||
DrawRect(cellPixelRect, Color.white);
|
||||
DrawDebugCross(cellPixelRect);
|
||||
}
|
||||
}
|
||||
DrawCornerWatermarks(groundFloorPixelRect);
|
||||
DrawCornerWatermarks(topFloorPixelRect);
|
||||
_drawCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateTemplate()
|
||||
{
|
||||
_drawCount = 0;
|
||||
if (m_generateFacadesTemplate)
|
||||
{
|
||||
DrawAtlasEntityData(m_atlasInfo.Textures);
|
||||
}
|
||||
if (m_generateRoofsTemplate)
|
||||
{
|
||||
DrawAtlasEntityData(m_atlasInfo.Roofs);
|
||||
}
|
||||
m_texture.Apply();
|
||||
}
|
||||
|
||||
public void SaveTextureAsPNG()
|
||||
{
|
||||
var path = EditorUtility.SaveFilePanel("Save texture as PNG", "Assets", "AtlasTemplate.png", "png");
|
||||
if (path.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
byte[] pngData = m_texture.EncodeToPNG();
|
||||
if (pngData != null)
|
||||
{
|
||||
File.WriteAllBytes(path, pngData);
|
||||
Debug.Log(pngData.Length / 1024 + "Kb was saved as: " + path);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc814d64f35ad4f1bbce68318166b67e
|
||||
timeCreated: 1520544854
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28d2b990a838d44e1b28195d8465d645
|
||||
folderAsset: yes
|
||||
timeCreated: 1495491662
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
#if UNITY_IOS
|
||||
namespace Mapbox.Editor.Build
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Globalization;
|
||||
|
||||
public class Mapbox_iOS_build : MonoBehaviour
|
||||
{
|
||||
[PostProcessBuild]
|
||||
public static void AppendBuildProperty(BuildTarget buildTarget, string pathToBuiltProject)
|
||||
{
|
||||
if (buildTarget == BuildTarget.iOS)
|
||||
{
|
||||
PBXProject proj = new PBXProject();
|
||||
// path to pbxproj file
|
||||
string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
|
||||
var file = File.ReadAllText(projPath);
|
||||
proj.ReadFromString(file);
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
string target = proj.GetUnityFrameworkTargetGuid();
|
||||
#else
|
||||
string target = proj.TargetGuidByName("Unity-iPhone");
|
||||
#endif
|
||||
|
||||
var defaultIncludePath = "Mapbox/Core/Plugins/iOS/MapboxMobileEvents/include";
|
||||
var includePaths = Directory.GetDirectories(Application.dataPath, "include", SearchOption.AllDirectories);
|
||||
var includePath = includePaths
|
||||
.Select(path => Regex.Replace(path, Application.dataPath + "/", ""))
|
||||
.Where(path => path.EndsWith(defaultIncludePath, true, CultureInfo.InvariantCulture))
|
||||
.DefaultIfEmpty(defaultIncludePath)
|
||||
.First();
|
||||
|
||||
proj.AddBuildProperty(target, "HEADER_SEARCH_PATHS", "$(SRCROOT)/Libraries/" + includePath);
|
||||
proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC -lz");
|
||||
|
||||
File.WriteAllText(projPath, proj.WriteToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ab2c6d9be5e048179de762cb9bf3cd1
|
||||
timeCreated: 1495323965
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public class ClearFileCache : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
[MenuItem("Mapbox/Clear File Cache")]
|
||||
public static void ClearAllCachFiles()
|
||||
{
|
||||
Unity.MapboxAccess.Instance.ClearAllCacheFiles();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 588d3a5d675244fc1a1d927b580b99a3
|
||||
timeCreated: 1497883479
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,289 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
|
||||
/// <summary>
|
||||
/// EditorHelper class provides methods for working with serialzed properties.
|
||||
/// Methods in this class are based on the spacepuppy-unity-framework, available at the url below.
|
||||
/// https://github.com/lordofduct/spacepuppy-unity-framework/tree/d8d592e212b26cad53264421d22c3d26c6799923/SpacepuppyBaseEditor.
|
||||
/// </summary>
|
||||
public static class EditorHelper
|
||||
{
|
||||
|
||||
[UnityEditor.Callbacks.DidReloadScripts]
|
||||
private static void OnScriptsReloaded()
|
||||
{
|
||||
if (Application.isEditor)
|
||||
{
|
||||
AbstractMap abstractMap = UnityEngine.Object.FindObjectOfType<AbstractMap>();
|
||||
|
||||
if (abstractMap == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UnityTile[] unityTiles = abstractMap.GetComponentsInChildren<UnityTile>();
|
||||
|
||||
for (int i = 0; i < unityTiles.Length; i++)
|
||||
{
|
||||
UnityEngine.Object.DestroyImmediate(unityTiles[i].gameObject);
|
||||
}
|
||||
|
||||
abstractMap.DestroyChildObjects();
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
abstractMap.ResetMap();
|
||||
return;
|
||||
}
|
||||
if (abstractMap.IsEditorPreviewEnabled == true)
|
||||
{
|
||||
if (EditorApplication.isPlayingOrWillChangePlaymode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
abstractMap.DisableEditorPreview();
|
||||
abstractMap.EnableEditorPreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void CheckForModifiedProperty<T>(SerializedProperty property, T targetObject, bool forceHasChanged = false)
|
||||
{
|
||||
MapboxDataProperty targetObjectAsDataProperty = GetMapboxDataPropertyObject(targetObject);
|
||||
if (targetObjectAsDataProperty != null)
|
||||
{
|
||||
targetObjectAsDataProperty.HasChanged = forceHasChanged || property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckForModifiedProperty(SerializedProperty property, bool forceHasChanged = false)
|
||||
{
|
||||
CheckForModifiedProperty(property, GetTargetObjectOfProperty(property), forceHasChanged);
|
||||
}
|
||||
|
||||
public static MapboxDataProperty GetMapboxDataPropertyObject<T>(T targetObject)
|
||||
{
|
||||
return targetObject as MapboxDataProperty;
|
||||
}
|
||||
|
||||
public static bool DidModifyProperty<T>(SerializedProperty property, T targetObject)
|
||||
{
|
||||
MapboxDataProperty targetObjectAsDataProperty = targetObject as MapboxDataProperty;
|
||||
return (property.serializedObject.ApplyModifiedProperties() && targetObjectAsDataProperty != null);
|
||||
}
|
||||
|
||||
public static bool DidModifyProperty(SerializedProperty property)
|
||||
{
|
||||
return DidModifyProperty(property, GetTargetObjectOfProperty(property));
|
||||
}
|
||||
|
||||
public static IEnumerable<SerializedProperty> GetChildren(this SerializedProperty property)
|
||||
{
|
||||
property = property.Copy();
|
||||
var nextElement = property.Copy();
|
||||
bool hasNextElement = nextElement.NextVisible(false);
|
||||
if (!hasNextElement)
|
||||
{
|
||||
nextElement = null;
|
||||
}
|
||||
|
||||
property.NextVisible(true);
|
||||
while (true)
|
||||
{
|
||||
if ((SerializedProperty.EqualContents(property, nextElement)))
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return property;
|
||||
|
||||
bool hasNext = property.NextVisible(false);
|
||||
if (!hasNext)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static System.Type GetTargetType(this SerializedObject obj)
|
||||
{
|
||||
if (obj == null) return null;
|
||||
|
||||
if (obj.isEditingMultipleObjects)
|
||||
{
|
||||
var c = obj.targetObjects[0];
|
||||
return c.GetType();
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj.targetObject.GetType();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the object the property represents.
|
||||
/// </summary>
|
||||
/// <param name="prop"></param>
|
||||
/// <returns></returns>
|
||||
public static object GetTargetObjectOfProperty(SerializedProperty prop)
|
||||
{
|
||||
var path = prop.propertyPath.Replace(".Array.data[", "[");
|
||||
object obj = prop.serializedObject.targetObject;
|
||||
var elements = path.Split('.');
|
||||
foreach (var element in elements)
|
||||
{
|
||||
if (element.Contains("["))
|
||||
{
|
||||
var elementName = element.Substring(0, element.IndexOf("[", StringComparison.CurrentCulture));
|
||||
var index = System.Convert.ToInt32(element.Substring(element.IndexOf("[", StringComparison.CurrentCulture)).Replace("[", "").Replace("]", ""));
|
||||
obj = GetValue_Imp(obj, elementName, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = GetValue_Imp(obj, element);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static void SetTargetObjectOfProperty(SerializedProperty prop, object value)
|
||||
{
|
||||
var path = prop.propertyPath.Replace(".Array.data[", "[");
|
||||
object obj = prop.serializedObject.targetObject;
|
||||
var elements = path.Split('.');
|
||||
foreach (var element in elements.Take(elements.Length - 1))
|
||||
{
|
||||
if (element.Contains("["))
|
||||
{
|
||||
var elementName = element.Substring(0, element.IndexOf("[", StringComparison.CurrentCulture));
|
||||
var index = System.Convert.ToInt32(element.Substring(element.IndexOf("[", StringComparison.CurrentCulture)).Replace("[", "").Replace("]", ""));
|
||||
obj = GetValue_Imp(obj, elementName, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = GetValue_Imp(obj, element);
|
||||
}
|
||||
}
|
||||
|
||||
if (System.Object.ReferenceEquals(obj, null)) return;
|
||||
|
||||
try
|
||||
{
|
||||
var element = elements.Last();
|
||||
|
||||
if (element.Contains("["))
|
||||
{
|
||||
var tp = obj.GetType();
|
||||
var elementName = element.Substring(0, element.IndexOf("[", StringComparison.CurrentCulture));
|
||||
var index = System.Convert.ToInt32(element.Substring(element.IndexOf("[", StringComparison.CurrentCulture)).Replace("[", "").Replace("]", ""));
|
||||
var field = tp.GetField(elementName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var arr = field.GetValue(obj) as System.Collections.IList;
|
||||
arr[index] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
var tp = obj.GetType();
|
||||
var field = tp.GetField(element, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
{
|
||||
field.SetValue(obj, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the object that the property is a member of
|
||||
/// </summary>
|
||||
/// <param name="prop"></param>
|
||||
/// <returns></returns>
|
||||
public static object GetTargetObjectWithProperty(SerializedProperty prop)
|
||||
{
|
||||
var path = prop.propertyPath.Replace(".Array.data[", "[");
|
||||
object obj = prop.serializedObject.targetObject;
|
||||
var elements = path.Split('.');
|
||||
foreach (var element in elements.Take(elements.Length - 1))
|
||||
{
|
||||
if (element.Contains("["))
|
||||
{
|
||||
var elementName = element.Substring(0, element.IndexOf("[", StringComparison.CurrentCulture));
|
||||
var index = System.Convert.ToInt32(element.Substring(element.IndexOf("[", StringComparison.CurrentCulture)).Replace("[", "").Replace("]", ""));
|
||||
obj = GetValue_Imp(obj, elementName, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = GetValue_Imp(obj, element);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static object GetValue_Imp(object source, string name)
|
||||
{
|
||||
if (source == null)
|
||||
return null;
|
||||
var type = source.GetType();
|
||||
|
||||
while (type != null)
|
||||
{
|
||||
var f = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
if (f != null)
|
||||
return f.GetValue(source);
|
||||
|
||||
var p = type.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
|
||||
if (p != null)
|
||||
return p.GetValue(source, null);
|
||||
|
||||
type = type.BaseType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static object GetValue_Imp(object source, string name, int index)
|
||||
{
|
||||
var enumerable = GetValue_Imp(source, name) as System.Collections.IEnumerable;
|
||||
if (enumerable == null) return null;
|
||||
var enm = enumerable.GetEnumerator();
|
||||
|
||||
for (int i = 0; i <= index; i++)
|
||||
{
|
||||
if (!enm.MoveNext()) return null;
|
||||
}
|
||||
return enm.Current;
|
||||
}
|
||||
|
||||
public static int GetChildPropertyCount(SerializedProperty property, bool includeGrandChildren = false)
|
||||
{
|
||||
var pstart = property.Copy();
|
||||
var pend = property.GetEndProperty();
|
||||
int cnt = 0;
|
||||
|
||||
pstart.Next(true);
|
||||
while (!SerializedProperty.EqualContents(pstart, pend))
|
||||
{
|
||||
cnt++;
|
||||
pstart.Next(includeGrandChildren);
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7390a064088424109a975353ccf6e504
|
||||
timeCreated: 1536113196
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Factories;
|
||||
|
||||
[CustomEditor(typeof(AbstractTileFactory))]
|
||||
public class FactoryEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a71b284f467d4de4584d5f813a75c7c0
|
||||
timeCreated: 1490923136
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
|
||||
[CustomEditor(typeof(FeatureBehaviour))]
|
||||
public class FeatureBehaviourEditor : Editor
|
||||
{
|
||||
FeatureBehaviour _beh;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
_beh = (FeatureBehaviour)target;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
if (GUILayout.Button("Show Properties"))
|
||||
{
|
||||
_beh.ShowDebugData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54536e5537a66a842818be9fc7a7d6f3
|
||||
timeCreated: 1499870444
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
internal class FeatureSectionMultiColumnHeader : MultiColumnHeader
|
||||
{
|
||||
Mode m_Mode;
|
||||
|
||||
public enum Mode
|
||||
{
|
||||
LargeHeader,
|
||||
DefaultHeader,
|
||||
MinimumHeaderWithoutSorting
|
||||
}
|
||||
|
||||
public FeatureSectionMultiColumnHeader(MultiColumnHeaderState state)
|
||||
: base(state)
|
||||
{
|
||||
mode = Mode.DefaultHeader;
|
||||
}
|
||||
|
||||
public Mode mode
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Mode;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Mode = value;
|
||||
switch (m_Mode)
|
||||
{
|
||||
case Mode.LargeHeader:
|
||||
canSort = true;
|
||||
height = 37f;
|
||||
break;
|
||||
case Mode.DefaultHeader:
|
||||
canSort = true;
|
||||
height = DefaultGUI.defaultHeight;
|
||||
break;
|
||||
case Mode.MinimumHeaderWithoutSorting:
|
||||
canSort = false;
|
||||
height = DefaultGUI.minimumHeight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ColumnHeaderGUI(MultiColumnHeaderState.Column column, Rect headerRect, int columnIndex)
|
||||
{
|
||||
// Default column header gui
|
||||
base.ColumnHeaderGUI(column, headerRect, columnIndex);
|
||||
|
||||
// Add additional info for large header
|
||||
if (mode == Mode.LargeHeader)
|
||||
{
|
||||
// Show example overlay stuff on some of the columns
|
||||
if (columnIndex > 2)
|
||||
{
|
||||
headerRect.xMax -= 3f;
|
||||
var oldAlignment = EditorStyles.largeLabel.alignment;
|
||||
EditorStyles.largeLabel.alignment = TextAnchor.UpperRight;
|
||||
GUI.Label(headerRect, 36 + columnIndex + "%", EditorStyles.largeLabel);
|
||||
EditorStyles.largeLabel.alignment = oldAlignment;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07bf8462a630d4aad95ad6e2fb8b2923
|
||||
timeCreated: 1530231284
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,194 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
internal class FeatureSubLayerTreeView : TreeViewWithTreeModel<FeatureTreeElement>
|
||||
{
|
||||
public SerializedProperty Layers;
|
||||
private float kToggleWidth = 18f;
|
||||
public int uniqueId;
|
||||
public static int uniqueIdPoI = 1000;
|
||||
public static int uniqueIdFeature = 3000;
|
||||
public int maxElementsAdded = 0;
|
||||
|
||||
public bool hasChanged = false;
|
||||
|
||||
const float kRowHeights = 15f;
|
||||
const float nameOffset = 15f;
|
||||
|
||||
MultiColumnHeaderState m_MultiColumnHeaderState;
|
||||
private GUIStyle columnStyle = new GUIStyle()
|
||||
{
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
normal = new GUIStyleState() { textColor = Color.white }
|
||||
};
|
||||
|
||||
public FeatureSubLayerTreeView(TreeViewState state, MultiColumnHeader multicolumnHeader, TreeModel<FeatureTreeElement> model, int uniqueIdentifier = 3000) : base(state, multicolumnHeader, model)
|
||||
{
|
||||
showAlternatingRowBackgrounds = true;
|
||||
showBorder = true;
|
||||
customFoldoutYOffset = (kRowHeights - EditorGUIUtility.singleLineHeight) * 0.5f; // center foldout in the row since we also center content. See RowGUI
|
||||
extraSpaceBeforeIconAndLabel = kToggleWidth;
|
||||
uniqueId = uniqueIdentifier;
|
||||
Reload();
|
||||
}
|
||||
|
||||
protected override bool CanRename(TreeViewItem item)
|
||||
{
|
||||
// Only allow rename if we can show the rename overlay with a certain width (label might be clipped by other columns)
|
||||
Rect renameRect = GetRenameRect(treeViewRect, 0, item);
|
||||
return renameRect.width > 30;
|
||||
}
|
||||
|
||||
protected override void RenameEnded(RenameEndedArgs args)
|
||||
{
|
||||
if (Layers == null || Layers.arraySize == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.acceptedRename)
|
||||
{
|
||||
var element = treeModel.Find(args.itemID);
|
||||
element.name = string.IsNullOrEmpty(args.newName.Trim()) ? args.originalName : args.newName;
|
||||
element.Name = string.IsNullOrEmpty(args.newName.Trim()) ? args.originalName : args.newName;
|
||||
var layer = Layers.GetArrayElementAtIndex(args.itemID - uniqueId);
|
||||
layer.FindPropertyRelative("coreOptions.sublayerName").stringValue = element.name;
|
||||
Reload();
|
||||
}
|
||||
}
|
||||
|
||||
protected override Rect GetRenameRect(Rect rowRect, int row, TreeViewItem item)
|
||||
{
|
||||
Rect cellRect = GetCellRectForTreeFoldouts(rowRect);
|
||||
cellRect.xMin = nameOffset;
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
return base.GetRenameRect(cellRect, row, item);
|
||||
}
|
||||
|
||||
public void RemoveItemFromTree(int id)
|
||||
{
|
||||
treeModel.RemoveElements(new List<int>() { id });
|
||||
}
|
||||
|
||||
public void AddElementToTree(SerializedProperty subLayer)
|
||||
{
|
||||
var name = subLayer.FindPropertyRelative("coreOptions.sublayerName").stringValue;
|
||||
var id = Layers.arraySize - 1 + uniqueId;
|
||||
|
||||
if (treeModel.Find(id) != null)
|
||||
{
|
||||
Debug.Log(" found one. exiting");
|
||||
return;
|
||||
}
|
||||
|
||||
var type = ((PresetFeatureType)subLayer.FindPropertyRelative("presetFeatureType").enumValueIndex).ToString();
|
||||
FeatureTreeElement element = new FeatureTreeElement(name, 0, id);
|
||||
element.Name = name;
|
||||
element.Type = type;
|
||||
treeModel.AddElement(element, treeModel.root, treeModel.numberOfDataElements - 1);
|
||||
}
|
||||
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
var rowItem = (TreeViewItem<FeatureTreeElement>)args.item;
|
||||
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
|
||||
{
|
||||
CellGUI(args.GetCellRect(i), rowItem, (FeatureSubLayerColumns)args.GetColumn(i), ref args);
|
||||
}
|
||||
}
|
||||
|
||||
void CellGUI(Rect cellRect, TreeViewItem<FeatureTreeElement> item, FeatureSubLayerColumns column, ref RowGUIArgs args)
|
||||
{
|
||||
// Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
|
||||
if (Layers == null || Layers.arraySize == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Layers.arraySize <= args.item.id - uniqueId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var layer = Layers.GetArrayElementAtIndex(args.item.id - uniqueId);
|
||||
CenterRectUsingSingleLineHeight(ref cellRect);
|
||||
if (column == FeatureSubLayerColumns.Name)
|
||||
{
|
||||
Rect toggleRect = cellRect;
|
||||
toggleRect.x += GetContentIndent(item);
|
||||
toggleRect.width = kToggleWidth;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
item.data.isActive = layer.FindPropertyRelative("coreOptions.isActive").boolValue;
|
||||
if (toggleRect.xMax < cellRect.xMax)
|
||||
{
|
||||
item.data.isActive = EditorGUI.Toggle(toggleRect, item.data.isActive); // hide when outside cell rect
|
||||
}
|
||||
layer.FindPropertyRelative("coreOptions.isActive").boolValue = item.data.isActive;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
VectorSubLayerProperties vectorSubLayerProperties = (VectorSubLayerProperties)EditorHelper.GetTargetObjectOfProperty(layer);
|
||||
EditorHelper.CheckForModifiedProperty(layer, vectorSubLayerProperties.coreOptions);
|
||||
}
|
||||
|
||||
cellRect.xMin += nameOffset; // Adding some gap between the checkbox and the name
|
||||
args.rowRect = cellRect;
|
||||
|
||||
layer.FindPropertyRelative("coreOptions.sublayerName").stringValue = item.data.Name;
|
||||
//This draws the name property
|
||||
base.RowGUI(args);
|
||||
}
|
||||
if (column == FeatureSubLayerColumns.Type)
|
||||
{
|
||||
cellRect.xMin += 15f; // Adding some gap between the checkbox and the name
|
||||
|
||||
var typeString = ((PresetFeatureType)layer.FindPropertyRelative("presetFeatureType").intValue).ToString();
|
||||
item.data.Type = typeString;
|
||||
EditorGUI.LabelField(cellRect, item.data.Type, columnStyle);
|
||||
}
|
||||
}
|
||||
|
||||
// All columns
|
||||
enum FeatureSubLayerColumns
|
||||
{
|
||||
Name,
|
||||
Type
|
||||
}
|
||||
|
||||
public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState()
|
||||
{
|
||||
var columns = new[]
|
||||
{
|
||||
//Name column
|
||||
new MultiColumnHeaderState.Column
|
||||
{
|
||||
headerContent = new GUIContent("Name"),
|
||||
contextMenuText = "Name",
|
||||
headerTextAlignment = TextAlignment.Center,
|
||||
autoResize = true,
|
||||
canSort = false,
|
||||
allowToggleVisibility = false,
|
||||
},
|
||||
|
||||
//Type column
|
||||
new MultiColumnHeaderState.Column
|
||||
{
|
||||
headerContent = new GUIContent("Type"),
|
||||
contextMenuText = "Type",
|
||||
headerTextAlignment = TextAlignment.Center,
|
||||
autoResize = true,
|
||||
canSort = false,
|
||||
allowToggleVisibility = false
|
||||
}
|
||||
};
|
||||
|
||||
var state = new MultiColumnHeaderState(columns);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6959c2320c56c4d89be4ff0e9d2a1b73
|
||||
timeCreated: 1525818947
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
[Serializable]
|
||||
public class FeatureTreeElement : TreeElement
|
||||
{
|
||||
public string Name;
|
||||
public string Type;
|
||||
public bool isActive;
|
||||
|
||||
public FeatureTreeElement(string name, int depth, int id) : base(name, depth, id)
|
||||
{
|
||||
isActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5ff51a6bc84040388ff12a051e5a758
|
||||
timeCreated: 1530231284
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.Utilities;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
/// <summary>
|
||||
/// Custom property drawer for geocodes <para/>
|
||||
/// Includes a search window to enable search of Lat/Lon via geocoder.
|
||||
/// Requires a Mapbox token be set for the project
|
||||
/// </summary>
|
||||
[CustomPropertyDrawer(typeof(GeocodeAttribute))]
|
||||
public class GeocodeAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
const string searchButtonContent = "Search";
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
float buttonWidth = EditorGUIUtility.singleLineHeight * 4;
|
||||
|
||||
Rect fieldRect = new Rect(position.x, position.y, position.width - buttonWidth, EditorGUIUtility.singleLineHeight);
|
||||
Rect buttonRect = new Rect(position.x + position.width - buttonWidth, position.y, buttonWidth, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.PropertyField(fieldRect, property);
|
||||
|
||||
if (GUI.Button(buttonRect, searchButtonContent))
|
||||
{
|
||||
object objectToUpdate = EditorHelper.GetTargetObjectWithProperty(property);
|
||||
GeocodeAttributeSearchWindow.Open(property, objectToUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 860c0aa37e7b91f49be4dbfdeb25951f
|
||||
timeCreated: 1484134996
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,184 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Geocoding;
|
||||
using Mapbox.Unity;
|
||||
using System.Globalization;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Editor;
|
||||
|
||||
public class GeocodeAttributeSearchWindow : EditorWindow
|
||||
{
|
||||
SerializedProperty _coordinateProperty;
|
||||
object _objectToUpdate;
|
||||
|
||||
private bool _updateAbstractMap;
|
||||
|
||||
string _searchInput = "";
|
||||
|
||||
ForwardGeocodeResource _resource;
|
||||
|
||||
List<Feature> _features;
|
||||
|
||||
System.Action<string> _callback;
|
||||
|
||||
const string searchFieldName = "searchField";
|
||||
const float width = 320f;
|
||||
const float height = 300f;
|
||||
|
||||
bool _isSearching = false;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_resource = new ForwardGeocodeResource("");
|
||||
EditorApplication.playModeStateChanged += OnModeChanged;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
EditorApplication.playModeStateChanged -= OnModeChanged;
|
||||
}
|
||||
|
||||
bool hasSetFocus = false;
|
||||
|
||||
public static void Open(SerializedProperty property, object objectToUpdate = null)
|
||||
{
|
||||
GeocodeAttributeSearchWindow window = EditorWindow.GetWindow<GeocodeAttributeSearchWindow>(true, "Search for location");
|
||||
|
||||
window._coordinateProperty = property;
|
||||
if (objectToUpdate != null)
|
||||
{
|
||||
window._objectToUpdate = objectToUpdate;
|
||||
}
|
||||
|
||||
Event e = Event.current;
|
||||
Vector2 mousePos = GUIUtility.GUIToScreenPoint(e.mousePosition);
|
||||
|
||||
window.position = new Rect(mousePos.x - width, mousePos.y, width, height);
|
||||
}
|
||||
|
||||
void OnModeChanged(PlayModeStateChange state)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Search for a location");
|
||||
|
||||
string oldSearchInput = _searchInput;
|
||||
|
||||
GUI.SetNextControlName(searchFieldName);
|
||||
_searchInput = GUILayout.TextField(_searchInput);
|
||||
|
||||
if (_searchInput.Length == 0)
|
||||
{
|
||||
GUILayout.Label("Type in a location to find it's latitude and longtitude");
|
||||
}
|
||||
else
|
||||
{
|
||||
bool changed = oldSearchInput != _searchInput;
|
||||
if (changed)
|
||||
{
|
||||
HandleUserInput(_searchInput);
|
||||
}
|
||||
|
||||
if (_features.Count > 0)
|
||||
{
|
||||
GUILayout.Label("Results:");
|
||||
for (int i = 0; i < _features.Count; i++)
|
||||
{
|
||||
Feature feature = _features[i];
|
||||
string coordinates = feature.Center.x.ToString(CultureInfo.InvariantCulture) + ", " +
|
||||
feature.Center.y.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
//abreviated coords for display in the UI
|
||||
string truncatedCoordinates = feature.Center.x.ToString("F2", CultureInfo.InvariantCulture) + ", " +
|
||||
feature.Center.y.ToString("F2", CultureInfo.InvariantCulture);
|
||||
|
||||
//split feature name and add elements until the maxButtonContentLenght is exceeded
|
||||
string[] featureNameSplit = feature.PlaceName.Split(',');
|
||||
string buttonContent = "";
|
||||
int maxButtonContentLength = 30;
|
||||
for (int j = 0; j < featureNameSplit.Length; j++)
|
||||
{
|
||||
if(buttonContent.Length + featureNameSplit[j].Length < maxButtonContentLength)
|
||||
{
|
||||
if(String.IsNullOrEmpty(buttonContent))
|
||||
{
|
||||
buttonContent = featureNameSplit[j];
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonContent = buttonContent + "," + featureNameSplit[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (buttonContent.Length < maxButtonContentLength + 15)
|
||||
{
|
||||
buttonContent = buttonContent + "," + " (" + truncatedCoordinates + ")";
|
||||
}
|
||||
|
||||
|
||||
if (GUILayout.Button(buttonContent))
|
||||
{
|
||||
_coordinateProperty.stringValue = coordinates;
|
||||
_coordinateProperty.serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(_coordinateProperty.serializedObject.targetObject);
|
||||
|
||||
if(_objectToUpdate != null)
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(_coordinateProperty, _objectToUpdate, true);
|
||||
}
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isSearching)
|
||||
GUILayout.Label("Searching...");
|
||||
else
|
||||
GUILayout.Label("No search results");
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasSetFocus)
|
||||
{
|
||||
GUI.FocusControl(searchFieldName);
|
||||
hasSetFocus = true;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleUserInput(string searchString)
|
||||
{
|
||||
_features = new List<Feature>();
|
||||
_isSearching = true;
|
||||
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
_resource.Query = searchString;
|
||||
MapboxAccess.Instance.Geocoder.Geocode(_resource, HandleGeocoderResponse);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleGeocoderResponse(ForwardGeocodeResponse res)
|
||||
{
|
||||
//null if no internet connection
|
||||
if (res != null)
|
||||
{
|
||||
//null if invalid token
|
||||
if (res.Features != null)
|
||||
{
|
||||
_features = res.Features;
|
||||
}
|
||||
}
|
||||
_isSearching = false;
|
||||
this.Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d99190dd95ea8a245ba1f7c8c3084d0a
|
||||
timeCreated: 1484136312
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
|
||||
[CustomEditor(typeof(LayerModifier))]
|
||||
public class LayerModifierEditor : Editor
|
||||
{
|
||||
public SerializedProperty layerId_Prop;
|
||||
private MonoScript script;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
layerId_Prop = serializedObject.FindProperty("_layerId");
|
||||
|
||||
script = MonoScript.FromScriptableObject((LayerModifier)target);
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
GUI.enabled = false;
|
||||
script = EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false) as MonoScript;
|
||||
GUI.enabled = true;
|
||||
|
||||
layerId_Prop.intValue = EditorGUILayout.LayerField("Layer", layerId_Prop.intValue);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae3383f13b58e544ba5c12293fff5957
|
||||
timeCreated: 1494349684
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Factories;
|
||||
|
||||
[CustomEditor(typeof(MapImageFactory))]
|
||||
public class MapImageFactoryEditor : FactoryEditor
|
||||
{
|
||||
public SerializedProperty layerProperties;
|
||||
private MonoScript script;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
layerProperties = serializedObject.FindProperty("_properties");
|
||||
script = MonoScript.FromScriptableObject((MapImageFactory)target);
|
||||
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
GUI.enabled = false;
|
||||
script = EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false) as MonoScript;
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.PropertyField(layerProperties);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26b414693cf1ad341bd50344ab4198f8
|
||||
timeCreated: 1490923136
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,370 @@
|
||||
using System;
|
||||
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Platform.TilesetTileJSON;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
|
||||
[CustomEditor(typeof(AbstractMap))]
|
||||
[CanEditMultipleObjects]
|
||||
public class MapManagerEditor : Editor
|
||||
{
|
||||
private string objectId = "";
|
||||
private Color previewButtonColor = new Color(0.7f, 1.0f, 0.7f);
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to show general section <see cref="T:Mapbox.Editor.MapManagerEditor"/>.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> then show general section; otherwise hide, <c>false</c>.</value>
|
||||
bool ShowGeneral
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showGeneral");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "MapManagerEditor_showGeneral", value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets a value to show or hide Image section<see cref="T:Mapbox.Editor.MapManagerEditor"/>.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if show image; otherwise, <c>false</c>.</value>
|
||||
bool ShowImage
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showImage");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "MapManagerEditor_showImage", value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets a value to show or hide Terrain section <see cref="T:Mapbox.Editor.MapManagerEditor"/>
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if show terrain; otherwise, <c>false</c>.</value>
|
||||
bool ShowTerrain
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showTerrain");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "MapManagerEditor_showTerrain", value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value to show or hide Map Layers section <see cref="T:Mapbox.Editor.MapManagerEditor"/> show features.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if show features; otherwise, <c>false</c>.</value>
|
||||
bool ShowMapLayers
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showMapLayers");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "MapManagerEditor_showMapLayers", value);
|
||||
}
|
||||
}
|
||||
|
||||
bool ShowPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showPosition");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "MapManagerEditor_showPosition", value);
|
||||
}
|
||||
}
|
||||
|
||||
private GUIContent tilesetIdGui = new GUIContent
|
||||
{
|
||||
text = "Tileset Id",
|
||||
tooltip = "Id of the tileset."
|
||||
};
|
||||
|
||||
bool _isGUIContentSet = false;
|
||||
GUIContent[] _sourceTypeContent;
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
VectorLayerPropertiesDrawer _vectorLayerDrawer = new VectorLayerPropertiesDrawer();
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
objectId = serializedObject.targetObject.GetInstanceID().ToString();
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
var previewOptions = serializedObject.FindProperty("_previewOptions");
|
||||
var prevProp = previewOptions.FindPropertyRelative("isPreviewEnabled");
|
||||
var prev = prevProp.boolValue;
|
||||
|
||||
Color guiColor = GUI.color;
|
||||
GUI.color = (prev) ? previewButtonColor : guiColor;
|
||||
|
||||
GUIStyle style = new GUIStyle("Button");
|
||||
style.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
prevProp.boolValue = GUILayout.Toggle(prevProp.boolValue, "Enable Preview", style);
|
||||
GUI.color = guiColor;
|
||||
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
||||
}
|
||||
|
||||
ShowGeneral = EditorGUILayout.Foldout(ShowGeneral, new GUIContent { text = "GENERAL", tooltip = "Options related to map data" });
|
||||
|
||||
if (ShowGeneral)
|
||||
{
|
||||
DrawMapOptions(serializedObject);
|
||||
}
|
||||
ShowSepartor();
|
||||
|
||||
ShowImage = EditorGUILayout.Foldout(ShowImage, "IMAGE");
|
||||
if (ShowImage)
|
||||
{
|
||||
GUILayout.Space(-1.5f * _lineHeight);
|
||||
ShowSection(serializedObject.FindProperty("_imagery"), "_layerProperty");
|
||||
}
|
||||
|
||||
ShowSepartor();
|
||||
|
||||
ShowTerrain = EditorGUILayout.Foldout(ShowTerrain, "TERRAIN");
|
||||
if (ShowTerrain)
|
||||
{
|
||||
GUILayout.Space(-1.5f * _lineHeight);
|
||||
ShowSection(serializedObject.FindProperty("_terrain"), "_layerProperty");
|
||||
}
|
||||
|
||||
ShowSepartor();
|
||||
|
||||
ShowMapLayers = EditorGUILayout.Foldout(ShowMapLayers, "MAP LAYERS");
|
||||
if (ShowMapLayers)
|
||||
{
|
||||
DrawMapLayerOptions();
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
var vectorDataProperty = serializedObject.FindProperty("_vectorData");
|
||||
var layerProperty = vectorDataProperty.FindPropertyRelative("_layerProperty");
|
||||
_vectorLayerDrawer.PostProcessLayerProperties(layerProperty);
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
if (prevProp.boolValue && !prev)
|
||||
{
|
||||
((AbstractMap)serializedObject.targetObject).EnableEditorPreview();
|
||||
}
|
||||
else if (prev && !prevProp.boolValue)
|
||||
{
|
||||
((AbstractMap)serializedObject.targetObject).DisableEditorPreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShowSection(SerializedProperty property, string propertyName)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative(propertyName));
|
||||
}
|
||||
|
||||
void ShowSepartor()
|
||||
{
|
||||
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
void DrawMapOptions(SerializedObject mapObject)
|
||||
{
|
||||
var property = mapObject.FindProperty("_options");
|
||||
if (!((AbstractMap)serializedObject.targetObject).IsAccessTokenValid)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Invalid Access Token. Please add a valid access token using the Mapbox > Setup Menu", MessageType.Error);
|
||||
}
|
||||
|
||||
EditorGUILayout.LabelField("Location ", GUILayout.Height(_lineHeight));
|
||||
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("locationOptions"));
|
||||
|
||||
|
||||
var extentOptions = property.FindPropertyRelative("extentOptions");
|
||||
var extentOptionsType = extentOptions.FindPropertyRelative("extentType");
|
||||
|
||||
|
||||
if ((MapExtentType)extentOptionsType.enumValueIndex == MapExtentType.Custom)
|
||||
{
|
||||
var tileProviderProperty = mapObject.FindProperty("_tileProvider");
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(extentOptionsType);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(extentOptions);
|
||||
}
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(tileProviderProperty);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Space(-_lineHeight);
|
||||
EditorGUILayout.PropertyField(extentOptions);
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("_initializeOnStart"));
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
ShowPosition = EditorGUILayout.Foldout(ShowPosition, "Others");
|
||||
if (ShowPosition)
|
||||
{
|
||||
GUILayout.Space(-_lineHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var placementOptions = property.FindPropertyRelative("placementOptions");
|
||||
EditorGUILayout.PropertyField(placementOptions);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(placementOptions);
|
||||
}
|
||||
|
||||
GUILayout.Space(-_lineHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var scalingOptions = property.FindPropertyRelative("scalingOptions");
|
||||
EditorGUILayout.PropertyField(scalingOptions);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(scalingOptions);
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("loadingTexture"));
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("tileMaterial"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DrawMapLayerOptions()
|
||||
{
|
||||
var vectorDataProperty = serializedObject.FindProperty("_vectorData");
|
||||
var layerProperty = vectorDataProperty.FindPropertyRelative("_layerProperty");
|
||||
var layerSourceProperty = layerProperty.FindPropertyRelative("sourceOptions");
|
||||
var sourceTypeProperty = layerProperty.FindPropertyRelative("_sourceType");
|
||||
VectorSourceType sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
|
||||
var layerSourceId = layerProperty.FindPropertyRelative("sourceOptions.layerSource.Id");
|
||||
string layerString = layerSourceId.stringValue;
|
||||
var isActiveProperty = layerSourceProperty.FindPropertyRelative("isActive");
|
||||
|
||||
var displayNames = sourceTypeProperty.enumDisplayNames;
|
||||
var names = sourceTypeProperty.enumNames;
|
||||
int count = sourceTypeProperty.enumDisplayNames.Length;
|
||||
if (!_isGUIContentSet)
|
||||
{
|
||||
_sourceTypeContent = new GUIContent[count];
|
||||
|
||||
var index = 0;
|
||||
foreach (var name in names)
|
||||
{
|
||||
_sourceTypeContent[index] = new GUIContent
|
||||
{
|
||||
text = displayNames[index],
|
||||
tooltip = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), name)).Description(),
|
||||
};
|
||||
index++;
|
||||
}
|
||||
//
|
||||
// for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
// {
|
||||
// _sourceTypeContent[extIdx] = new GUIContent
|
||||
// {
|
||||
// text = displayNames[extIdx],
|
||||
// tooltip = ((VectorSourceType)extIdx).Description(),
|
||||
// };
|
||||
// }
|
||||
|
||||
_isGUIContentSet = true;
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(new GUIContent
|
||||
{
|
||||
text = "Data Source",
|
||||
tooltip = "Source tileset for Vector Data"
|
||||
}, sourceTypeProperty.enumValueIndex, _sourceTypeContent);
|
||||
|
||||
//sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
|
||||
sourceTypeValue = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), names[sourceTypeProperty.enumValueIndex]));
|
||||
|
||||
switch (sourceTypeValue)
|
||||
{
|
||||
case VectorSourceType.MapboxStreets:
|
||||
case VectorSourceType.MapboxStreetsV8:
|
||||
case VectorSourceType.MapboxStreetsWithBuildingIds:
|
||||
case VectorSourceType.MapboxStreetsV8WithBuildingIds:
|
||||
var sourcePropertyValue = MapboxDefaultVector.GetParameters(sourceTypeValue);
|
||||
layerSourceId.stringValue = sourcePropertyValue.Id;
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(layerSourceProperty, tilesetIdGui);
|
||||
GUI.enabled = true;
|
||||
isActiveProperty.boolValue = true;
|
||||
break;
|
||||
case VectorSourceType.Custom:
|
||||
EditorGUILayout.PropertyField(layerSourceProperty, tilesetIdGui);
|
||||
isActiveProperty.boolValue = true;
|
||||
break;
|
||||
case VectorSourceType.None:
|
||||
isActiveProperty.boolValue = false;
|
||||
break;
|
||||
default:
|
||||
isActiveProperty.boolValue = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sourceTypeValue != VectorSourceType.None)
|
||||
{
|
||||
var isStyleOptimized = layerProperty.FindPropertyRelative("useOptimizedStyle");
|
||||
EditorGUILayout.PropertyField(isStyleOptimized);
|
||||
|
||||
if (isStyleOptimized.boolValue)
|
||||
{
|
||||
EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("optimizedStyle"), new GUIContent("Style Options"));
|
||||
}
|
||||
GUILayout.Space(-_lineHeight);
|
||||
EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("performanceOptions"), new GUIContent("Perfomance Options"));
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
ShowSepartor();
|
||||
|
||||
_vectorLayerDrawer.DrawUI(layerProperty);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(layerProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fe5a867f0f1546009ebdda576486b9e
|
||||
timeCreated: 1518137782
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,668 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using Mapbox.Unity;
|
||||
using Mapbox.Tokens;
|
||||
using Mapbox.Json;
|
||||
using Mapbox.Unity.Utilities;
|
||||
using Mapbox.Unity.Utilities.DebugTools;
|
||||
using UnityEditor.Callbacks;
|
||||
using System;
|
||||
|
||||
public class MapboxConfigurationWindow : EditorWindow
|
||||
{
|
||||
public static MapboxConfigurationWindow instance;
|
||||
static MapboxConfiguration _mapboxConfig;
|
||||
static MapboxTokenStatus _currentTokenStatus = MapboxTokenStatus.StatusNotYetSet;
|
||||
static MapboxAccess _mapboxAccess;
|
||||
static bool _waitingToLoad = false;
|
||||
|
||||
//default mapboxconfig
|
||||
static string _configurationFile;
|
||||
static string _accessToken = "";
|
||||
[Range(0, 1000)]
|
||||
static int _memoryCacheSize = 500;
|
||||
[Range(0, 3000)]
|
||||
static int _fileCacheSize = 25000;
|
||||
static int _webRequestTimeout = 30;
|
||||
static bool _autoRefreshCache = false;
|
||||
|
||||
//mapbox access callbacks
|
||||
static bool _listeningForTokenValidation = false;
|
||||
static bool _validating = false;
|
||||
static string _lastValidatedToken;
|
||||
|
||||
//gui flags
|
||||
bool _showConfigurationFoldout;
|
||||
bool _showChangelogFoldout;
|
||||
Vector2 _scrollPosition;
|
||||
|
||||
//samples
|
||||
static int _selectedSample;
|
||||
static ScenesList _sceneList;
|
||||
static GUIContent[] _sampleContent;
|
||||
string _sceneToOpen;
|
||||
|
||||
//prefabs
|
||||
static int _selectedPrefab;
|
||||
static ScenesList _prefabList;
|
||||
static GUIContent[] _prefabContent;
|
||||
|
||||
|
||||
//styles
|
||||
GUISkin _skin;
|
||||
Color _defaultContentColor;
|
||||
Color _defaultBackgroundColor;
|
||||
GUIStyle _titleStyle;
|
||||
GUIStyle _bodyStyle;
|
||||
GUIStyle _linkStyle;
|
||||
|
||||
GUIStyle _textFieldStyle;
|
||||
GUIStyle _submitButtonStyle;
|
||||
|
||||
GUIStyle _validButtonStyle;
|
||||
Color _validContentColor;
|
||||
Color _validBackgroundColor;
|
||||
|
||||
GUIStyle _invalidFieldStyle;
|
||||
GUIStyle _invalidButtonStyle;
|
||||
Color _invalidContentColor;
|
||||
Color _invalidBackgroundColor;
|
||||
GUIStyle _errorStyle;
|
||||
|
||||
GUIStyle _verticalGroup;
|
||||
GUIStyle _horizontalGroup;
|
||||
GUIStyle _scrollViewStyle;
|
||||
|
||||
GUIStyle _sampleButtonStyle;
|
||||
|
||||
|
||||
[DidReloadScripts]
|
||||
public static void ShowWindowOnImport()
|
||||
{
|
||||
if (ShouldShowConfigurationWindow())
|
||||
{
|
||||
PlayerPrefs.SetInt(Constants.Path.DID_PROMPT_CONFIGURATION, 1);
|
||||
PlayerPrefs.Save();
|
||||
InitWhenLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Mapbox/Setup")]
|
||||
static void InitWhenLoaded()
|
||||
{
|
||||
if (EditorApplication.isCompiling && !_waitingToLoad)
|
||||
{
|
||||
//subscribe to updates
|
||||
_waitingToLoad = true;
|
||||
EditorApplication.update += InitWhenLoaded;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EditorApplication.isCompiling)
|
||||
{
|
||||
//unsubscribe from updates if waiting
|
||||
if (_waitingToLoad)
|
||||
{
|
||||
EditorApplication.update -= InitWhenLoaded;
|
||||
_waitingToLoad = false;
|
||||
}
|
||||
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
static void Init()
|
||||
{
|
||||
Runnable.EnableRunnableInEditor();
|
||||
|
||||
//verify that the config file exists
|
||||
_configurationFile = Path.Combine(Unity.Constants.Path.MAPBOX_RESOURCES_ABSOLUTE, Unity.Constants.Path.CONFIG_FILE);
|
||||
if (!Directory.Exists(Unity.Constants.Path.MAPBOX_RESOURCES_ABSOLUTE))
|
||||
{
|
||||
Directory.CreateDirectory(Unity.Constants.Path.MAPBOX_RESOURCES_ABSOLUTE);
|
||||
}
|
||||
|
||||
if (!File.Exists(_configurationFile))
|
||||
{
|
||||
_mapboxConfig = new MapboxConfiguration
|
||||
{
|
||||
AccessToken = _accessToken,
|
||||
MemoryCacheSize = (uint)_memoryCacheSize,
|
||||
FileCacheSize = (uint)_fileCacheSize,
|
||||
AutoRefreshCache = _autoRefreshCache,
|
||||
DefaultTimeout = _webRequestTimeout
|
||||
};
|
||||
var json = JsonUtility.ToJson(_mapboxConfig);
|
||||
File.WriteAllText(_configurationFile, json);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
//finish opening the window after the assetdatabase is refreshed.
|
||||
EditorApplication.delayCall += OpenWindow;
|
||||
}
|
||||
|
||||
static void OpenWindow()
|
||||
{
|
||||
EditorApplication.delayCall -= OpenWindow;
|
||||
|
||||
//setup mapboxaccess listener
|
||||
_mapboxAccess = MapboxAccess.Instance;
|
||||
if (!_listeningForTokenValidation)
|
||||
{
|
||||
_mapboxAccess.OnTokenValidation += HandleValidationResponse;
|
||||
_listeningForTokenValidation = true;
|
||||
}
|
||||
|
||||
//setup local variables from mapbox config file
|
||||
_mapboxConfig = _mapboxAccess.Configuration;
|
||||
if (_mapboxConfig != null)
|
||||
{
|
||||
_accessToken = _mapboxConfig.AccessToken;
|
||||
_memoryCacheSize = (int)_mapboxConfig.MemoryCacheSize;
|
||||
_fileCacheSize = (int)_mapboxConfig.FileCacheSize;
|
||||
_autoRefreshCache = _mapboxConfig.AutoRefreshCache;
|
||||
_webRequestTimeout = (int)_mapboxConfig.DefaultTimeout;
|
||||
|
||||
}
|
||||
|
||||
//validate current config
|
||||
if (!string.IsNullOrEmpty(_accessToken))
|
||||
{
|
||||
SubmitConfiguration();
|
||||
}
|
||||
|
||||
//cache sample scene gui content
|
||||
GetSceneList();
|
||||
_selectedSample = -1;
|
||||
|
||||
//instantiate the config window
|
||||
instance = GetWindow(typeof(MapboxConfigurationWindow)) as MapboxConfigurationWindow;
|
||||
instance.minSize = new Vector2(800, 350);
|
||||
instance.titleContent = new GUIContent("Mapbox Setup");
|
||||
instance.Show();
|
||||
|
||||
}
|
||||
|
||||
static void GetSceneList()
|
||||
{
|
||||
_prefabList = Resources.Load<ScenesList>("Mapbox/PrefabList");
|
||||
_sceneList = Resources.Load<ScenesList>("Mapbox/ScenesList");
|
||||
|
||||
_prefabContent = LoadContent(_prefabList);
|
||||
_sampleContent = LoadContent(_sceneList);
|
||||
|
||||
}
|
||||
|
||||
static GUIContent[] LoadContent(ScenesList list)
|
||||
{
|
||||
|
||||
//exclude scenes with no image data
|
||||
var content = new List<SceneData>();
|
||||
if (list != null)
|
||||
{
|
||||
for (int i = 0; i < list.SceneList.Length; i++)
|
||||
{
|
||||
if (list.SceneList[i] != null)
|
||||
{
|
||||
if (File.Exists(list.SceneList[i].ScenePath))
|
||||
{
|
||||
if (list.SceneList[i].Image != null)
|
||||
{
|
||||
content.Add(list.SceneList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var outputContent = new GUIContent[content.Count];
|
||||
for (int i = 0; i < outputContent.Length; i++)
|
||||
{
|
||||
outputContent[i] = new GUIContent(content[i].Name, content[i].Image, content[i].ScenePath);
|
||||
}
|
||||
|
||||
return outputContent;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Unity Events
|
||||
/// </summary>
|
||||
|
||||
private void OnDisable() { AssetDatabase.Refresh(); }
|
||||
|
||||
private void OnDestroy() { AssetDatabase.Refresh(); }
|
||||
|
||||
private void OnLostFocus() { AssetDatabase.Refresh(); }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Mapbox access
|
||||
/// </summary>
|
||||
private static void SubmitConfiguration()
|
||||
{
|
||||
var mapboxConfiguration = new MapboxConfiguration
|
||||
{
|
||||
AccessToken = _accessToken,
|
||||
MemoryCacheSize = (uint)_memoryCacheSize,
|
||||
FileCacheSize = (uint)_fileCacheSize,
|
||||
AutoRefreshCache = _autoRefreshCache,
|
||||
DefaultTimeout = _webRequestTimeout
|
||||
};
|
||||
_mapboxAccess.SetConfiguration(mapboxConfiguration, false);
|
||||
_validating = true;
|
||||
}
|
||||
|
||||
private static void HandleValidationResponse(MapboxTokenStatus status)
|
||||
{
|
||||
_currentTokenStatus = status;
|
||||
_validating = false;
|
||||
_lastValidatedToken = _accessToken;
|
||||
|
||||
//save the config
|
||||
_configurationFile = Path.Combine(Unity.Constants.Path.MAPBOX_RESOURCES_ABSOLUTE, Unity.Constants.Path.CONFIG_FILE);
|
||||
var json = JsonUtility.ToJson(_mapboxAccess.Configuration);
|
||||
File.WriteAllText(_configurationFile, json);
|
||||
}
|
||||
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
//only run after init
|
||||
if (instance == null)
|
||||
{
|
||||
//TODO: loading message?
|
||||
InitWhenLoaded();
|
||||
return;
|
||||
}
|
||||
|
||||
InitStyles();
|
||||
|
||||
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, _scrollViewStyle);
|
||||
EditorGUILayout.BeginVertical();
|
||||
// Access token link.
|
||||
DrawAccessTokenLink();
|
||||
|
||||
// Access token entry and validation.
|
||||
DrawAccessTokenField();
|
||||
|
||||
// Draw the validation error, if one exists
|
||||
DrawError();
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.BeginVertical(_verticalGroup);
|
||||
|
||||
// Configuration
|
||||
DrawConfigurationSettings();
|
||||
GUILayout.Space(8);
|
||||
|
||||
// Changelog
|
||||
DrawChangelog();
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
// Draw Prefab Examples
|
||||
if (_prefabContent.Length > 0)
|
||||
{
|
||||
EditorGUILayout.BeginVertical(_verticalGroup);
|
||||
DrawPrefabLinks();
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
}
|
||||
|
||||
// Draw Example links if the scenelist asset is where it should be.
|
||||
if (_sampleContent.Length > 0)
|
||||
{
|
||||
EditorGUILayout.BeginVertical(_verticalGroup);
|
||||
DrawExampleLinks();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
void InitStyles()
|
||||
{
|
||||
_defaultContentColor = GUI.contentColor;
|
||||
_defaultBackgroundColor = GUI.backgroundColor;
|
||||
|
||||
_titleStyle = new GUIStyle(GUI.skin.FindStyle("IN TitleText"));
|
||||
_titleStyle.padding.left = 3;
|
||||
_bodyStyle = new GUIStyle(GUI.skin.FindStyle("WordWrapLabel"));
|
||||
_linkStyle = new GUIStyle(GUI.skin.FindStyle("PR PrefabLabel"));
|
||||
_linkStyle.padding.left = 0;
|
||||
_linkStyle.padding.top = -1;
|
||||
|
||||
_textFieldStyle = new GUIStyle(GUI.skin.FindStyle("TextField"));
|
||||
_textFieldStyle.margin.right = 0;
|
||||
_textFieldStyle.margin.top = 0;
|
||||
|
||||
_submitButtonStyle = new GUIStyle(GUI.skin.FindStyle("ButtonRight"));
|
||||
_submitButtonStyle.padding.top = 0;
|
||||
_submitButtonStyle.margin.top = 0;
|
||||
_submitButtonStyle.fixedWidth = 200;
|
||||
|
||||
_validButtonStyle = new GUIStyle(GUI.skin.FindStyle("LODSliderRange"));
|
||||
_validButtonStyle.alignment = TextAnchor.MiddleCenter;
|
||||
_validButtonStyle.padding = new RectOffset(0, 0, 0, 0);
|
||||
_validButtonStyle.border = new RectOffset(0, 0, 5, -2);
|
||||
_validButtonStyle.fixedWidth = 60;
|
||||
|
||||
_validContentColor = new Color(1, 1, 1, .7f);
|
||||
_validBackgroundColor = new Color(.2f, .8f, .2f, 1);
|
||||
_invalidContentColor = new Color(1, 1, 1, .7f);
|
||||
_invalidBackgroundColor = new Color(.8f, .2f, .2f, 1);
|
||||
|
||||
_errorStyle = new GUIStyle(GUI.skin.FindStyle("ErrorLabel"));
|
||||
_errorStyle.padding.left = 5;
|
||||
|
||||
_verticalGroup = new GUIStyle();
|
||||
_verticalGroup.margin = new RectOffset(0, 0, 0, 35);
|
||||
_horizontalGroup = new GUIStyle();
|
||||
_horizontalGroup.padding = new RectOffset(0, 0, 4, 4);
|
||||
_scrollViewStyle = new GUIStyle(GUI.skin.FindStyle("scrollview"));
|
||||
_scrollViewStyle.padding = new RectOffset(20, 20, 40, 0);
|
||||
|
||||
_sampleButtonStyle = new GUIStyle(GUI.skin.FindStyle("button"));
|
||||
_sampleButtonStyle.imagePosition = ImagePosition.ImageAbove;
|
||||
_sampleButtonStyle.padding = new RectOffset(0, 0, 5, 5);
|
||||
_sampleButtonStyle.fontStyle = FontStyle.Bold;
|
||||
}
|
||||
|
||||
void DrawAccessTokenLink()
|
||||
{
|
||||
|
||||
EditorGUILayout.LabelField("Access Token", _titleStyle);
|
||||
|
||||
EditorGUILayout.BeginHorizontal(_horizontalGroup);
|
||||
if (string.IsNullOrEmpty(_accessToken))
|
||||
{
|
||||
//fit box to text to create an 'inline link'
|
||||
GUIContent labelContent = new GUIContent("Copy your free token from");
|
||||
GUIContent linkContent = new GUIContent("mapbox.com");
|
||||
|
||||
EditorGUILayout.LabelField(labelContent, _bodyStyle, GUILayout.Width(_bodyStyle.CalcSize(labelContent).x));
|
||||
|
||||
if (GUILayout.Button(linkContent, _linkStyle))
|
||||
{
|
||||
Application.OpenURL("https://www.mapbox.com/studio/account/tokens/");
|
||||
}
|
||||
|
||||
//create link cursor
|
||||
var rect = GUILayoutUtility.GetLastRect();
|
||||
rect.width = _linkStyle.CalcSize(new GUIContent(linkContent)).x;
|
||||
EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
GUIContent labelContent = new GUIContent("Manage your tokens at");
|
||||
GUIContent linkContent = new GUIContent("mapbox.com/studio/accounts/tokens/");
|
||||
|
||||
EditorGUILayout.LabelField(labelContent, _bodyStyle, GUILayout.Width(_bodyStyle.CalcSize(labelContent).x));
|
||||
|
||||
if (GUILayout.Button(linkContent, _linkStyle))
|
||||
{
|
||||
Application.OpenURL("https://www.mapbox.com/studio/account/tokens/");
|
||||
}
|
||||
|
||||
//create link cursor
|
||||
var rect = GUILayoutUtility.GetLastRect();
|
||||
rect.width = _linkStyle.CalcSize(new GUIContent(linkContent)).x;
|
||||
EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
}
|
||||
|
||||
void DrawAccessTokenField()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal(_horizontalGroup);
|
||||
|
||||
//_accessToken is empty
|
||||
if (string.IsNullOrEmpty(_accessToken))
|
||||
{
|
||||
_accessToken = EditorGUILayout.TextField("", _accessToken, _textFieldStyle);
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
GUILayout.Button("Submit", _submitButtonStyle);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
else
|
||||
{
|
||||
//_accessToken is being validated
|
||||
if (_validating)
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
_accessToken = EditorGUILayout.TextField("", _accessToken, _textFieldStyle);
|
||||
GUILayout.Button("Checking", _submitButtonStyle);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
//_accessToken is the same as the already submitted token
|
||||
else if (string.Equals(_lastValidatedToken, _accessToken))
|
||||
{
|
||||
//valid token
|
||||
if (_currentTokenStatus == MapboxTokenStatus.TokenValid)
|
||||
{
|
||||
GUI.backgroundColor = _validBackgroundColor;
|
||||
GUI.contentColor = _validContentColor;
|
||||
|
||||
_accessToken = EditorGUILayout.TextField("", _accessToken, _textFieldStyle);
|
||||
GUILayout.Button("Valid", _validButtonStyle);
|
||||
|
||||
GUI.contentColor = _defaultContentColor;
|
||||
GUI.backgroundColor = _defaultBackgroundColor;
|
||||
|
||||
}
|
||||
//invalid token
|
||||
else
|
||||
{
|
||||
|
||||
GUI.contentColor = _invalidContentColor;
|
||||
GUI.backgroundColor = _invalidBackgroundColor;
|
||||
|
||||
_accessToken = EditorGUILayout.TextField("", _accessToken, _textFieldStyle);
|
||||
GUILayout.Button("Invalid", _validButtonStyle);
|
||||
|
||||
GUI.contentColor = _defaultContentColor;
|
||||
GUI.backgroundColor = _defaultBackgroundColor;
|
||||
|
||||
}
|
||||
//Submit button
|
||||
if (GUILayout.Button("Submit", _submitButtonStyle))
|
||||
{
|
||||
SubmitConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
//_accessToken is a new, unsubmitted token.
|
||||
else
|
||||
{
|
||||
_accessToken = EditorGUILayout.TextField("", _accessToken, _textFieldStyle);
|
||||
|
||||
if (GUILayout.Button("Submit", _submitButtonStyle))
|
||||
{
|
||||
SubmitConfiguration();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
}
|
||||
|
||||
void DrawError()
|
||||
{
|
||||
//draw the error message, if one exists
|
||||
EditorGUILayout.BeginHorizontal(_horizontalGroup);
|
||||
|
||||
if (_currentTokenStatus != MapboxTokenStatus.TokenValid
|
||||
&& _currentTokenStatus != MapboxTokenStatus.StatusNotYetSet
|
||||
&& string.Equals(_lastValidatedToken, _accessToken)
|
||||
&& !_validating)
|
||||
{
|
||||
EditorGUILayout.LabelField(_currentTokenStatus.ToString(), _errorStyle);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
}
|
||||
|
||||
void DrawChangelog()
|
||||
{
|
||||
EditorGUI.indentLevel = 2;
|
||||
|
||||
GUIContent linkContent = new GUIContent("v" + Constants.SDK_VERSION + " changelog");
|
||||
|
||||
if (GUILayout.Button(linkContent, _linkStyle))
|
||||
{
|
||||
Application.OpenURL("https://github.com/mapbox/mapbox-unity-sdk/blob/develop/documentation/docs/05-changelog.md");
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
void DrawConfigurationSettings()
|
||||
{
|
||||
_showConfigurationFoldout = EditorGUILayout.Foldout(_showConfigurationFoldout, "Configuration", true);
|
||||
|
||||
if (_showConfigurationFoldout)
|
||||
{
|
||||
EditorGUIUtility.labelWidth = 240f;
|
||||
EditorGUI.indentLevel = 2;
|
||||
_memoryCacheSize = EditorGUILayout.IntSlider("Mem Cache Size (# of tiles)", _memoryCacheSize, 0, 1000);
|
||||
_fileCacheSize = EditorGUILayout.IntSlider("File Cache Size (# of tiles)", _fileCacheSize, 0, 3000);
|
||||
_autoRefreshCache = EditorGUILayout.Toggle(new GUIContent("Auto refresh cache", "Automatically update tiles in the local ambient cache if there is a newer version available online. ATTENTION: for every tile displayed (even a cached one) a webrequest needs to be made to check for updates."), _autoRefreshCache);
|
||||
_webRequestTimeout = EditorGUILayout.IntField("Default Web Request Timeout (s)", _webRequestTimeout);
|
||||
|
||||
EditorGUILayout.BeginHorizontal(_horizontalGroup);
|
||||
GUILayout.Space(35f);
|
||||
if (GUILayout.Button("Save"))
|
||||
{
|
||||
SubmitConfiguration();
|
||||
}
|
||||
EditorGUI.indentLevel = 0;
|
||||
EditorGUIUtility.labelWidth = 0f;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DrawPrefabLinks()
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(_currentTokenStatus != MapboxTokenStatus.TokenValid
|
||||
|| _validating);
|
||||
|
||||
if (_currentTokenStatus == MapboxTokenStatus.TokenValid)
|
||||
{
|
||||
EditorGUILayout.LabelField("Map Prefabs", _titleStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.LabelField("Map Prefabs", "Paste your mapbox access token to get started", _titleStyle);
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal(_horizontalGroup);
|
||||
EditorGUILayout.LabelField("Choose a starting scene to see each location-based prefab in action, or go to the prefabs folder and add them to your existing scene.", _bodyStyle);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
int rowCount = 4;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
_selectedPrefab = GUILayout.SelectionGrid(-1, _prefabContent, rowCount, _sampleButtonStyle);
|
||||
|
||||
if (_selectedPrefab != -1)
|
||||
{
|
||||
EditorApplication.isPaused = false;
|
||||
EditorApplication.isPlaying = false;
|
||||
|
||||
_sceneToOpen = _prefabContent[_selectedPrefab].tooltip;
|
||||
EditorApplication.update += OpenAndPlayScene;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
}
|
||||
|
||||
void DrawExampleLinks()
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(_currentTokenStatus != MapboxTokenStatus.TokenValid
|
||||
|| _validating);
|
||||
|
||||
if (_currentTokenStatus == MapboxTokenStatus.TokenValid)
|
||||
{
|
||||
EditorGUILayout.LabelField("Example Scenes", _titleStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.LabelField("Example Scenes", _titleStyle);
|
||||
}
|
||||
|
||||
|
||||
int rowCount = 4;
|
||||
EditorGUILayout.BeginHorizontal(_horizontalGroup);
|
||||
|
||||
_selectedSample = GUILayout.SelectionGrid(-1, _sampleContent, rowCount, _sampleButtonStyle);
|
||||
|
||||
if (_selectedSample != -1)
|
||||
{
|
||||
EditorApplication.isPaused = false;
|
||||
EditorApplication.isPlaying = false;
|
||||
|
||||
_sceneToOpen = _sampleContent[_selectedSample].tooltip;
|
||||
EditorApplication.update += OpenAndPlayScene;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
private void OpenAndPlayScene()
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EditorApplication.update -= OpenAndPlayScene;
|
||||
|
||||
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
||||
{
|
||||
EditorSceneManager.OpenScene(_sceneToOpen);
|
||||
EditorApplication.isPlaying = true;
|
||||
|
||||
var editorWindow = GetWindow(typeof(MapboxConfigurationWindow));
|
||||
editorWindow.Close();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_sceneToOpen = null;
|
||||
_selectedPrefab = -1;
|
||||
_selectedSample = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool ShouldShowConfigurationWindow()
|
||||
{
|
||||
if (!PlayerPrefs.HasKey(Constants.Path.DID_PROMPT_CONFIGURATION))
|
||||
{
|
||||
PlayerPrefs.SetInt(Constants.Path.DID_PROMPT_CONFIGURATION, 0);
|
||||
}
|
||||
|
||||
return PlayerPrefs.GetInt(Constants.Path.DID_PROMPT_CONFIGURATION) == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 276c74102975f4a52b0d286bdb580c2e
|
||||
timeCreated: 1490214747
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
|
||||
[CustomEditor(typeof(MaterialModifier))]
|
||||
public class MaterialModifierEditor : UnityEditor.Editor
|
||||
{
|
||||
|
||||
private MonoScript script;
|
||||
private SerializedProperty _materials;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
script = MonoScript.FromScriptableObject((MaterialModifier)target);
|
||||
_materials = serializedObject.FindProperty("_options");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
GUI.enabled = false;
|
||||
script = EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false) as MonoScript;
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.PropertyField(_materials);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a416905e274b84a428108fb5b0ee6bb7
|
||||
timeCreated: 1504124010
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
|
||||
[CustomEditor(typeof(MergedModifierStack))]
|
||||
public class MergedModifierStackEditor : UnityEditor.Editor
|
||||
{
|
||||
private MonoScript script;
|
||||
private Texture2D _magnifier;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
script = MonoScript.FromScriptableObject((MergedModifierStack)target);
|
||||
_magnifier = EditorGUIUtility.FindTexture("d_ViewToolZoom");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
GUI.enabled = false;
|
||||
script = EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false) as MonoScript;
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Mesh Modifiers");
|
||||
var facs = serializedObject.FindProperty("MeshModifiers");
|
||||
for (int i = 0; i < facs.arraySize; i++)
|
||||
{
|
||||
var ind = i;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.BeginVertical();
|
||||
GUILayout.Space(5);
|
||||
facs.GetArrayElementAtIndex(ind).objectReferenceValue = EditorGUILayout.ObjectField(facs.GetArrayElementAtIndex(i).objectReferenceValue, typeof(MeshModifier), false) as ScriptableObject;
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (GUILayout.Button(_magnifier, (GUIStyle)"minibuttonleft", GUILayout.Width(30)))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(MeshModifier), facs, ind);
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("-"), (GUIStyle)"minibuttonright", GUILayout.Width(30), GUILayout.Height(22)))
|
||||
{
|
||||
facs.DeleteArrayElementAtIndex(ind);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(new GUIContent("Add New Empty"), (GUIStyle)"minibuttonleft"))
|
||||
{
|
||||
facs.arraySize++;
|
||||
facs.GetArrayElementAtIndex(facs.arraySize - 1).objectReferenceValue = null;
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("Find Asset"), (GUIStyle)"minibuttonright"))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(MeshModifier), facs);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Game Object Modifiers");
|
||||
var facs2 = serializedObject.FindProperty("GoModifiers");
|
||||
for (int i = 0; i < facs2.arraySize; i++)
|
||||
{
|
||||
var ind = i;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.BeginVertical();
|
||||
GUILayout.Space(5);
|
||||
facs2.GetArrayElementAtIndex(ind).objectReferenceValue = EditorGUILayout.ObjectField(facs2.GetArrayElementAtIndex(i).objectReferenceValue, typeof(GameObjectModifier), false) as ScriptableObject;
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (GUILayout.Button(_magnifier, (GUIStyle)"minibuttonleft", GUILayout.Width(30)))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(GameObjectModifier), facs2, ind);
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("-"), (GUIStyle)"minibuttonright", GUILayout.Width(30), GUILayout.Height(22)))
|
||||
{
|
||||
facs2.DeleteArrayElementAtIndex(ind);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(new GUIContent("Add New Empty"), (GUIStyle)"minibuttonleft"))
|
||||
{
|
||||
facs2.arraySize++;
|
||||
facs2.GetArrayElementAtIndex(facs2.arraySize - 1).objectReferenceValue = null;
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("Find Asset"), (GUIStyle)"minibuttonright"))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(GameObjectModifier), facs2);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0ec3bc7bc8e146dc8ee1fcfcded456a
|
||||
timeCreated: 1504124010
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,107 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
|
||||
[CustomEditor(typeof(ModifierStack))]
|
||||
public class ModifierStackEditor : UnityEditor.Editor
|
||||
{
|
||||
|
||||
private MonoScript script;
|
||||
private SerializedProperty _positionType;
|
||||
private Texture2D _magnifier;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
script = MonoScript.FromScriptableObject((ModifierStack)target);
|
||||
_positionType = serializedObject.FindProperty("moveFeaturePositionTo");
|
||||
_magnifier = EditorGUIUtility.FindTexture("d_ViewToolZoom");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
GUI.enabled = false;
|
||||
script = EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false) as MonoScript;
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.PropertyField(_positionType, new GUIContent("Feature Position"));
|
||||
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Mesh Modifiers");
|
||||
var meshfac = serializedObject.FindProperty("MeshModifiers");
|
||||
for (int i = 0; i < meshfac.arraySize; i++)
|
||||
{
|
||||
var ind = i;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.BeginVertical();
|
||||
GUILayout.Space(5);
|
||||
meshfac.GetArrayElementAtIndex(ind).objectReferenceValue = EditorGUILayout.ObjectField(meshfac.GetArrayElementAtIndex(i).objectReferenceValue, typeof(MeshModifier), false) as ScriptableObject;
|
||||
EditorGUILayout.EndVertical();
|
||||
if (GUILayout.Button(_magnifier, (GUIStyle)"minibuttonleft", GUILayout.Width(30)))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(MeshModifier), meshfac, ind);
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("-"), (GUIStyle)"minibuttonright", GUILayout.Width(30), GUILayout.Height(22)))
|
||||
{
|
||||
meshfac.DeleteArrayElementAtIndex(ind);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(new GUIContent("Add New Empty"), (GUIStyle)"minibuttonleft"))
|
||||
{
|
||||
meshfac.arraySize++;
|
||||
meshfac.GetArrayElementAtIndex(meshfac.arraySize - 1).objectReferenceValue = null;
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("Find Asset"), (GUIStyle)"minibuttonright"))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(MeshModifier), meshfac);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Game Object Modifiers");
|
||||
var gofac = serializedObject.FindProperty("GoModifiers");
|
||||
for (int i = 0; i < gofac.arraySize; i++)
|
||||
{
|
||||
var ind = i;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.BeginVertical();
|
||||
GUILayout.Space(5);
|
||||
gofac.GetArrayElementAtIndex(ind).objectReferenceValue = EditorGUILayout.ObjectField(gofac.GetArrayElementAtIndex(i).objectReferenceValue, typeof(GameObjectModifier), false) as ScriptableObject;
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (GUILayout.Button(_magnifier, (GUIStyle)"minibuttonleft", GUILayout.Width(30)))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(GameObjectModifier), gofac, ind);
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("-"), (GUIStyle)"minibuttonright", GUILayout.Width(30), GUILayout.Height(22)))
|
||||
{
|
||||
gofac.DeleteArrayElementAtIndex(ind);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(new GUIContent("Add New Empty"), (GUIStyle)"minibuttonleft"))
|
||||
{
|
||||
gofac.arraySize++;
|
||||
gofac.GetArrayElementAtIndex(gofac.arraySize - 1).objectReferenceValue = null;
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("Find Asset"), (GUIStyle)"minibuttonright"))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(GameObjectModifier), gofac);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0cd73e58c7a441cd81f138edd9bbb31
|
||||
timeCreated: 1504124010
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,82 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
public class PointsOfInterestSubLayerTreeView : TreeView
|
||||
{
|
||||
public SerializedProperty Layers;
|
||||
private float kToggleWidth = 18f;
|
||||
private const int uniqueId = 0;
|
||||
|
||||
public bool hasChanged = false;
|
||||
|
||||
public PointsOfInterestSubLayerTreeView(TreeViewState state)
|
||||
: base(state)
|
||||
{
|
||||
showAlternatingRowBackgrounds = true;
|
||||
showBorder = true;
|
||||
Reload();
|
||||
}
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
// The root item is required to have a depth of -1, and the rest of the items increment from that.
|
||||
var root = new TreeViewItem { id = -1, depth = -1, displayName = "Root" };
|
||||
|
||||
var items = new List<TreeViewItem>();
|
||||
var index = 0;
|
||||
|
||||
if (Layers != null)
|
||||
{
|
||||
for (int i = 0; i < Layers.arraySize; i++)
|
||||
{
|
||||
var name = Layers.GetArrayElementAtIndex(i).FindPropertyRelative("coreOptions.sublayerName").stringValue;
|
||||
items.Add(new TreeViewItem { id = index + uniqueId, depth = 1, displayName = name });
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
// Utility method that initializes the TreeViewItem.children and .parent for all items.
|
||||
SetupParentsAndChildrenFromDepths(root, items);
|
||||
|
||||
// Return root of the tree
|
||||
return root;
|
||||
}
|
||||
|
||||
protected override bool CanRename(TreeViewItem item)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void RenameEnded(RenameEndedArgs args)
|
||||
{
|
||||
if (Layers == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var layer = Layers.GetArrayElementAtIndex(args.itemID - uniqueId);
|
||||
layer.FindPropertyRelative("coreOptions.sublayerName").stringValue = string.IsNullOrEmpty(args.newName.Trim()) ? args.originalName : args.newName;
|
||||
}
|
||||
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
Rect toggleRect = args.rowRect;
|
||||
toggleRect.width = kToggleWidth;
|
||||
var item = Layers.GetArrayElementAtIndex(args.item.id - uniqueId);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
item.FindPropertyRelative("coreOptions.isActive").boolValue = EditorGUI.Toggle(toggleRect, item.FindPropertyRelative("coreOptions.isActive").boolValue);
|
||||
if(EditorGUI.EndChangeCheck())
|
||||
{
|
||||
hasChanged = true;
|
||||
}
|
||||
args.item.displayName = item.FindPropertyRelative("coreOptions.sublayerName").stringValue;
|
||||
base.RowGUI(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 430429020c0a64703b89ac33585da3e7
|
||||
timeCreated: 1530564120
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,161 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Mapbox.Unity;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Pop up menu for selecting, creating and assigning modifier instances to AbstractMap.
|
||||
/// </summary>
|
||||
public class PopupSelectionMenu : PopupWindowContent
|
||||
{
|
||||
|
||||
private Type _type;
|
||||
|
||||
private List<Type> _modTypes;
|
||||
|
||||
private SerializedProperty _finalize;
|
||||
|
||||
private Vector2 _scrollPos;
|
||||
|
||||
public override Vector2 GetWindowSize()
|
||||
{
|
||||
return new Vector2(250, 250);
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
if (_modTypes == null || _modTypes.Count == 0)
|
||||
{
|
||||
_modTypes = new List<Type>();
|
||||
|
||||
AppDomain currentDomain = AppDomain.CurrentDomain;
|
||||
Assembly[] assemblies = currentDomain.GetAssemblies();
|
||||
for (int i = 0; i < assemblies.Length; i++)
|
||||
{
|
||||
Type[] types = assemblies[i].GetTypes();
|
||||
for (int j = 0; j < types.Length; j++)
|
||||
{
|
||||
if (types[j].IsSubclassOf(_type))
|
||||
{
|
||||
_modTypes.Add(types[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Label(String.Format("{0}s", _type.Name), EditorStyles.boldLabel);
|
||||
var st = new GUIStyle();
|
||||
st.padding = new RectOffset(0, 0, 15, 15);
|
||||
_scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, st);
|
||||
|
||||
for (int i = 0; i < _modTypes.Count; i++)
|
||||
{
|
||||
Type asset = _modTypes[i];
|
||||
if (asset == null) //yea turns out this can happen
|
||||
continue;
|
||||
var style = GUI.skin.button;
|
||||
style.alignment = TextAnchor.MiddleLeft;
|
||||
string shortTypeName = GetShortTypeName(asset.ToString());
|
||||
if (GUILayout.Button(shortTypeName, style))
|
||||
{
|
||||
CreateNewModiferInstance(asset, shortTypeName);
|
||||
editorWindow.Close();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the short name of the type.
|
||||
/// </summary>
|
||||
/// <returns>The short type name.</returns>
|
||||
/// <param name="input">Input.</param>
|
||||
private string GetShortTypeName(string input)
|
||||
{
|
||||
int pos = input.LastIndexOf(".", StringComparison.CurrentCulture) + 1;
|
||||
return input.Substring(pos, input.Length - pos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the new modifer instance.
|
||||
/// </summary>
|
||||
/// <param name="type">Type.</param>
|
||||
/// <param name="name">Name.</param>
|
||||
private void CreateNewModiferInstance(Type type, string name)
|
||||
{
|
||||
var modifierInstance = ScriptableObject.CreateInstance(type);
|
||||
|
||||
string pathCandidate = Constants.Path.MAPBOX_USER_MODIFIERS;
|
||||
if (!Directory.Exists(pathCandidate))
|
||||
{
|
||||
|
||||
string userFolder = Constants.Path.MAPBOX_USER;
|
||||
if (!Directory.Exists(userFolder))
|
||||
{
|
||||
string parentPath = System.IO.Path.Combine("Assets", "Mapbox");
|
||||
AssetDatabase.CreateFolder(parentPath, "User");
|
||||
}
|
||||
AssetDatabase.CreateFolder(userFolder, "Modifiers");
|
||||
}
|
||||
|
||||
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
|
||||
{
|
||||
pathCandidate = AssetDatabase.GetAssetPath(obj);
|
||||
if (!string.IsNullOrEmpty(pathCandidate) && File.Exists(pathCandidate))
|
||||
{
|
||||
pathCandidate = Path.GetDirectoryName(pathCandidate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string combinedPath = string.Format("{0}{1}.asset", Path.Combine(pathCandidate, "New"), name);
|
||||
string uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath(combinedPath);
|
||||
|
||||
modifierInstance.name = name;
|
||||
|
||||
AssetDatabase.CreateAsset(modifierInstance, uniqueAssetPath);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
AddNewInstanceToArray(modifierInstance);
|
||||
|
||||
Debug.Log(string.Format("Created new {0} modifer at {1}", name, uniqueAssetPath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the new instance to array.
|
||||
/// </summary>
|
||||
/// <param name="obj">Object.</param>
|
||||
public void AddNewInstanceToArray(object obj)
|
||||
{
|
||||
ScriptableObject asset = obj as ScriptableObject;
|
||||
|
||||
_finalize.arraySize++;
|
||||
_finalize.GetArrayElementAtIndex(_finalize.arraySize - 1).objectReferenceValue = asset;
|
||||
|
||||
MapboxDataProperty mapboxDataProperty = (MapboxDataProperty)EditorHelper.GetTargetObjectWithProperty(_finalize);
|
||||
if (_finalize.serializedObject.ApplyModifiedProperties() && mapboxDataProperty != null)
|
||||
{
|
||||
mapboxDataProperty.HasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:Mapbox.Editor.PopupSelectionMenu"/> class.
|
||||
/// </summary>
|
||||
/// <param name="t">T.</param>
|
||||
/// <param name="p">P.</param>
|
||||
public PopupSelectionMenu(Type t, SerializedProperty p)
|
||||
{
|
||||
_type = t;
|
||||
_finalize = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6c73878fee204232a755433b391ccd5
|
||||
timeCreated: 1526401331
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0963d53ec1a1b453bbcf67aa71a02a1d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,218 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
|
||||
public class BehaviorModifiersSectionDrawer
|
||||
{
|
||||
string objectId = "";
|
||||
|
||||
bool showGameplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "VectorSubLayerProperties_showGameplay");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "VectorSubLayerProperties_showGameplay", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawUI(SerializedProperty layerProperty, VectorPrimitiveType primitiveTypeProp, VectorSourceType sourceType)
|
||||
{
|
||||
|
||||
showGameplay = EditorGUILayout.Foldout(showGameplay, "Behavior Modifiers");
|
||||
if (showGameplay)
|
||||
{
|
||||
|
||||
bool isPrimitiveTypeValidForBuidingIds = (primitiveTypeProp == VectorPrimitiveType.Polygon || primitiveTypeProp == VectorPrimitiveType.Custom);
|
||||
bool isSourceValidForBuildingIds = sourceType != VectorSourceType.MapboxStreets;
|
||||
|
||||
layerProperty.FindPropertyRelative("honorBuildingIdSetting").boolValue = isPrimitiveTypeValidForBuidingIds && isSourceValidForBuildingIds;
|
||||
|
||||
if (layerProperty.FindPropertyRelative("honorBuildingIdSetting").boolValue == true)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("buildingsWithUniqueIds"), new GUIContent
|
||||
{
|
||||
text = "Buildings With Unique Ids",
|
||||
tooltip =
|
||||
"Turn on this setting only when rendering 3D buildings from the Mapbox Streets with Building Ids tileset. Using this setting with any other polygon layers or source will result in visual artifacts. "
|
||||
});
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(layerProperty);
|
||||
}
|
||||
}
|
||||
|
||||
var subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions");
|
||||
var combineMeshesProperty = subLayerCoreOptions.FindPropertyRelative("combineMeshes");
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (combineMeshesProperty.boolValue == false)
|
||||
{
|
||||
var featurePositionProperty = layerProperty.FindPropertyRelative("moveFeaturePositionTo");
|
||||
GUIContent dropDownLabel = new GUIContent
|
||||
{
|
||||
text = "Feature Position",
|
||||
tooltip = "Position to place feature in the tile. "
|
||||
};
|
||||
|
||||
GUIContent[] dropDownItems = new GUIContent[featurePositionProperty.enumDisplayNames.Length];
|
||||
|
||||
for (int i = 0; i < featurePositionProperty.enumDisplayNames.Length; i++)
|
||||
{
|
||||
dropDownItems[i] = new GUIContent
|
||||
{
|
||||
text = featurePositionProperty.enumDisplayNames[i]
|
||||
};
|
||||
}
|
||||
EditorGUI.BeginChangeCheck();
|
||||
featurePositionProperty.enumValueIndex = EditorGUILayout.Popup(dropDownLabel, featurePositionProperty.enumValueIndex, dropDownItems);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(layerProperty);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
DrawMeshModifiers(layerProperty);
|
||||
DrawGoModifiers(layerProperty);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMeshModifiers(SerializedProperty property)
|
||||
{
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.LabelField(new GUIContent
|
||||
{
|
||||
text = "Mesh Modifiers",
|
||||
tooltip = "Modifiers that manipulate the features mesh. "
|
||||
});
|
||||
|
||||
var meshfac = property.FindPropertyRelative("MeshModifiers");
|
||||
|
||||
for (int i = 0; i < meshfac.arraySize; i++)
|
||||
{
|
||||
var ind = i;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
meshfac.GetArrayElementAtIndex(ind).objectReferenceValue =
|
||||
EditorGUILayout.ObjectField(meshfac.GetArrayElementAtIndex(i).objectReferenceValue, typeof(MeshModifier), false)
|
||||
as ScriptableObject;
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (GUILayout.Button(new GUIContent("x"), (GUIStyle)"minibuttonright", GUILayout.Width(30)))
|
||||
{
|
||||
bool elementWasDeleted = false;
|
||||
if (meshfac.arraySize > 0)
|
||||
{
|
||||
meshfac.DeleteArrayElementAtIndex(ind);
|
||||
elementWasDeleted = true;
|
||||
}
|
||||
if (meshfac.arraySize > 0)
|
||||
{
|
||||
meshfac.DeleteArrayElementAtIndex(ind);
|
||||
}
|
||||
if (elementWasDeleted)
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUI.indentLevel * 12);
|
||||
Rect buttonRect = GUILayoutUtility.GetLastRect();
|
||||
if (GUILayout.Button(new GUIContent("Add New"), (GUIStyle)"minibuttonleft"))
|
||||
{
|
||||
PopupWindow.Show(buttonRect, new PopupSelectionMenu(typeof(MeshModifier), meshfac));
|
||||
if (Event.current.type == EventType.Repaint) buttonRect = GUILayoutUtility.GetLastRect();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Add Existing"), (GUIStyle)"minibuttonright"))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(MeshModifier), meshfac, -1, null, property);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private void DrawGoModifiers(SerializedProperty property)
|
||||
{
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent
|
||||
{
|
||||
text = "Game Object Modifiers",
|
||||
tooltip = "Modifiers that manipulate the GameObject after mesh generation."
|
||||
});
|
||||
var gofac = property.FindPropertyRelative("GoModifiers");
|
||||
|
||||
for (int i = 0; i < gofac.arraySize; i++)
|
||||
{
|
||||
var ind = i;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.BeginVertical();
|
||||
GUILayout.Space(5);
|
||||
gofac.GetArrayElementAtIndex(ind).objectReferenceValue =
|
||||
EditorGUILayout.ObjectField(gofac.GetArrayElementAtIndex(i).objectReferenceValue, typeof(GameObjectModifier),
|
||||
false) as ScriptableObject;
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (GUILayout.Button(new GUIContent("x"), GUILayout.Width(30)))
|
||||
{
|
||||
bool elementWasDeleted = false;
|
||||
if (gofac.arraySize > 0)
|
||||
{
|
||||
gofac.DeleteArrayElementAtIndex(ind);
|
||||
elementWasDeleted = true;
|
||||
}
|
||||
if (gofac.arraySize > 0)
|
||||
{
|
||||
gofac.DeleteArrayElementAtIndex(ind);
|
||||
}
|
||||
if (elementWasDeleted)
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUI.indentLevel * 12);
|
||||
Rect buttonRect = GUILayoutUtility.GetLastRect();
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Add New"), (GUIStyle)"minibuttonleft"))
|
||||
{
|
||||
PopupWindow.Show(buttonRect, new PopupSelectionMenu(typeof(GameObjectModifier), gofac));
|
||||
if (Event.current.type == EventType.Repaint) buttonRect = GUILayoutUtility.GetLastRect();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Add Existing"), (GUIStyle)"minibuttonright"))
|
||||
{
|
||||
|
||||
ScriptableCreatorWindow.Open(typeof(GameObjectModifier), gofac, -1, null, property);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4301f1990a1f8417280b87eb43510a4c
|
||||
timeCreated: 1533828994
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(CameraBoundsTileProviderOptions))]
|
||||
public class CameraBoundsTileProviderOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var camera = property.FindPropertyRelative("camera");
|
||||
EditorGUI.PropertyField(position, camera, new GUIContent
|
||||
{
|
||||
text = camera.displayName,
|
||||
tooltip = "Camera to control map extent."
|
||||
});
|
||||
}
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 1 * _lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edfd5847c11274df4a63d74e142d6695
|
||||
timeCreated: 1517858264
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,58 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
using Mapbox.Editor;
|
||||
|
||||
[CustomPropertyDrawer(typeof(ColliderOptions))]
|
||||
public class ColliderOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
bool isGUIContentSet = false;
|
||||
GUIContent[] colliderTypeContent;
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, null, property);
|
||||
var colliderTypeLabel = new GUIContent
|
||||
{
|
||||
text = "Collider Type",
|
||||
tooltip = "The type of collider added to game objects in this layer."
|
||||
};
|
||||
var colliderTypeProperty = property.FindPropertyRelative("colliderType");
|
||||
|
||||
var displayNames = colliderTypeProperty.enumDisplayNames;
|
||||
int count = colliderTypeProperty.enumDisplayNames.Length;
|
||||
|
||||
if (!isGUIContentSet)
|
||||
{
|
||||
colliderTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
colliderTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = EnumExtensions.Description((ColliderType)extIdx),
|
||||
};
|
||||
}
|
||||
isGUIContentSet = true;
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
colliderTypeProperty.enumValueIndex = EditorGUILayout.Popup(colliderTypeLabel, colliderTypeProperty.enumValueIndex, colliderTypeContent);
|
||||
if(EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05ab73c42b3654a68823b6793c470531
|
||||
timeCreated: 1522459817
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
using Mapbox.Editor;
|
||||
|
||||
[CustomPropertyDrawer(typeof(CoreVectorLayerProperties))]
|
||||
public class CoreVectorLayerPropertiesDrawer : PropertyDrawer
|
||||
{
|
||||
bool _isGUIContentSet = false;
|
||||
GUIContent[] _primitiveTypeContent;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
|
||||
EditorGUI.BeginProperty(position, null, property);
|
||||
|
||||
var primitiveType = property.FindPropertyRelative("geometryType");
|
||||
|
||||
var primitiveTypeLabel = new GUIContent
|
||||
{
|
||||
text = "Primitive Type",
|
||||
tooltip = "Primitive geometry type of the visualizer, allowed primitives - point, line, polygon."
|
||||
};
|
||||
|
||||
var displayNames = primitiveType.enumDisplayNames;
|
||||
int count = primitiveType.enumDisplayNames.Length;
|
||||
|
||||
if (!_isGUIContentSet)
|
||||
{
|
||||
_primitiveTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
_primitiveTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = EnumExtensions.Description((VectorPrimitiveType)extIdx),
|
||||
};
|
||||
}
|
||||
_isGUIContentSet = true;
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
primitiveType.enumValueIndex = EditorGUILayout.Popup(primitiveTypeLabel, primitiveType.enumValueIndex, _primitiveTypeContent);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a198cd5919ca149099130ba68e0f258b
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,163 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
|
||||
[CustomPropertyDrawer(typeof(ElevationLayerProperties))]
|
||||
public class ElevationLayerPropertiesDrawer : PropertyDrawer
|
||||
{
|
||||
string objectId = "";
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
GUIContent[] sourceTypeContent;
|
||||
bool isGUIContentSet = false;
|
||||
|
||||
bool ShowPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "ElevationLayerProperties_showPosition");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "ElevationLayerProperties_showPosition", value);
|
||||
}
|
||||
}
|
||||
|
||||
private GUIContent _tilesetIdGui = new GUIContent
|
||||
{
|
||||
text = "Tileset Id",
|
||||
tooltip = "Id of the tileset."
|
||||
};
|
||||
|
||||
string CustomSourceTilesetId
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetString(objectId + "ElevationLayerProperties_customSourceTilesetId");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetString(objectId + "ElevationLayerProperties_customSourceTilesetId", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
objectId = property.serializedObject.targetObject.GetInstanceID().ToString();
|
||||
|
||||
var sourceTypeProperty = property.FindPropertyRelative("sourceType");
|
||||
|
||||
var displayNames = sourceTypeProperty.enumDisplayNames;
|
||||
int count = sourceTypeProperty.enumDisplayNames.Length;
|
||||
if (!isGUIContentSet)
|
||||
{
|
||||
sourceTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
sourceTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = ((ElevationSourceType)extIdx).Description(),
|
||||
};
|
||||
}
|
||||
isGUIContentSet = true;
|
||||
}
|
||||
var sourceTypeLabel = new GUIContent { text = "Data Source", tooltip = "Source tileset for Terrain." };
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(sourceTypeLabel, sourceTypeProperty.enumValueIndex, sourceTypeContent);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
var sourceTypeValue = (ElevationSourceType)sourceTypeProperty.enumValueIndex;
|
||||
|
||||
var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
|
||||
var layerSourceProperty = sourceOptionsProperty.FindPropertyRelative("layerSource");
|
||||
var layerSourceId = layerSourceProperty.FindPropertyRelative("Id");
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
switch (sourceTypeValue)
|
||||
{
|
||||
case ElevationSourceType.MapboxTerrain:
|
||||
var sourcePropertyValue = MapboxDefaultElevation.GetParameters(sourceTypeValue);
|
||||
layerSourceId.stringValue = sourcePropertyValue.Id;
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(sourceOptionsProperty, _tilesetIdGui);
|
||||
GUI.enabled = true;
|
||||
break;
|
||||
case ElevationSourceType.Custom:
|
||||
layerSourceId.stringValue = string.IsNullOrEmpty(CustomSourceTilesetId) ? MapboxDefaultElevation.GetParameters(ElevationSourceType.MapboxTerrain).Id : CustomSourceTilesetId;
|
||||
EditorGUILayout.PropertyField(sourceOptionsProperty, _tilesetIdGui);
|
||||
CustomSourceTilesetId = layerSourceId.stringValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
var elevationLayerType = property.FindPropertyRelative("elevationLayerType");
|
||||
|
||||
if (sourceTypeValue == ElevationSourceType.None)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
elevationLayerType.enumValueIndex = (int)ElevationLayerType.FlatTerrain;
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("elevationLayerType"), new GUIContent { text = elevationLayerType.displayName, tooltip = ((ElevationLayerType)elevationLayerType.enumValueIndex).Description() });
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
if (sourceTypeValue == ElevationSourceType.None)
|
||||
{
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
GUILayout.Space(-lineHeight);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("colliderOptions"), true);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property.FindPropertyRelative("colliderOptions"));
|
||||
}
|
||||
GUILayout.Space(2 * -lineHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("requiredOptions"), true);
|
||||
GUILayout.Space(-lineHeight);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
ShowPosition = EditorGUILayout.Foldout(ShowPosition, "Others");
|
||||
|
||||
if (ShowPosition)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("modificationOptions"), true);
|
||||
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("sideWallOptions"), true);
|
||||
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("unityLayerOptions"), true);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: becc811ca916a4717bf81685180e605d
|
||||
timeCreated: 1520010402
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(ElevationModificationOptions))]
|
||||
public class ElevationModificationOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("sampleCount"));
|
||||
position.y += lineHeight;
|
||||
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("useRelativeHeight"));
|
||||
position.y += lineHeight;
|
||||
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("earthRadius"));
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Reserve space for the total visible properties.
|
||||
return 3.0f * lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 299ec1d2adf5f4418aa69f1441d59731
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(ElevationRequiredOptions))]
|
||||
public class ElevationRequiredOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
position.y += lineHeight;
|
||||
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("exaggerationFactor"));
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Reserve space for the total visible properties.
|
||||
return 3.0f * lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b69c5574214341c9888bda16d659aee
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,696 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.Map;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
using Mapbox.Unity.MeshGeneration.Filters;
|
||||
using Mapbox.Platform.TilesetTileJSON;
|
||||
using Mapbox.Editor;
|
||||
using System;
|
||||
|
||||
public class FeaturesSubLayerPropertiesDrawer
|
||||
{
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
GUIContent[] _sourceTypeContent;
|
||||
bool _isGUIContentSet = false;
|
||||
bool _isInitialized = false;
|
||||
private TileJsonData tileJSONData;
|
||||
private static TileJSONResponse tileJSONResponse;
|
||||
static TileJsonData tileJsonData = new TileJsonData();
|
||||
int _layerIndex = 0;
|
||||
GUIContent[] _layerTypeContent;
|
||||
private static VectorSubLayerProperties subLayerProperties;
|
||||
private TreeModel<FeatureTreeElement> treeModel;
|
||||
|
||||
private static string[] names;
|
||||
[SerializeField]
|
||||
TreeViewState m_TreeViewState;
|
||||
|
||||
[SerializeField]
|
||||
MultiColumnHeaderState m_MultiColumnHeaderState;
|
||||
|
||||
public bool isLayerAdded = false;
|
||||
bool m_Initialized = false;
|
||||
string objectId = "";
|
||||
private string TilesetId
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetString(objectId + "VectorSubLayerProperties_tilesetId");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetString(objectId + "VectorSubLayerProperties_tilesetId", value);
|
||||
}
|
||||
}
|
||||
|
||||
bool ShowPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "VectorSubLayerProperties_showPosition");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "VectorSubLayerProperties_showPosition", value);
|
||||
}
|
||||
}
|
||||
|
||||
int SelectionIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetInt(objectId + "VectorSubLayerProperties_selectionIndex");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetInt(objectId + "VectorSubLayerProperties_selectionIndex", value);
|
||||
}
|
||||
}
|
||||
|
||||
ModelingSectionDrawer _modelingSectionDrawer = new ModelingSectionDrawer();
|
||||
BehaviorModifiersSectionDrawer _behaviorModifierSectionDrawer = new BehaviorModifiersSectionDrawer();
|
||||
|
||||
private static TileStats _streetsV7TileStats;
|
||||
private static string[] subTypeValues;
|
||||
FeatureSubLayerTreeView layerTreeView;
|
||||
IList<int> selectedLayers = new List<int>();
|
||||
public void DrawUI(SerializedProperty property)
|
||||
{
|
||||
|
||||
objectId = property.serializedObject.targetObject.GetInstanceID().ToString();
|
||||
var serializedMapObject = property.serializedObject;
|
||||
AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject;
|
||||
tileJSONData = mapObject.VectorData.GetTileJsonData();
|
||||
|
||||
var sourceTypeProperty = property.FindPropertyRelative("_sourceType");
|
||||
var sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
|
||||
|
||||
var displayNames = sourceTypeProperty.enumDisplayNames;
|
||||
var names = sourceTypeProperty.enumNames;
|
||||
int count = sourceTypeProperty.enumDisplayNames.Length;
|
||||
if (!_isGUIContentSet)
|
||||
{
|
||||
_sourceTypeContent = new GUIContent[count];
|
||||
|
||||
var index = 0;
|
||||
foreach (var name in names)
|
||||
{
|
||||
_sourceTypeContent[index] = new GUIContent
|
||||
{
|
||||
text = displayNames[index],
|
||||
tooltip = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), name)).Description(),
|
||||
};
|
||||
index++;
|
||||
}
|
||||
|
||||
// for (int index0 = 0; index0 < count; index0++)
|
||||
// {
|
||||
// _sourceTypeContent[index0] = new GUIContent
|
||||
// {
|
||||
// text = displayNames[index0],
|
||||
// tooltip = ((VectorSourceType)index0).Description(),
|
||||
// };
|
||||
// }
|
||||
_isGUIContentSet = true;
|
||||
}
|
||||
|
||||
//sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
|
||||
sourceTypeValue = ((VectorSourceType)Enum.Parse(typeof(VectorSourceType), names[sourceTypeProperty.enumValueIndex]));
|
||||
var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
|
||||
var layerSourceProperty = sourceOptionsProperty.FindPropertyRelative("layerSource");
|
||||
var layerSourceId = layerSourceProperty.FindPropertyRelative("Id");
|
||||
var isActiveProperty = sourceOptionsProperty.FindPropertyRelative("isActive");
|
||||
switch (sourceTypeValue)
|
||||
{
|
||||
case VectorSourceType.MapboxStreets:
|
||||
case VectorSourceType.MapboxStreetsV8:
|
||||
case VectorSourceType.MapboxStreetsWithBuildingIds:
|
||||
case VectorSourceType.MapboxStreetsV8WithBuildingIds:
|
||||
var sourcePropertyValue = MapboxDefaultVector.GetParameters(sourceTypeValue);
|
||||
layerSourceId.stringValue = sourcePropertyValue.Id;
|
||||
GUI.enabled = false;
|
||||
if (_isInitialized)
|
||||
{
|
||||
LoadEditorTileJSON(property, sourceTypeValue, layerSourceId.stringValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
_isInitialized = true;
|
||||
}
|
||||
if (tileJSONData.PropertyDisplayNames.Count == 0 && tileJSONData.tileJSONLoaded)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Invalid Tileset Id / There might be a problem with the internet connection.", MessageType.Error);
|
||||
}
|
||||
GUI.enabled = true;
|
||||
isActiveProperty.boolValue = true;
|
||||
break;
|
||||
case VectorSourceType.Custom:
|
||||
if (_isInitialized)
|
||||
{
|
||||
string test = layerSourceId.stringValue;
|
||||
LoadEditorTileJSON(property, sourceTypeValue, layerSourceId.stringValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
_isInitialized = true;
|
||||
}
|
||||
if (tileJSONData.PropertyDisplayNames.Count == 0 && tileJSONData.tileJSONLoaded)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Invalid Tileset Id / There might be a problem with the internet connection.", MessageType.Error);
|
||||
}
|
||||
isActiveProperty.boolValue = true;
|
||||
break;
|
||||
case VectorSourceType.None:
|
||||
isActiveProperty.boolValue = false;
|
||||
break;
|
||||
default:
|
||||
isActiveProperty.boolValue = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sourceTypeValue != VectorSourceType.None)
|
||||
{
|
||||
EditorGUILayout.LabelField(new GUIContent
|
||||
{
|
||||
text = "Map Features",
|
||||
tooltip = "Visualizers for vector features contained in a layer. "
|
||||
});
|
||||
|
||||
var subLayerArray = property.FindPropertyRelative("vectorSubLayers");
|
||||
|
||||
var layersRect = EditorGUILayout.GetControlRect(GUILayout.MinHeight(Mathf.Max(subLayerArray.arraySize + 1, 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight),
|
||||
GUILayout.MaxHeight((subLayerArray.arraySize + 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight));
|
||||
|
||||
if (!m_Initialized)
|
||||
{
|
||||
bool firstInit = m_MultiColumnHeaderState == null;
|
||||
var headerState = FeatureSubLayerTreeView.CreateDefaultMultiColumnHeaderState();
|
||||
if (MultiColumnHeaderState.CanOverwriteSerializedFields(m_MultiColumnHeaderState, headerState))
|
||||
{
|
||||
MultiColumnHeaderState.OverwriteSerializedFields(m_MultiColumnHeaderState, headerState);
|
||||
}
|
||||
m_MultiColumnHeaderState = headerState;
|
||||
|
||||
var multiColumnHeader = new FeatureSectionMultiColumnHeader(headerState);
|
||||
|
||||
if (firstInit)
|
||||
{
|
||||
multiColumnHeader.ResizeToFit();
|
||||
}
|
||||
|
||||
treeModel = new TreeModel<FeatureTreeElement>(GetData(subLayerArray));
|
||||
if (m_TreeViewState == null)
|
||||
{
|
||||
m_TreeViewState = new TreeViewState();
|
||||
}
|
||||
|
||||
if (layerTreeView == null)
|
||||
{
|
||||
layerTreeView = new FeatureSubLayerTreeView(m_TreeViewState, multiColumnHeader, treeModel);
|
||||
}
|
||||
layerTreeView.multiColumnHeader = multiColumnHeader;
|
||||
m_Initialized = true;
|
||||
}
|
||||
layerTreeView.Layers = subLayerArray;
|
||||
layerTreeView.Reload();
|
||||
layerTreeView.OnGUI(layersRect);
|
||||
|
||||
if (layerTreeView.hasChanged)
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
layerTreeView.hasChanged = false;
|
||||
}
|
||||
|
||||
selectedLayers = layerTreeView.GetSelection();
|
||||
|
||||
//if there are selected elements, set the selection index at the first element.
|
||||
//if not, use the Selection index to persist the selection at the right index.
|
||||
if (selectedLayers.Count > 0)
|
||||
{
|
||||
//ensure that selectedLayers[0] isn't out of bounds
|
||||
if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdFeature > subLayerArray.arraySize - 1)
|
||||
{
|
||||
selectedLayers[0] = subLayerArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdFeature;
|
||||
}
|
||||
|
||||
SelectionIndex = selectedLayers[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SelectionIndex > 0 && (SelectionIndex - FeatureSubLayerTreeView.uniqueIdFeature <= subLayerArray.arraySize - 1))
|
||||
{
|
||||
selectedLayers = new int[1] { SelectionIndex };
|
||||
layerTreeView.SetSelection(selectedLayers);
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Space(EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GenericMenu menu = new GenericMenu();
|
||||
foreach (var name in Enum.GetNames(typeof(PresetFeatureType)))
|
||||
{
|
||||
menu.AddItem(new GUIContent() { text = name }, false, FetchPresetProperties, name);
|
||||
}
|
||||
GUILayout.Space(0); // do not remove this line; it is needed for the next line to work
|
||||
Rect rect = GUILayoutUtility.GetLastRect();
|
||||
rect.y += 2 * _lineHeight / 3;
|
||||
|
||||
if (EditorGUILayout.DropdownButton(new GUIContent { text = "Add Feature" }, FocusType.Passive, (GUIStyle)"minibuttonleft"))
|
||||
{
|
||||
menu.DropDown(rect);
|
||||
}
|
||||
|
||||
//Assign subLayerProperties after fetching it from the presets class. This happens everytime an element is added
|
||||
if (subLayerProperties != null)
|
||||
{
|
||||
subLayerArray.arraySize++;
|
||||
var subLayer = subLayerArray.GetArrayElementAtIndex(subLayerArray.arraySize - 1);
|
||||
SetSubLayerProps(subLayer);
|
||||
|
||||
//Refreshing the tree
|
||||
layerTreeView.Layers = subLayerArray;
|
||||
layerTreeView.AddElementToTree(subLayer);
|
||||
layerTreeView.Reload();
|
||||
|
||||
selectedLayers = new int[1] { subLayerArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdFeature };
|
||||
layerTreeView.SetSelection(selectedLayers);
|
||||
subLayerProperties = null; // setting this to null so that the if block is not called again
|
||||
|
||||
if (EditorHelper.DidModifyProperty(property))
|
||||
{
|
||||
isLayerAdded = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright"))
|
||||
{
|
||||
foreach (var index in selectedLayers.OrderByDescending(i => i))
|
||||
{
|
||||
if (layerTreeView != null)
|
||||
{
|
||||
var subLayer = subLayerArray.GetArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdFeature);
|
||||
|
||||
VectorLayerProperties vectorLayerProperties = (VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property);
|
||||
VectorSubLayerProperties vectorSubLayerProperties = (VectorSubLayerProperties)EditorHelper.GetTargetObjectOfProperty(subLayer);
|
||||
|
||||
vectorLayerProperties.OnSubLayerPropertyRemoved(new VectorLayerUpdateArgs { property = vectorSubLayerProperties });
|
||||
|
||||
layerTreeView.RemoveItemFromTree(index);
|
||||
subLayerArray.DeleteArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdFeature);
|
||||
layerTreeView.treeModel.SetData(GetData(subLayerArray));
|
||||
}
|
||||
}
|
||||
|
||||
selectedLayers = new int[0];
|
||||
layerTreeView.SetSelection(selectedLayers);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(EditorGUIUtility.singleLineHeight);
|
||||
|
||||
if (selectedLayers.Count == 1 && subLayerArray.arraySize != 0 && selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdFeature >= 0)
|
||||
{
|
||||
//ensure that selectedLayers[0] isn't out of bounds
|
||||
if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdFeature > subLayerArray.arraySize - 1)
|
||||
{
|
||||
selectedLayers[0] = subLayerArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdFeature;
|
||||
}
|
||||
|
||||
SelectionIndex = selectedLayers[0];
|
||||
|
||||
var layerProperty = subLayerArray.GetArrayElementAtIndex(SelectionIndex - FeatureSubLayerTreeView.uniqueIdFeature);
|
||||
|
||||
layerProperty.isExpanded = true;
|
||||
var subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions");
|
||||
bool isLayerActive = subLayerCoreOptions.FindPropertyRelative("isActive").boolValue;
|
||||
if (!isLayerActive)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
}
|
||||
|
||||
DrawLayerVisualizerProperties(sourceTypeValue, layerProperty, property);
|
||||
|
||||
if (!isLayerActive)
|
||||
{
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label("Select a visualizer to see properties");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IList<FeatureTreeElement> GetData(SerializedProperty subLayerArray)
|
||||
{
|
||||
List<FeatureTreeElement> elements = new List<FeatureTreeElement>();
|
||||
string name = string.Empty;
|
||||
string type = string.Empty;
|
||||
int id = 0;
|
||||
var root = new FeatureTreeElement("Root", -1, 0);
|
||||
elements.Add(root);
|
||||
for (int i = 0; i < subLayerArray.arraySize; i++)
|
||||
{
|
||||
var subLayer = subLayerArray.GetArrayElementAtIndex(i);
|
||||
name = subLayer.FindPropertyRelative("coreOptions.sublayerName").stringValue;
|
||||
id = i + FeatureSubLayerTreeView.uniqueIdFeature;
|
||||
type = ((PresetFeatureType)subLayer.FindPropertyRelative("presetFeatureType").enumValueIndex).ToString();
|
||||
FeatureTreeElement element = new FeatureTreeElement(name, 0, id);
|
||||
element.Name = name;
|
||||
element.name = name;
|
||||
element.Type = type;
|
||||
elements.Add(element);
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the preset properties using the supplied <see cref="PresetFeatureType">PresetFeatureType</see>
|
||||
/// </summary>
|
||||
/// <param name="name">Name.</param>
|
||||
void FetchPresetProperties(object name)
|
||||
{
|
||||
PresetFeatureType featureType = ((PresetFeatureType)Enum.Parse(typeof(PresetFeatureType), name.ToString()));
|
||||
subLayerProperties = PresetSubLayerPropertiesFetcher.GetSubLayerProperties(featureType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the sub layer properties for the newly added layer
|
||||
/// </summary>
|
||||
/// <param name="subLayer">Sub layer.</param>
|
||||
void SetSubLayerProps(SerializedProperty subLayer)
|
||||
{
|
||||
subLayer.FindPropertyRelative("coreOptions.sublayerName").stringValue = subLayerProperties.coreOptions.sublayerName;
|
||||
subLayer.FindPropertyRelative("presetFeatureType").enumValueIndex = (int)subLayerProperties.presetFeatureType;
|
||||
// Set defaults here because SerializedProperty copies the previous element.
|
||||
var subLayerCoreOptions = subLayer.FindPropertyRelative("coreOptions");
|
||||
CoreVectorLayerProperties coreOptions = subLayerProperties.coreOptions;
|
||||
subLayerCoreOptions.FindPropertyRelative("isActive").boolValue = coreOptions.isActive;
|
||||
subLayerCoreOptions.FindPropertyRelative("layerName").stringValue = coreOptions.layerName;
|
||||
subLayerCoreOptions.FindPropertyRelative("geometryType").enumValueIndex = (int)coreOptions.geometryType;
|
||||
subLayerCoreOptions.FindPropertyRelative("snapToTerrain").boolValue = coreOptions.snapToTerrain;
|
||||
subLayerCoreOptions.FindPropertyRelative("combineMeshes").boolValue = coreOptions.combineMeshes;
|
||||
|
||||
var subLayerlineGeometryOptions = subLayer.FindPropertyRelative("lineGeometryOptions");
|
||||
var lineGeometryOptions = subLayerProperties.lineGeometryOptions;
|
||||
subLayerlineGeometryOptions.FindPropertyRelative("Width").floatValue = lineGeometryOptions.Width;
|
||||
subLayerlineGeometryOptions.FindPropertyRelative("CapType").enumValueIndex = (int)lineGeometryOptions.CapType;
|
||||
subLayerlineGeometryOptions.FindPropertyRelative("JoinType").enumValueIndex = (int)lineGeometryOptions.JoinType;
|
||||
subLayerlineGeometryOptions.FindPropertyRelative("MiterLimit").floatValue = lineGeometryOptions.MiterLimit;
|
||||
subLayerlineGeometryOptions.FindPropertyRelative("RoundLimit").floatValue = lineGeometryOptions.RoundLimit;
|
||||
|
||||
|
||||
var subLayerExtrusionOptions = subLayer.FindPropertyRelative("extrusionOptions");
|
||||
var extrusionOptions = subLayerProperties.extrusionOptions;
|
||||
subLayerExtrusionOptions.FindPropertyRelative("extrusionType").enumValueIndex = (int)extrusionOptions.extrusionType;
|
||||
subLayerExtrusionOptions.FindPropertyRelative("extrusionGeometryType").enumValueIndex = (int)extrusionOptions.extrusionGeometryType;
|
||||
subLayerExtrusionOptions.FindPropertyRelative("propertyName").stringValue = extrusionOptions.propertyName;
|
||||
subLayerExtrusionOptions.FindPropertyRelative("extrusionScaleFactor").floatValue = extrusionOptions.extrusionScaleFactor;
|
||||
subLayerExtrusionOptions.FindPropertyRelative("maximumHeight").floatValue = extrusionOptions.maximumHeight;
|
||||
|
||||
var subLayerFilterOptions = subLayer.FindPropertyRelative("filterOptions");
|
||||
var filterOptions = subLayerProperties.filterOptions;
|
||||
subLayerFilterOptions.FindPropertyRelative("filters").ClearArray();
|
||||
subLayerFilterOptions.FindPropertyRelative("combinerType").enumValueIndex = (int)filterOptions.combinerType;
|
||||
//Add any future filter related assignments here
|
||||
|
||||
var subLayerGeometryMaterialOptions = subLayer.FindPropertyRelative("materialOptions");
|
||||
var materialOptions = subLayerProperties.materialOptions;
|
||||
subLayerGeometryMaterialOptions.FindPropertyRelative("style").enumValueIndex = (int)materialOptions.style;
|
||||
|
||||
var mats = subLayerGeometryMaterialOptions.FindPropertyRelative("materials");
|
||||
mats.arraySize = 2;
|
||||
|
||||
var topMatArray = mats.GetArrayElementAtIndex(0).FindPropertyRelative("Materials");
|
||||
var sideMatArray = mats.GetArrayElementAtIndex(1).FindPropertyRelative("Materials");
|
||||
|
||||
if (topMatArray.arraySize == 0)
|
||||
{
|
||||
topMatArray.arraySize = 1;
|
||||
}
|
||||
if (sideMatArray.arraySize == 0)
|
||||
{
|
||||
sideMatArray.arraySize = 1;
|
||||
}
|
||||
|
||||
var topMat = topMatArray.GetArrayElementAtIndex(0);
|
||||
var sideMat = sideMatArray.GetArrayElementAtIndex(0);
|
||||
|
||||
var atlas = subLayerGeometryMaterialOptions.FindPropertyRelative("atlasInfo");
|
||||
var palette = subLayerGeometryMaterialOptions.FindPropertyRelative("colorPalette");
|
||||
var lightStyleOpacity = subLayerGeometryMaterialOptions.FindPropertyRelative("lightStyleOpacity");
|
||||
var darkStyleOpacity = subLayerGeometryMaterialOptions.FindPropertyRelative("darkStyleOpacity");
|
||||
var colorStyleColor = subLayerGeometryMaterialOptions.FindPropertyRelative("colorStyleColor");
|
||||
var customStyleOptions = subLayerGeometryMaterialOptions.FindPropertyRelative("customStyleOptions");
|
||||
|
||||
topMat.objectReferenceValue = materialOptions.materials[0].Materials[0];
|
||||
sideMat.objectReferenceValue = materialOptions.materials[1].Materials[0];
|
||||
atlas.objectReferenceValue = materialOptions.atlasInfo;
|
||||
palette.objectReferenceValue = materialOptions.colorPalette;
|
||||
lightStyleOpacity.floatValue = materialOptions.lightStyleOpacity;
|
||||
darkStyleOpacity.floatValue = materialOptions.darkStyleOpacity;
|
||||
colorStyleColor.colorValue = materialOptions.colorStyleColor;
|
||||
//set custom style options.
|
||||
var customMats = customStyleOptions.FindPropertyRelative("materials");
|
||||
customMats.arraySize = 2;
|
||||
|
||||
var customTopMatArray = customMats.GetArrayElementAtIndex(0).FindPropertyRelative("Materials");
|
||||
var customSideMatArray = customMats.GetArrayElementAtIndex(1).FindPropertyRelative("Materials");
|
||||
|
||||
if (customTopMatArray.arraySize == 0)
|
||||
{
|
||||
customTopMatArray.arraySize = 1;
|
||||
}
|
||||
if (customSideMatArray.arraySize == 0)
|
||||
{
|
||||
customSideMatArray.arraySize = 1;
|
||||
}
|
||||
|
||||
var customTopMat = customTopMatArray.GetArrayElementAtIndex(0);
|
||||
var customSideMat = customSideMatArray.GetArrayElementAtIndex(0);
|
||||
|
||||
|
||||
customTopMat.objectReferenceValue = materialOptions.customStyleOptions.materials[0].Materials[0];
|
||||
customSideMat.objectReferenceValue = materialOptions.customStyleOptions.materials[1].Materials[0];
|
||||
customStyleOptions.FindPropertyRelative("atlasInfo").objectReferenceValue = materialOptions.customStyleOptions.atlasInfo;
|
||||
customStyleOptions.FindPropertyRelative("colorPalette").objectReferenceValue = materialOptions.customStyleOptions.colorPalette;
|
||||
|
||||
subLayer.FindPropertyRelative("buildingsWithUniqueIds").boolValue = subLayerProperties.buildingsWithUniqueIds;
|
||||
subLayer.FindPropertyRelative("moveFeaturePositionTo").enumValueIndex = (int)subLayerProperties.moveFeaturePositionTo;
|
||||
subLayer.FindPropertyRelative("MeshModifiers").ClearArray();
|
||||
subLayer.FindPropertyRelative("GoModifiers").ClearArray();
|
||||
|
||||
var subLayerColliderOptions = subLayer.FindPropertyRelative("colliderOptions");
|
||||
subLayerColliderOptions.FindPropertyRelative("colliderType").enumValueIndex = (int)subLayerProperties.colliderOptions.colliderType;
|
||||
}
|
||||
|
||||
private void UpdateMe()
|
||||
{
|
||||
Debug.Log("Update!");
|
||||
}
|
||||
|
||||
void DrawLayerVisualizerProperties(VectorSourceType sourceType, SerializedProperty layerProperty, SerializedProperty property)
|
||||
{
|
||||
var subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions");
|
||||
|
||||
var subLayerName = subLayerCoreOptions.FindPropertyRelative("sublayerName").stringValue;
|
||||
var visualizerLayer = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue;
|
||||
var subLayerType = PresetSubLayerPropertiesFetcher.GetPresetTypeFromLayerName(visualizerLayer);
|
||||
|
||||
GUILayout.Space(-_lineHeight);
|
||||
layerProperty.FindPropertyRelative("presetFeatureType").intValue = (int)subLayerType;
|
||||
|
||||
GUILayout.Space(_lineHeight);
|
||||
//*********************** LAYER NAME BEGINS ***********************************//
|
||||
VectorPrimitiveType primitiveTypeProp = (VectorPrimitiveType)subLayerCoreOptions.FindPropertyRelative("geometryType").enumValueIndex;
|
||||
|
||||
var serializedMapObject = property.serializedObject;
|
||||
AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject;
|
||||
tileJsonData = mapObject.VectorData.GetTileJsonData();
|
||||
|
||||
var layerDisplayNames = tileJsonData.LayerDisplayNames;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
DrawLayerName(subLayerCoreOptions, layerDisplayNames);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(subLayerCoreOptions);
|
||||
}
|
||||
//*********************** LAYER NAME ENDS ***********************************//
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
//*********************** FILTERS SECTION BEGINS ***********************************//
|
||||
var filterOptions = layerProperty.FindPropertyRelative("filterOptions");
|
||||
filterOptions.FindPropertyRelative("_selectedLayerName").stringValue = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue;
|
||||
GUILayout.Space(-_lineHeight);
|
||||
EditorGUILayout.PropertyField(filterOptions, new GUIContent("Filters"));
|
||||
//*********************** FILTERS SECTION ENDS ***********************************//
|
||||
|
||||
|
||||
|
||||
//*********************** MODELING SECTION BEGINS ***********************************//
|
||||
_modelingSectionDrawer.DrawUI(subLayerCoreOptions, layerProperty, primitiveTypeProp);
|
||||
//*********************** MODELING SECTION ENDS ***********************************//
|
||||
|
||||
|
||||
//*********************** TEXTURING SECTION BEGINS ***********************************//
|
||||
if (primitiveTypeProp != VectorPrimitiveType.Point && primitiveTypeProp != VectorPrimitiveType.Custom)
|
||||
{
|
||||
GUILayout.Space(-_lineHeight);
|
||||
EditorGUILayout.PropertyField(layerProperty.FindPropertyRelative("materialOptions"));
|
||||
}
|
||||
//*********************** TEXTURING SECTION ENDS ***********************************//
|
||||
|
||||
|
||||
//*********************** GAMEPLAY SECTION BEGINS ***********************************//
|
||||
_behaviorModifierSectionDrawer.DrawUI(layerProperty, primitiveTypeProp, sourceType);
|
||||
//*********************** GAMEPLAY SECTION ENDS ***********************************//
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private void LoadEditorTileJSON(SerializedProperty property, VectorSourceType sourceTypeValue, string sourceString)
|
||||
{
|
||||
if (sourceTypeValue != VectorSourceType.None && !string.IsNullOrEmpty(sourceString))
|
||||
{
|
||||
if (tileJSONResponse == null || string.IsNullOrEmpty(sourceString) || sourceString != TilesetId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Unity.MapboxAccess.Instance.TileJSON.Get(sourceString, (response) =>
|
||||
{
|
||||
//if the code has reached this point it means that there is a valid access token
|
||||
tileJSONResponse = response;
|
||||
if (response == null || response.VectorLayers == null) //indicates bad tileresponse
|
||||
{
|
||||
tileJSONData.ClearData();
|
||||
return;
|
||||
}
|
||||
tileJSONData.ProcessTileJSONData(response);
|
||||
});
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
//no valid access token causes MapboxAccess to throw an error and hence setting this property
|
||||
tileJSONData.ClearData();
|
||||
}
|
||||
}
|
||||
else if (tileJSONData.LayerPropertyDescriptionDictionary.Count == 0)
|
||||
{
|
||||
tileJSONData.ProcessTileJSONData(tileJSONResponse);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tileJSONData.ClearData();
|
||||
}
|
||||
TilesetId = sourceString;
|
||||
}
|
||||
|
||||
public void DrawLayerName(SerializedProperty property, List<string> layerDisplayNames)
|
||||
{
|
||||
|
||||
var layerNameLabel = new GUIContent
|
||||
{
|
||||
text = "Data Layer",
|
||||
tooltip = "The layer name from the Mapbox tileset that would be used for visualizing a feature"
|
||||
};
|
||||
|
||||
//disable the selection if there is no layer
|
||||
if (layerDisplayNames.Count == 0)
|
||||
{
|
||||
EditorGUILayout.LabelField(layerNameLabel, new GUIContent("No layers found: Invalid TilesetId / No Internet."), (GUIStyle)"minipopUp");
|
||||
return;
|
||||
}
|
||||
|
||||
//check the string value at the current _layerIndex to verify that the stored index matches the property string.
|
||||
var layerString = property.FindPropertyRelative("layerName").stringValue;
|
||||
if (layerDisplayNames.Contains(layerString))
|
||||
{
|
||||
//if the layer contains the current layerstring, set it's index to match
|
||||
_layerIndex = layerDisplayNames.FindIndex(s => s.Equals(layerString));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//if the selected layer isn't in the source, add a placeholder entry
|
||||
_layerIndex = 0;
|
||||
layerDisplayNames.Insert(0, layerString);
|
||||
if (!tileJsonData.LayerPropertyDescriptionDictionary.ContainsKey(layerString))
|
||||
{
|
||||
tileJsonData.LayerPropertyDescriptionDictionary.Add(layerString, new Dictionary<string, string>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//create the display name guicontent array with an additional entry for the currently selected item
|
||||
_layerTypeContent = new GUIContent[layerDisplayNames.Count];
|
||||
for (int extIdx = 0; extIdx < layerDisplayNames.Count; extIdx++)
|
||||
{
|
||||
_layerTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = layerDisplayNames[extIdx],
|
||||
};
|
||||
}
|
||||
|
||||
//draw the layer selection popup
|
||||
_layerIndex = EditorGUILayout.Popup(layerNameLabel, _layerIndex, _layerTypeContent);
|
||||
var parsedString = layerDisplayNames.ToArray()[_layerIndex].Split(new string[] { tileJsonData.commonLayersKey }, System.StringSplitOptions.None)[0].Trim();
|
||||
property.FindPropertyRelative("layerName").stringValue = parsedString;
|
||||
}
|
||||
|
||||
private string[] GetSubTypeValues(SerializedProperty layerProperty, string visualizerLayer, VectorSourceType sourceType)
|
||||
{
|
||||
string[] typesArray = null;
|
||||
string roadLayer = layerProperty.FindPropertyRelative("roadLayer").stringValue;
|
||||
string landuseLayer = layerProperty.FindPropertyRelative("landuseLayer").stringValue;
|
||||
|
||||
if (visualizerLayer == roadLayer || visualizerLayer == landuseLayer)
|
||||
{
|
||||
_streetsV7TileStats = TileStatsFetcher.Instance.GetTileStats(sourceType);
|
||||
if (_streetsV7TileStats != null && _streetsV7TileStats.layers != null && _streetsV7TileStats.layers.Length != 0)
|
||||
{
|
||||
foreach (var layer in _streetsV7TileStats.layers)
|
||||
{
|
||||
if (layer.layer != visualizerLayer)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string presetPropertyName = "";
|
||||
if (layer.layer == roadLayer)
|
||||
{
|
||||
presetPropertyName = layerProperty.FindPropertyRelative("roadLayer_TypeProperty").stringValue;
|
||||
}
|
||||
else if (layer.layer == landuseLayer)
|
||||
{
|
||||
presetPropertyName = layerProperty.FindPropertyRelative("landuseLayer_TypeProperty").stringValue;
|
||||
}
|
||||
|
||||
if (layer.attributes != null && layer.attributes.Length > 0)
|
||||
{
|
||||
foreach (var attributeItem in layer.attributes)
|
||||
{
|
||||
if (attributeItem.attribute == presetPropertyName)
|
||||
{
|
||||
typesArray = attributeItem.values;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return typesArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a49c4311b159a483a8d3a61c78ac50bf
|
||||
timeCreated: 1525818948
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,240 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
using System.Linq;
|
||||
using Mapbox.Platform.TilesetTileJSON;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Editor;
|
||||
|
||||
[CustomPropertyDrawer(typeof(GeometryExtrusionOptions))]
|
||||
public class GeometryExtrusionOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
//indices for tileJSON lookup
|
||||
int _propertyIndex = 0;
|
||||
private static List<string> _propertyNamesList = new List<string>();
|
||||
GUIContent[] _propertyNameContent;
|
||||
|
||||
GUIContent[] extrusionTypeContent;
|
||||
bool isGUIContentSet = false;
|
||||
static TileJsonData tileJsonData = new TileJsonData();
|
||||
static TileJSONResponse tileJsonResponse;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var extrusionTypeProperty = property.FindPropertyRelative("extrusionType");
|
||||
var displayNames = extrusionTypeProperty.enumDisplayNames;
|
||||
int count = extrusionTypeProperty.enumDisplayNames.Length;
|
||||
|
||||
if (!isGUIContentSet)
|
||||
{
|
||||
extrusionTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
extrusionTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = EnumExtensions.Description((ExtrusionType)extIdx),
|
||||
};
|
||||
}
|
||||
isGUIContentSet = true;
|
||||
}
|
||||
|
||||
var extrusionTypeLabel = new GUIContent
|
||||
{
|
||||
text = "Extrusion Type",
|
||||
tooltip = "Type of geometry extrusion"
|
||||
};
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
extrusionTypeProperty.enumValueIndex = EditorGUILayout.Popup(extrusionTypeLabel, extrusionTypeProperty.enumValueIndex, extrusionTypeContent);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
var sourceTypeValue = (Unity.Map.ExtrusionType)extrusionTypeProperty.enumValueIndex;
|
||||
|
||||
var minHeightProperty = property.FindPropertyRelative("minimumHeight");
|
||||
var maxHeightProperty = property.FindPropertyRelative("maximumHeight");
|
||||
|
||||
var extrusionGeometryType = property.FindPropertyRelative("extrusionGeometryType");
|
||||
var extrusionGeometryGUI = new GUIContent { text = "Geometry Type", tooltip = EnumExtensions.Description((Unity.Map.ExtrusionGeometryType)extrusionGeometryType.enumValueIndex) };
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
switch (sourceTypeValue)
|
||||
{
|
||||
case Unity.Map.ExtrusionType.None:
|
||||
break;
|
||||
case Unity.Map.ExtrusionType.PropertyHeight:
|
||||
EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
|
||||
DrawPropertyDropDown(property, position);
|
||||
break;
|
||||
case Unity.Map.ExtrusionType.MinHeight:
|
||||
EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
|
||||
DrawPropertyDropDown(property, position);
|
||||
break;
|
||||
case Unity.Map.ExtrusionType.MaxHeight:
|
||||
EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
|
||||
DrawPropertyDropDown(property, position);
|
||||
break;
|
||||
case Unity.Map.ExtrusionType.RangeHeight:
|
||||
EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
|
||||
DrawPropertyDropDown(property, position);
|
||||
EditorGUILayout.PropertyField(minHeightProperty);
|
||||
EditorGUILayout.PropertyField(maxHeightProperty);
|
||||
if (minHeightProperty.floatValue > maxHeightProperty.floatValue)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Maximum Height less than Minimum Height!", MessageType.Error);
|
||||
}
|
||||
break;
|
||||
case Unity.Map.ExtrusionType.AbsoluteHeight:
|
||||
EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
|
||||
EditorGUILayout.PropertyField(maxHeightProperty, new GUIContent { text = "Height" });
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("extrusionScaleFactor"), new GUIContent { text = "Scale Factor" });
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private void DrawPropertyDropDown(SerializedProperty property, Rect position)
|
||||
{
|
||||
var selectedLayerName = property.FindPropertyRelative("_selectedLayerName").stringValue;
|
||||
|
||||
var serializedMapObject = property.serializedObject;
|
||||
AbstractMap mapObject = (AbstractMap)serializedMapObject.targetObject;
|
||||
tileJsonData = mapObject.VectorData.GetTileJsonData();
|
||||
|
||||
DrawPropertyName(property, position, selectedLayerName);
|
||||
}
|
||||
|
||||
private void DrawPropertyName(SerializedProperty property, Rect position, string selectedLayerName)
|
||||
{
|
||||
var parsedString = "No property selected";
|
||||
var descriptionString = "No description available";
|
||||
|
||||
if (string.IsNullOrEmpty(selectedLayerName) || tileJsonData == null || !tileJsonData.PropertyDisplayNames.ContainsKey(selectedLayerName))
|
||||
{
|
||||
DrawWarningMessage(position);
|
||||
}
|
||||
else
|
||||
{
|
||||
var propertyDisplayNames = tileJsonData.PropertyDisplayNames[selectedLayerName];
|
||||
_propertyNamesList = new List<string>(propertyDisplayNames);
|
||||
|
||||
//check if the selection is valid
|
||||
var propertyString = property.FindPropertyRelative("propertyName").stringValue;
|
||||
if (_propertyNamesList.Contains(propertyString))
|
||||
{
|
||||
//if the layer contains the current layerstring, set it's index to match
|
||||
_propertyIndex = propertyDisplayNames.FindIndex(s => s.Equals(propertyString));
|
||||
|
||||
|
||||
//create guicontent for a valid layer
|
||||
_propertyNameContent = new GUIContent[_propertyNamesList.Count];
|
||||
for (int extIdx = 0; extIdx < _propertyNamesList.Count; extIdx++)
|
||||
{
|
||||
var parsedPropertyString = _propertyNamesList[extIdx].Split(new string[] { tileJsonData.optionalPropertiesString }, System.StringSplitOptions.None)[0].Trim();
|
||||
_propertyNameContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = _propertyNamesList[extIdx],
|
||||
tooltip = tileJsonData.LayerPropertyDescriptionDictionary[selectedLayerName][parsedPropertyString]
|
||||
};
|
||||
}
|
||||
|
||||
//display popup
|
||||
var propertyNameLabel = new GUIContent { text = "Property Name", tooltip = "The name of the property in the selected Mapbox layer that will be used for extrusion" };
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
_propertyIndex = EditorGUILayout.Popup(propertyNameLabel, _propertyIndex, _propertyNameContent);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
//set new string values based on selection
|
||||
parsedString = _propertyNamesList[_propertyIndex].Split(new string[] { tileJsonData.optionalPropertiesString }, System.StringSplitOptions.None)[0].Trim();
|
||||
descriptionString = tileJsonData.LayerPropertyDescriptionDictionary[selectedLayerName][parsedString];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//if the selected layer isn't in the source, add a placeholder entry
|
||||
_propertyIndex = 0;
|
||||
_propertyNamesList.Insert(0, propertyString);
|
||||
|
||||
//create guicontent for an invalid layer
|
||||
_propertyNameContent = new GUIContent[_propertyNamesList.Count];
|
||||
|
||||
//first property gets a unique tooltip
|
||||
_propertyNameContent[0] = new GUIContent
|
||||
{
|
||||
text = _propertyNamesList[0],
|
||||
tooltip = "Unavialable in Selected Layer"
|
||||
};
|
||||
|
||||
for (int extIdx = 1; extIdx < _propertyNamesList.Count; extIdx++)
|
||||
{
|
||||
var parsedPropertyString = _propertyNamesList[extIdx].Split(new string[] { tileJsonData.optionalPropertiesString }, System.StringSplitOptions.None)[0].Trim();
|
||||
_propertyNameContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = _propertyNamesList[extIdx],
|
||||
tooltip = tileJsonData.LayerPropertyDescriptionDictionary[selectedLayerName][parsedPropertyString]
|
||||
};
|
||||
}
|
||||
|
||||
//display popup
|
||||
var propertyNameLabel = new GUIContent { text = "Property Name", tooltip = "The name of the property in the selected Mapbox layer that will be used for extrusion" };
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
_propertyIndex = EditorGUILayout.Popup(propertyNameLabel, _propertyIndex, _propertyNameContent);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
//set new string values based on the offset
|
||||
parsedString = _propertyNamesList[_propertyIndex].Split(new string[] { tileJsonData.optionalPropertiesString }, System.StringSplitOptions.None)[0].Trim();
|
||||
descriptionString = "Unavailable in Selected Layer.";
|
||||
|
||||
}
|
||||
|
||||
property.FindPropertyRelative("propertyName").stringValue = parsedString;
|
||||
property.FindPropertyRelative("propertyDescription").stringValue = descriptionString;
|
||||
|
||||
}
|
||||
|
||||
descriptionString = string.IsNullOrEmpty(descriptionString) ? "No description available" : descriptionString;
|
||||
|
||||
var propertyDescriptionPrefixLabel = new GUIContent { text = "Property Description", tooltip = "Factual information about the selected property" };
|
||||
EditorGUILayout.LabelField(propertyDescriptionPrefixLabel, new GUIContent(descriptionString), (GUIStyle)"wordWrappedLabel");
|
||||
}
|
||||
|
||||
private void DrawWarningMessage(Rect position)
|
||||
{
|
||||
GUIStyle labelStyle = new GUIStyle(EditorStyles.popup);
|
||||
labelStyle.fontStyle = FontStyle.Bold;
|
||||
var layerNameLabel = new GUIContent { text = "Property Name", tooltip = "The name of the property in the selected Mapbox layer that will be used for extrusion" };
|
||||
EditorGUILayout.LabelField(layerNameLabel, new GUIContent("No properties found in layer"), labelStyle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d66413ab6b7d648e2ba3cfd4e1d72382
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,239 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity;
|
||||
using Mapbox.Editor;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class StyleIconBundle
|
||||
{
|
||||
public string path;
|
||||
public Texture texture;
|
||||
public void Load()
|
||||
{
|
||||
if (texture == null)
|
||||
{
|
||||
texture = Resources.Load(path) as Texture;
|
||||
}
|
||||
}
|
||||
|
||||
public StyleIconBundle(string styleName, string paletteName = "")
|
||||
{
|
||||
path = Path.Combine(Constants.Path.MAP_FEATURE_STYLES_SAMPLES, Path.Combine(styleName, string.Format("{0}Icon", (styleName + paletteName))));
|
||||
}
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(GeometryMaterialOptions))]
|
||||
public class GeometryMaterialOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
private string objectId = "";
|
||||
bool showTexturing
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "VectorSubLayerProperties_showTexturing");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "VectorSubLayerProperties_showTexturing", value);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<StyleTypes, StyleIconBundle> _styleIconBundles = new Dictionary<StyleTypes, StyleIconBundle>()
|
||||
{
|
||||
{StyleTypes.Simple, new StyleIconBundle(StyleTypes.Simple.ToString())},
|
||||
{StyleTypes.Realistic, new StyleIconBundle(StyleTypes.Realistic.ToString())},
|
||||
{StyleTypes.Fantasy, new StyleIconBundle(StyleTypes.Fantasy.ToString())},
|
||||
{StyleTypes.Light, new StyleIconBundle(StyleTypes.Light.ToString())},
|
||||
{StyleTypes.Dark, new StyleIconBundle(StyleTypes.Dark.ToString())},
|
||||
{StyleTypes.Color, new StyleIconBundle(StyleTypes.Color.ToString())},
|
||||
{StyleTypes.Satellite, new StyleIconBundle(StyleTypes.Satellite.ToString())},
|
||||
};
|
||||
|
||||
private Dictionary<SamplePalettes, StyleIconBundle> _paletteIconBundles = new Dictionary<SamplePalettes, StyleIconBundle>()
|
||||
{
|
||||
{SamplePalettes.City, new StyleIconBundle(StyleTypes.Simple.ToString(), SamplePalettes.City.ToString())},
|
||||
{SamplePalettes.Cool, new StyleIconBundle(StyleTypes.Simple.ToString(), SamplePalettes.Cool.ToString())},
|
||||
{SamplePalettes.Rainbow, new StyleIconBundle(StyleTypes.Simple.ToString(), SamplePalettes.Rainbow.ToString())},
|
||||
{SamplePalettes.Urban, new StyleIconBundle(StyleTypes.Simple.ToString(), SamplePalettes.Urban.ToString())},
|
||||
{SamplePalettes.Warm, new StyleIconBundle(StyleTypes.Simple.ToString(), SamplePalettes.Warm.ToString())},
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Loads the default style icons.
|
||||
/// </summary>
|
||||
|
||||
private void LoadDefaultStyleIcons()
|
||||
{
|
||||
foreach (var key in _styleIconBundles.Keys)
|
||||
{
|
||||
_styleIconBundles[key].Load();
|
||||
}
|
||||
foreach (var key in _paletteIconBundles.Keys)
|
||||
{
|
||||
_paletteIconBundles[key].Load();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
|
||||
objectId = property.serializedObject.targetObject.GetInstanceID().ToString();
|
||||
|
||||
showTexturing = EditorGUILayout.Foldout(showTexturing, new GUIContent { text = "Texturing", tooltip = "Material options to texture the generated building geometry" });
|
||||
if (showTexturing)
|
||||
{
|
||||
LoadDefaultStyleIcons();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
var styleTypeLabel = new GUIContent { text = "Style Type", tooltip = "Texturing style for feature; choose from sample style or create your own by choosing Custom. " };
|
||||
var styleType = property.FindPropertyRelative("style");
|
||||
|
||||
GUIContent[] styleTypeGuiContent = new GUIContent[styleType.enumDisplayNames.Length];
|
||||
for (int i = 0; i < styleType.enumDisplayNames.Length; i++)
|
||||
{
|
||||
styleTypeGuiContent[i] = new GUIContent
|
||||
{
|
||||
text = styleType.enumDisplayNames[i]
|
||||
};
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
styleType.enumValueIndex = EditorGUILayout.Popup(styleTypeLabel, styleType.enumValueIndex, styleTypeGuiContent);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if ((StyleTypes)styleType.enumValueIndex != StyleTypes.Custom)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
var style = (StyleTypes)styleType.enumValueIndex;
|
||||
|
||||
Texture2D thumbnailTexture = (Texture2D)_styleIconBundles[style].texture;
|
||||
|
||||
if ((StyleTypes)styleType.enumValueIndex == StyleTypes.Simple)
|
||||
{
|
||||
var samplePaletteType = property.FindPropertyRelative("samplePalettes");
|
||||
var palette = (SamplePalettes)samplePaletteType.enumValueIndex;
|
||||
thumbnailTexture = (Texture2D)_paletteIconBundles[palette].texture;
|
||||
}
|
||||
|
||||
string descriptionLabel = EnumExtensions.Description(style);
|
||||
EditorGUILayout.LabelField(new GUIContent(" ", thumbnailTexture), Constants.GUI.Styles.EDITOR_TEXTURE_THUMBNAIL_STYLE, GUILayout.Height(60), GUILayout.Width(EditorGUIUtility.labelWidth - 60));
|
||||
EditorGUILayout.TextArea(descriptionLabel, (GUIStyle)"wordWrappedLabel");
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
switch ((StyleTypes)styleType.enumValueIndex)
|
||||
{
|
||||
case StyleTypes.Simple:
|
||||
var samplePaletteType = property.FindPropertyRelative("samplePalettes");
|
||||
var samplePaletteTypeLabel = new GUIContent { text = "Palette Type", tooltip = "Palette type for procedural colorization; choose from sample palettes or create your own by choosing Custom. " };
|
||||
|
||||
GUIContent[] samplePaletteTypeGuiContent = new GUIContent[samplePaletteType.enumDisplayNames.Length];
|
||||
for (int i = 0; i < samplePaletteType.enumDisplayNames.Length; i++)
|
||||
{
|
||||
samplePaletteTypeGuiContent[i] = new GUIContent
|
||||
{
|
||||
text = samplePaletteType.enumDisplayNames[i]
|
||||
};
|
||||
}
|
||||
samplePaletteType.enumValueIndex = EditorGUILayout.Popup(samplePaletteTypeLabel, samplePaletteType.enumValueIndex, samplePaletteTypeGuiContent);
|
||||
break;
|
||||
case StyleTypes.Light:
|
||||
property.FindPropertyRelative("lightStyleOpacity").floatValue = EditorGUILayout.Slider("Opacity", property.FindPropertyRelative("lightStyleOpacity").floatValue, 0.0f, 1.0f);
|
||||
break;
|
||||
case StyleTypes.Dark:
|
||||
property.FindPropertyRelative("darkStyleOpacity").floatValue = EditorGUILayout.Slider("Opacity", property.FindPropertyRelative("darkStyleOpacity").floatValue, 0.0f, 1.0f);
|
||||
break;
|
||||
case StyleTypes.Color:
|
||||
property.FindPropertyRelative("colorStyleColor").colorValue = EditorGUILayout.ColorField("Color", property.FindPropertyRelative("colorStyleColor").colorValue);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var customStyleProperty = property.FindPropertyRelative("customStyleOptions");
|
||||
var texturingType = customStyleProperty.FindPropertyRelative("texturingType");
|
||||
|
||||
int valIndex = texturingType.enumValueIndex == 0 ? 0 : texturingType.enumValueIndex + 1;
|
||||
var texturingTypeGUI = new GUIContent { text = "Texturing Type", tooltip = EnumExtensions.Description((UvMapType)valIndex) };
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(texturingType, texturingTypeGUI);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
var matList = customStyleProperty.FindPropertyRelative("materials");
|
||||
if (matList.arraySize == 0)
|
||||
{
|
||||
matList.arraySize = 2;
|
||||
}
|
||||
GUILayout.Space(-lineHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(matList.GetArrayElementAtIndex(0), new GUIContent { text = "Top Material", tooltip = "Unity material to use for extruded top/roof mesh. " });
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
|
||||
GUILayout.Space(-lineHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(matList.GetArrayElementAtIndex(1), new GUIContent { text = "Side Material", tooltip = "Unity material to use for extruded side/wall mesh. " });
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
if ((UvMapType)texturingType.enumValueIndex + 1 == UvMapType.Atlas)
|
||||
{
|
||||
var atlasInfo = customStyleProperty.FindPropertyRelative("atlasInfo");
|
||||
EditorGUILayout.ObjectField(atlasInfo, new GUIContent { text = "Altas Info", tooltip = "Atlas information scriptable object, this defines how the texture roof and wall texture atlases will be used. " });
|
||||
}
|
||||
if ((UvMapType)texturingType.enumValueIndex + 1 == UvMapType.AtlasWithColorPalette)
|
||||
{
|
||||
var atlasInfo = customStyleProperty.FindPropertyRelative("atlasInfo");
|
||||
EditorGUILayout.ObjectField(atlasInfo, new GUIContent { text = "Altas Info", tooltip = "Atlas information scriptable object, this defines how the texture roof and wall texture atlases will be used. " });
|
||||
|
||||
var colorPalette = customStyleProperty.FindPropertyRelative("colorPalette");
|
||||
EditorGUILayout.ObjectField(colorPalette, new GUIContent { text = "Color Palette", tooltip = "Color palette scriptable object, allows texture features to be procedurally colored at runtime. Requires materials that use the MapboxPerRenderer shader. " });
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent { text = "Note: Atlas With Color Palette requires materials that use the MapboxPerRenderer shader." }, Constants.GUI.Styles.EDITOR_NOTE_STYLE);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8e9adb2cd7094d48acbefb75a01436b
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,97 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
|
||||
[CustomPropertyDrawer(typeof(ImageryLayerProperties))]
|
||||
public class ImageryLayerPropertiesDrawer : PropertyDrawer
|
||||
{
|
||||
GUIContent[] sourceTypeContent;
|
||||
bool isGUIContentSet = false;
|
||||
|
||||
private GUIContent _tilesetIdGui = new GUIContent
|
||||
{
|
||||
text = "Tileset Id",
|
||||
tooltip = "Id of the tileset."
|
||||
};
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var sourceTypeProperty = property.FindPropertyRelative("sourceType");
|
||||
var sourceTypeValue = (ImagerySourceType)sourceTypeProperty.enumValueIndex;
|
||||
|
||||
var displayNames = sourceTypeProperty.enumDisplayNames;
|
||||
int count = sourceTypeProperty.enumDisplayNames.Length;
|
||||
if (!isGUIContentSet)
|
||||
{
|
||||
sourceTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
sourceTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = EnumExtensions.Description((ImagerySourceType)extIdx),
|
||||
};
|
||||
}
|
||||
isGUIContentSet = true;
|
||||
}
|
||||
|
||||
// Draw label.
|
||||
var sourceTypeLabel = new GUIContent { text = "Data Source", tooltip = "Source tileset for Imagery." };
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(sourceTypeLabel, sourceTypeProperty.enumValueIndex, sourceTypeContent);
|
||||
if(EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
sourceTypeValue = (ImagerySourceType)sourceTypeProperty.enumValueIndex;
|
||||
|
||||
var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
|
||||
var layerSourceProperty = sourceOptionsProperty.FindPropertyRelative("layerSource");
|
||||
var layerSourceId = layerSourceProperty.FindPropertyRelative("Id");
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
switch (sourceTypeValue)
|
||||
{
|
||||
case ImagerySourceType.MapboxStreets:
|
||||
case ImagerySourceType.MapboxOutdoors:
|
||||
case ImagerySourceType.MapboxDark:
|
||||
case ImagerySourceType.MapboxLight:
|
||||
case ImagerySourceType.MapboxSatellite:
|
||||
case ImagerySourceType.MapboxSatelliteStreet:
|
||||
var sourcePropertyValue = MapboxDefaultImagery.GetParameters(sourceTypeValue);
|
||||
layerSourceId.stringValue = sourcePropertyValue.Id;
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(sourceOptionsProperty, _tilesetIdGui);
|
||||
GUI.enabled = true;
|
||||
break;
|
||||
case ImagerySourceType.Custom:
|
||||
EditorGUILayout.PropertyField(sourceOptionsProperty, new GUIContent { text = "Tileset Id / Style URL", tooltip = _tilesetIdGui.tooltip });
|
||||
break;
|
||||
case ImagerySourceType.None:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
if (sourceTypeValue != ImagerySourceType.None)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("rasterOptions"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d00c4bf63fb7481bba0b0a96c4e9b03
|
||||
timeCreated: 1517889179
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(ImageryRasterOptions))]
|
||||
public class ImageryRasterOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
bool showPosition = true;
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
position.height = lineHeight;
|
||||
foreach (var item in property)
|
||||
{
|
||||
var subproperty = item as SerializedProperty;
|
||||
EditorGUI.PropertyField(position, subproperty, true);
|
||||
position.height = lineHeight;
|
||||
position.y += lineHeight;
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
int rows = (showPosition) ? 3 : 1;
|
||||
return (float)rows * lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6eff4b0718ee34d37913417f65afad08
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(LayerPerformanceOptions))]
|
||||
public class LayerPerformanceOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
SerializedProperty isActiveProperty;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
isActiveProperty = property.FindPropertyRelative("isEnabled");
|
||||
|
||||
isActiveProperty.boolValue = EditorGUILayout.Toggle(new GUIContent("Enable Coroutines"), isActiveProperty.boolValue);
|
||||
|
||||
if (isActiveProperty.boolValue == true)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("entityPerCoroutine"), true);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16db3da0a971247e79b6bb10e0d26862
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(LayerSourceOptions))]
|
||||
public class LayerSourceOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
position.height = lineHeight;
|
||||
EditorGUI.PropertyField(position, property.FindPropertyRelative("layerSource"), label);
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66a87ffd5023a4fbe889f65e3fdcb4ac
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
|
||||
[CustomPropertyDrawer(typeof(LineGeometryOptions))]
|
||||
public class LineGeometryOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("Width"));
|
||||
property.FindPropertyRelative("JoinType").enumValueIndex = (int)((LineJoinType)EditorGUILayout.EnumPopup("Join Type", (LineJoinType)property.FindPropertyRelative("JoinType").intValue));
|
||||
if (property.FindPropertyRelative("JoinType").enumValueIndex == (int)LineJoinType.Miter || property.FindPropertyRelative("JoinType").enumValueIndex == (int)LineJoinType.Bevel)
|
||||
{
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("MiterLimit"));
|
||||
}
|
||||
else if (property.FindPropertyRelative("JoinType").enumValueIndex == (int)LineJoinType.Round)
|
||||
{
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("RoundLimit"));
|
||||
}
|
||||
|
||||
property.FindPropertyRelative("CapType").enumValueIndex = (int)((LineCapType)EditorGUILayout.EnumPopup("Cap Type", (LineCapType)property.FindPropertyRelative("CapType").intValue));
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81806f31401d69747ba09bd8aa3e4c73
|
||||
timeCreated: 1537464920
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
|
||||
[CustomPropertyDrawer(typeof(MapExtentOptions))]
|
||||
public class MapExtentOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static string extTypePropertyName = "extentType";
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
GUIContent[] extentTypeContent;
|
||||
bool isGUIContentSet = false;
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var kindProperty = property.FindPropertyRelative(extTypePropertyName);
|
||||
var displayNames = kindProperty.enumDisplayNames;
|
||||
int count = kindProperty.enumDisplayNames.Length;
|
||||
if (!isGUIContentSet)
|
||||
{
|
||||
extentTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
extentTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = EnumExtensions.Description((MapExtentType)extIdx),
|
||||
};
|
||||
}
|
||||
isGUIContentSet = true;
|
||||
}
|
||||
// Draw label.
|
||||
var extentTypeLabel = new GUIContent
|
||||
{
|
||||
text = label.text,
|
||||
tooltip = "Options to determine the geographic extent of the world for which the map tiles will be requested.",
|
||||
};
|
||||
EditorGUI.BeginChangeCheck();
|
||||
kindProperty.enumValueIndex = EditorGUILayout.Popup(extentTypeLabel, kindProperty.enumValueIndex, extentTypeContent, GUILayout.Height(_lineHeight));
|
||||
|
||||
var kind = (MapExtentType)kindProperty.enumValueIndex;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
GUILayout.Space(-_lineHeight);
|
||||
SerializedProperty defaultExtentsProp = property.FindPropertyRelative("defaultExtents");
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
case MapExtentType.CameraBounds:
|
||||
GUILayout.Space(_lineHeight);
|
||||
EditorGUILayout.PropertyField(defaultExtentsProp.FindPropertyRelative("cameraBoundsOptions"), new GUIContent { text = "CameraOptions-" });
|
||||
break;
|
||||
case MapExtentType.RangeAroundCenter:
|
||||
EditorGUILayout.PropertyField(defaultExtentsProp.FindPropertyRelative("rangeAroundCenterOptions"), new GUIContent { text = "RangeAroundCenter" });
|
||||
break;
|
||||
case MapExtentType.RangeAroundTransform:
|
||||
GUILayout.Space(_lineHeight);
|
||||
EditorGUILayout.PropertyField(defaultExtentsProp.FindPropertyRelative("rangeAroundTransformOptions"), new GUIContent { text = "RangeAroundTransform" });
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(defaultExtentsProp);
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61582b113819848348a7a1a629916371
|
||||
timeCreated: 1517858264
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(MapLocationOptions))]
|
||||
public class MapLocationOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
GUILayout.Space(-1f * _lineHeight);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("latitudeLongitude"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("zoom"), GUILayout.Height(_lineHeight));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cba048f4ed8d1458e88aee6ae0ae4226
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
using Mapbox.Unity.Map.TileProviders;
|
||||
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
[CustomPropertyDrawer(typeof(MapOptions))]
|
||||
public class MapOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
bool showPosition = false;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
position.height = lineHeight;
|
||||
EditorGUI.LabelField(position, "Location ");
|
||||
position.y += lineHeight;
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("locationOptions"));
|
||||
position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("locationOptions"));
|
||||
var extentOptions = property.FindPropertyRelative("extentOptions");
|
||||
var extentOptionsType = extentOptions.FindPropertyRelative("extentType");
|
||||
if ((MapExtentType)extentOptionsType.enumValueIndex == MapExtentType.Custom)
|
||||
{
|
||||
var test = property.serializedObject.FindProperty("_tileProvider");
|
||||
|
||||
EditorGUI.PropertyField(position, test);
|
||||
position.y += lineHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(position, property.FindPropertyRelative("extentOptions"));
|
||||
|
||||
position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("extentOptions"));
|
||||
}
|
||||
|
||||
showPosition = EditorGUI.Foldout(position, showPosition, "Others");
|
||||
if (showPosition)
|
||||
{
|
||||
position.y += lineHeight;
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("placementOptions"));
|
||||
|
||||
position.y += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("placementOptions"));
|
||||
EditorGUI.PropertyField(position, property.FindPropertyRelative("scalingOptions"));
|
||||
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Reserve space for the total visible properties.
|
||||
float height = 2.0f * lineHeight;
|
||||
if (showPosition)
|
||||
{
|
||||
height += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("placementOptions"));
|
||||
height += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("scalingOptions"));
|
||||
}
|
||||
height += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("locationOptions"));
|
||||
height += EditorGUI.GetPropertyHeight(property.FindPropertyRelative("extentOptions"));
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(AbstractTileProvider))]
|
||||
public class AbstractTileProviderDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
EditorGUI.ObjectField(position, property);
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f76f257073bf49efbf18d1e75531f2a
|
||||
timeCreated: 1520010402
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
|
||||
[CustomPropertyDrawer(typeof(MapPlacementOptions))]
|
||||
public class MapPlacementOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
GUIContent[] placementTypeContent;
|
||||
bool isGUIContentSet = false;
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var placementType = property.FindPropertyRelative("placementType");
|
||||
var snapMapToTerrain = property.FindPropertyRelative("snapMapToZero");
|
||||
|
||||
var displayNames = placementType.enumDisplayNames;
|
||||
int count = placementType.enumDisplayNames.Length;
|
||||
if (!isGUIContentSet)
|
||||
{
|
||||
placementTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
placementTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = EnumExtensions.Description((MapPlacementType)extIdx),
|
||||
};
|
||||
}
|
||||
isGUIContentSet = true;
|
||||
}
|
||||
|
||||
placementType.enumValueIndex = EditorGUILayout.Popup(new GUIContent { text = label.text, tooltip = "Placement of Map root.", }, placementType.enumValueIndex, placementTypeContent);
|
||||
EditorGUILayout.PropertyField(snapMapToTerrain, new GUIContent { text = snapMapToTerrain.displayName, tooltip = "If checked, map's root will be snapped to zero. " });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5156142fbca0a4c7bbc4b5949bd9a004
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
|
||||
[CustomPropertyDrawer(typeof(MapScalingOptions))]
|
||||
public class MapScalingOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
GUIContent[] scalingTypeContent;
|
||||
bool isGUIContentSet = false;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var scalingType = property.FindPropertyRelative("scalingType");
|
||||
var displayNames = scalingType.enumDisplayNames;
|
||||
int count = scalingType.enumDisplayNames.Length;
|
||||
if (!isGUIContentSet)
|
||||
{
|
||||
scalingTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
scalingTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = EnumExtensions.Description((MapScalingType)extIdx),
|
||||
};
|
||||
}
|
||||
isGUIContentSet = true;
|
||||
}
|
||||
|
||||
// Draw label.
|
||||
var scalingTypeLabel = new GUIContent { text = label.text, tooltip = "Scale of map in game units.", };
|
||||
|
||||
scalingType.enumValueIndex = EditorGUILayout.Popup(scalingTypeLabel, scalingType.enumValueIndex, scalingTypeContent);
|
||||
|
||||
if ((MapScalingType)scalingType.enumValueIndex == MapScalingType.Custom)
|
||||
{
|
||||
position.y += lineHeight;
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("unityTileSize"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3273da310cf694e0982177c792acf843
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
|
||||
[CustomPropertyDrawer(typeof(MaterialList))]
|
||||
public class MaterialListDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
var matArray = property.FindPropertyRelative("Materials");
|
||||
if (matArray.arraySize == 0)
|
||||
{
|
||||
matArray.arraySize = 1;
|
||||
}
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("Materials").GetArrayElementAtIndex(0), label);
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac4d01f35c9334c9f90ce5c57523f06c
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Editor;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
|
||||
public class ModelingSectionDrawer
|
||||
{
|
||||
private string objectId = "";
|
||||
bool showModeling
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetBool(objectId + "VectorSubLayerProperties_showModeling");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetBool(objectId + "VectorSubLayerProperties_showModeling", value);
|
||||
}
|
||||
}
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public void DrawUI(SerializedProperty subLayerCoreOptions, SerializedProperty layerProperty, VectorPrimitiveType primitiveTypeProp)
|
||||
{
|
||||
|
||||
objectId = layerProperty.serializedObject.targetObject.GetInstanceID().ToString();
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
showModeling = EditorGUILayout.Foldout(showModeling, new GUIContent { text = "Modeling", tooltip = "This section provides you with options to fine tune your meshes" });
|
||||
if (showModeling)
|
||||
{
|
||||
GUILayout.Space(-_lineHeight);
|
||||
EditorGUILayout.PropertyField(subLayerCoreOptions);
|
||||
|
||||
if (primitiveTypeProp == VectorPrimitiveType.Line)
|
||||
{
|
||||
GUILayout.Space(-_lineHeight);
|
||||
var lineGeometryOptions = layerProperty.FindPropertyRelative("lineGeometryOptions");
|
||||
EditorGUILayout.PropertyField(lineGeometryOptions);
|
||||
}
|
||||
|
||||
if (primitiveTypeProp != VectorPrimitiveType.Point && primitiveTypeProp != VectorPrimitiveType.Custom)
|
||||
{
|
||||
GUILayout.Space(-_lineHeight);
|
||||
var extrusionOptions = layerProperty.FindPropertyRelative("extrusionOptions");
|
||||
extrusionOptions.FindPropertyRelative("_selectedLayerName").stringValue = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue;
|
||||
EditorGUILayout.PropertyField(extrusionOptions);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var snapToTerrainProperty = subLayerCoreOptions.FindPropertyRelative("snapToTerrain");
|
||||
snapToTerrainProperty.boolValue = EditorGUILayout.Toggle(snapToTerrainProperty.displayName, snapToTerrainProperty.boolValue);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(subLayerCoreOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (primitiveTypeProp != VectorPrimitiveType.Point)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var combineMeshesProperty = subLayerCoreOptions.FindPropertyRelative("combineMeshes");
|
||||
combineMeshesProperty.boolValue = EditorGUILayout.Toggle(combineMeshesProperty.displayName, combineMeshesProperty.boolValue);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(subLayerCoreOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (primitiveTypeProp != VectorPrimitiveType.Point && primitiveTypeProp != VectorPrimitiveType.Custom)
|
||||
{
|
||||
GUILayout.Space(-_lineHeight);
|
||||
|
||||
var colliderOptionsProperty = layerProperty.FindPropertyRelative("colliderOptions");
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(colliderOptionsProperty);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Debug.Log("Collider UI changed");
|
||||
EditorHelper.CheckForModifiedProperty(colliderOptionsProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39f85c0d2d7cb4b5e989cf0edd7109a9
|
||||
timeCreated: 1529620234
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,232 @@
|
||||
namespace Mapbox.Unity.Map
|
||||
{
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using Mapbox.Editor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using System.Linq;
|
||||
|
||||
public class PointsOfInterestSubLayerPropertiesDrawer
|
||||
{
|
||||
string objectId = "";
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
FeatureSubLayerTreeView layerTreeView;
|
||||
IList<int> selectedLayers = new List<int>();
|
||||
|
||||
private TreeModel<FeatureTreeElement> treeModel;
|
||||
[SerializeField]
|
||||
TreeViewState m_TreeViewState;
|
||||
|
||||
[SerializeField]
|
||||
MultiColumnHeaderState m_MultiColumnHeaderState;
|
||||
|
||||
bool m_Initialized = false;
|
||||
public bool isLayerAdded = false;
|
||||
|
||||
int SelectionIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetInt(objectId + "LocationPrefabsLayerProperties_selectionIndex");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetInt(objectId + "LocationPrefabsLayerProperties_selectionIndex", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawUI(SerializedProperty property)
|
||||
{
|
||||
objectId = property.serializedObject.targetObject.GetInstanceID().ToString();
|
||||
var prefabItemArray = property.FindPropertyRelative("locationPrefabList");
|
||||
var layersRect = EditorGUILayout.GetControlRect(GUILayout.MinHeight(Mathf.Max(prefabItemArray.arraySize + 1, 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight),
|
||||
GUILayout.MaxHeight((prefabItemArray.arraySize + 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight));
|
||||
|
||||
if (!m_Initialized)
|
||||
{
|
||||
bool firstInit = m_MultiColumnHeaderState == null;
|
||||
var headerState = FeatureSubLayerTreeView.CreateDefaultMultiColumnHeaderState();
|
||||
if (MultiColumnHeaderState.CanOverwriteSerializedFields(m_MultiColumnHeaderState, headerState))
|
||||
{
|
||||
MultiColumnHeaderState.OverwriteSerializedFields(m_MultiColumnHeaderState, headerState);
|
||||
}
|
||||
m_MultiColumnHeaderState = headerState;
|
||||
|
||||
var multiColumnHeader = new FeatureSectionMultiColumnHeader(headerState);
|
||||
|
||||
if (firstInit)
|
||||
{
|
||||
multiColumnHeader.ResizeToFit();
|
||||
}
|
||||
|
||||
treeModel = new TreeModel<FeatureTreeElement>(GetData(prefabItemArray));
|
||||
if (m_TreeViewState == null)
|
||||
{
|
||||
m_TreeViewState = new TreeViewState();
|
||||
}
|
||||
|
||||
if (layerTreeView == null)
|
||||
{
|
||||
layerTreeView = new FeatureSubLayerTreeView(m_TreeViewState, multiColumnHeader, treeModel, FeatureSubLayerTreeView.uniqueIdPoI);
|
||||
}
|
||||
layerTreeView.multiColumnHeader = multiColumnHeader;
|
||||
m_Initialized = true;
|
||||
}
|
||||
|
||||
|
||||
layerTreeView.Layers = prefabItemArray;
|
||||
layerTreeView.Reload();
|
||||
layerTreeView.OnGUI(layersRect);
|
||||
|
||||
if (layerTreeView.hasChanged)
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
layerTreeView.hasChanged = false;
|
||||
}
|
||||
|
||||
selectedLayers = layerTreeView.GetSelection();
|
||||
//if there are selected elements, set the selection index at the first element.
|
||||
//if not, use the Selection index to persist the selection at the right index.
|
||||
if (selectedLayers.Count > 0)
|
||||
{
|
||||
//ensure that selectedLayers[0] isn't out of bounds
|
||||
if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdPoI > prefabItemArray.arraySize - 1)
|
||||
{
|
||||
selectedLayers[0] = prefabItemArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdPoI;
|
||||
}
|
||||
|
||||
SelectionIndex = selectedLayers[0];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedLayers = new int[1] { SelectionIndex };
|
||||
if (SelectionIndex > 0 && (SelectionIndex - FeatureSubLayerTreeView.uniqueIdPoI <= prefabItemArray.arraySize - 1))
|
||||
{
|
||||
layerTreeView.SetSelection(selectedLayers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GUILayout.Space(EditorGUIUtility.singleLineHeight);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Add Layer"), (GUIStyle)"minibuttonleft"))
|
||||
{
|
||||
prefabItemArray.arraySize++;
|
||||
|
||||
var prefabItem = prefabItemArray.GetArrayElementAtIndex(prefabItemArray.arraySize - 1);
|
||||
var prefabItemName = prefabItem.FindPropertyRelative("coreOptions.sublayerName");
|
||||
|
||||
prefabItemName.stringValue = "New Location";
|
||||
|
||||
// Set defaults here because SerializedProperty copies the previous element.
|
||||
prefabItem.FindPropertyRelative("coreOptions.isActive").boolValue = true;
|
||||
prefabItem.FindPropertyRelative("coreOptions.snapToTerrain").boolValue = true;
|
||||
prefabItem.FindPropertyRelative("presetFeatureType").enumValueIndex = (int)PresetFeatureType.Points;
|
||||
var categories = prefabItem.FindPropertyRelative("categories");
|
||||
categories.intValue = (int)(LocationPrefabCategories.AnyCategory);//To select any category option
|
||||
|
||||
var density = prefabItem.FindPropertyRelative("density");
|
||||
density.intValue = 15;//To select all locations option
|
||||
|
||||
//Refreshing the tree
|
||||
layerTreeView.Layers = prefabItemArray;
|
||||
layerTreeView.AddElementToTree(prefabItem);
|
||||
layerTreeView.Reload();
|
||||
|
||||
selectedLayers = new int[1] { prefabItemArray.arraySize - 1 };
|
||||
layerTreeView.SetSelection(selectedLayers);
|
||||
|
||||
if (EditorHelper.DidModifyProperty(property))
|
||||
{
|
||||
isLayerAdded = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright"))
|
||||
{
|
||||
foreach (var index in selectedLayers.OrderByDescending(i => i))
|
||||
{
|
||||
if (layerTreeView != null)
|
||||
{
|
||||
var poiSubLayer = prefabItemArray.GetArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdPoI);
|
||||
|
||||
VectorLayerProperties vectorLayerProperties = (VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property);
|
||||
PrefabItemOptions poiSubLayerProperties = (PrefabItemOptions)EditorHelper.GetTargetObjectOfProperty(poiSubLayer);
|
||||
|
||||
vectorLayerProperties.OnSubLayerPropertyRemoved(new VectorLayerUpdateArgs { property = poiSubLayerProperties });
|
||||
|
||||
layerTreeView.RemoveItemFromTree(index);
|
||||
prefabItemArray.DeleteArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdPoI);
|
||||
layerTreeView.treeModel.SetData(GetData(prefabItemArray));
|
||||
}
|
||||
}
|
||||
selectedLayers = new int[0];
|
||||
layerTreeView.SetSelection(selectedLayers);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if (selectedLayers.Count == 1 && prefabItemArray.arraySize != 0 && selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdPoI >= 0)
|
||||
{
|
||||
//ensure that selectedLayers[0] isn't out of bounds
|
||||
if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdPoI > prefabItemArray.arraySize - 1)
|
||||
{
|
||||
selectedLayers[0] = prefabItemArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdPoI;
|
||||
}
|
||||
SelectionIndex = selectedLayers[0];
|
||||
|
||||
var layerProperty = prefabItemArray.GetArrayElementAtIndex(SelectionIndex - FeatureSubLayerTreeView.uniqueIdPoI);
|
||||
|
||||
layerProperty.isExpanded = true;
|
||||
var subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions");
|
||||
bool isLayerActive = subLayerCoreOptions.FindPropertyRelative("isActive").boolValue;
|
||||
if (!isLayerActive)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
}
|
||||
DrawLayerLocationPrefabProperties(layerProperty, property);
|
||||
if (!isLayerActive)
|
||||
{
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Space(15);
|
||||
GUILayout.Label("Select a visualizer to see properties");
|
||||
}
|
||||
}
|
||||
|
||||
void DrawLayerLocationPrefabProperties(SerializedProperty layerProperty, SerializedProperty property)
|
||||
{
|
||||
EditorGUILayout.PropertyField(layerProperty);
|
||||
}
|
||||
|
||||
IList<FeatureTreeElement> GetData(SerializedProperty subLayerArray)
|
||||
{
|
||||
List<FeatureTreeElement> elements = new List<FeatureTreeElement>();
|
||||
string name = string.Empty;
|
||||
string type = string.Empty;
|
||||
int id = 0;
|
||||
var root = new FeatureTreeElement("Root", -1, 0);
|
||||
elements.Add(root);
|
||||
for (int i = 0; i < subLayerArray.arraySize; i++)
|
||||
{
|
||||
var subLayer = subLayerArray.GetArrayElementAtIndex(i);
|
||||
name = subLayer.FindPropertyRelative("coreOptions.sublayerName").stringValue;
|
||||
id = i + FeatureSubLayerTreeView.uniqueIdPoI;
|
||||
type = PresetFeatureType.Points.ToString();
|
||||
FeatureTreeElement element = new FeatureTreeElement(name, 0, id);
|
||||
element.Name = name;
|
||||
element.name = name;
|
||||
element.Type = type;
|
||||
elements.Add(element);
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20fb110d2102743939c89f5a3ab9c3a4
|
||||
timeCreated: 1525818946
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,223 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.VectorTile.ExtensionMethods;
|
||||
|
||||
[CustomPropertyDrawer(typeof(PrefabItemOptions))]
|
||||
public class PrefabItemOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
const string searchButtonContent = "Search";
|
||||
|
||||
private GUIContent prefabLocationsTitle = new GUIContent
|
||||
{
|
||||
text = "Prefab Locations",
|
||||
tooltip = "Where on the map to spawn the selected prefab"
|
||||
};
|
||||
|
||||
|
||||
private GUIContent findByDropDown = new GUIContent
|
||||
{
|
||||
text = "Find by",
|
||||
tooltip = "Find points-of-interest by category, name, or address"
|
||||
};
|
||||
|
||||
private GUIContent categoriesDropDown = new GUIContent
|
||||
{
|
||||
text = "Category",
|
||||
tooltip = "Spawn at locations in the categories selected"
|
||||
};
|
||||
|
||||
private GUIContent densitySlider = new GUIContent
|
||||
{
|
||||
text = "Density",
|
||||
tooltip = "The number of prefabs to spawn per-tile; try a lower number if the map is cluttered"
|
||||
};
|
||||
|
||||
private GUIContent nameField = new GUIContent
|
||||
{
|
||||
text = "Name",
|
||||
tooltip = "Spawn at locations containing this name string"
|
||||
};
|
||||
|
||||
GUIContent[] findByPropContent;
|
||||
bool isGUIContentSet = false;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
GUILayout.Space(-_lineHeight);
|
||||
var prefabItemCoreOptions = property.FindPropertyRelative("coreOptions");
|
||||
GUILayout.Label(prefabItemCoreOptions.FindPropertyRelative("sublayerName").stringValue + " Properties");
|
||||
|
||||
//Prefab Game Object
|
||||
EditorGUI.indentLevel++;
|
||||
var spawnPrefabOptions = property.FindPropertyRelative("spawnPrefabOptions");
|
||||
|
||||
EditorGUILayout.PropertyField(spawnPrefabOptions);
|
||||
|
||||
GUILayout.Space(1);
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
//Prefab Locations title
|
||||
GUILayout.Label(prefabLocationsTitle);
|
||||
|
||||
//FindBy drop down
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
var findByProp = property.FindPropertyRelative("findByType");
|
||||
|
||||
var displayNames = findByProp.enumDisplayNames;
|
||||
int count = findByProp.enumDisplayNames.Length;
|
||||
if (!isGUIContentSet)
|
||||
{
|
||||
findByPropContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
findByPropContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = ((LocationPrefabFindBy)extIdx).Description(),
|
||||
};
|
||||
}
|
||||
isGUIContentSet = true;
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
findByProp.enumValueIndex = EditorGUILayout.Popup(findByDropDown, findByProp.enumValueIndex, findByPropContent);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
switch ((LocationPrefabFindBy)findByProp.enumValueIndex)
|
||||
{
|
||||
case (LocationPrefabFindBy.MapboxCategory):
|
||||
ShowCategoryOptions(property);
|
||||
break;
|
||||
case (LocationPrefabFindBy.AddressOrLatLon):
|
||||
ShowAddressOrLatLonUI(property);
|
||||
break;
|
||||
case (LocationPrefabFindBy.POIName):
|
||||
ShowPOINames(property);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private void ShowCategoryOptions(SerializedProperty property)
|
||||
{
|
||||
//Category drop down
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var categoryProp = property.FindPropertyRelative("categories");
|
||||
categoryProp.intValue = (int)(LocationPrefabCategories)(EditorGUILayout.EnumFlagsField(categoriesDropDown, (LocationPrefabCategories)categoryProp.intValue));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
ShowDensitySlider(property);
|
||||
}
|
||||
|
||||
private void ShowAddressOrLatLonUI(SerializedProperty property)
|
||||
{
|
||||
//EditorGUILayout.BeginVertical();
|
||||
var coordinateProperties = property.FindPropertyRelative("coordinates");
|
||||
|
||||
for (int i = 0; i < coordinateProperties.arraySize; i++)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
//get the element to draw
|
||||
var coordinate = coordinateProperties.GetArrayElementAtIndex(i);
|
||||
|
||||
//label for each location.
|
||||
var coordinateLabel = String.Format("Location {0}", i);
|
||||
|
||||
// draw coordinate string.
|
||||
EditorGUI.BeginChangeCheck();
|
||||
coordinate.stringValue = EditorGUILayout.TextField(coordinateLabel, coordinate.stringValue);
|
||||
|
||||
if(EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property, true);
|
||||
}
|
||||
// draw search button.
|
||||
if (GUILayout.Button(new GUIContent(searchButtonContent), (GUIStyle)"minibuttonleft", GUILayout.MaxWidth(100)))
|
||||
{
|
||||
object propertyObject = EditorHelper.GetTargetObjectOfProperty(property);
|
||||
GeocodeAttributeSearchWindow.Open(coordinate, propertyObject);
|
||||
}
|
||||
|
||||
//include a remove button in the row
|
||||
if (GUILayout.Button(new GUIContent(" X "), (GUIStyle)"minibuttonright", GUILayout.MaxWidth(30)))
|
||||
{
|
||||
coordinateProperties.DeleteArrayElementAtIndex(i);
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth - 3);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Add Location"), (GUIStyle)"minibutton"))
|
||||
{
|
||||
coordinateProperties.arraySize++;
|
||||
var newElement = coordinateProperties.GetArrayElementAtIndex(coordinateProperties.arraySize - 1);
|
||||
newElement.stringValue = "";
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
|
||||
private void ShowPOINames(SerializedProperty property)
|
||||
{
|
||||
//Name field
|
||||
var categoryProp = property.FindPropertyRelative("nameString");
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
categoryProp.stringValue = EditorGUILayout.TextField(nameField, categoryProp.stringValue);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
|
||||
ShowDensitySlider(property);
|
||||
}
|
||||
|
||||
private void ShowDensitySlider(SerializedProperty property)
|
||||
{
|
||||
//Density slider
|
||||
var densityProp = property.FindPropertyRelative("density");
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(densityProp, densitySlider);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
GUI.enabled = true;
|
||||
densityProp.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private Rect GetNewRect(Rect position)
|
||||
{
|
||||
return new Rect(position.x, position.y, position.width, _lineHeight);
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return _lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e267a35441e2f4c19a4b96c23afad4ae
|
||||
timeCreated: 1523396148
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(RangeAroundTransformTileProviderOptions))]
|
||||
public class RangeAroundTransformTileProviderOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
foreach (var item in property)
|
||||
{
|
||||
var subproperty = item as SerializedProperty;
|
||||
EditorGUI.PropertyField(position, subproperty, true);
|
||||
position.height = lineHeight;
|
||||
position.y += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 3 * lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 758132744af3642f2ae9a7c31ce9c0d9
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(RangeTileProviderOptions))]
|
||||
public class RangeTileProviderOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
foreach (var item in property)
|
||||
{
|
||||
var subproperty = item as SerializedProperty;
|
||||
EditorGUILayout.PropertyField(subproperty, true);
|
||||
position.height = lineHeight;
|
||||
position.y += lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59524ff7910c146abad051df9ab054db
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace Mapbox.Unity.Map
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
using UnityEditor;
|
||||
using Mapbox.Editor;
|
||||
|
||||
[CustomPropertyDrawer(typeof(SpawnPrefabOptions))]
|
||||
public class SpawnPrefabOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
private GUIContent prefabContent = new GUIContent
|
||||
{
|
||||
text = "Prefab",
|
||||
tooltip = "The prefab to be spawned"
|
||||
};
|
||||
|
||||
private GUIContent scalePrefabContent = new GUIContent
|
||||
{
|
||||
text = "Scale down with world",
|
||||
tooltip = "The prefab will scale with the map object"
|
||||
};
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
position.height = 2.5f * lineHeight;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
property.FindPropertyRelative("prefab").objectReferenceValue = EditorGUI.ObjectField(new Rect(position.x, position.y, position.width, lineHeight), prefabContent, property.FindPropertyRelative("prefab").objectReferenceValue, typeof(UnityEngine.GameObject), false);
|
||||
position.y += lineHeight;
|
||||
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("scaleDownWithWorld"), scalePrefabContent);
|
||||
if(EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(property);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 2.0f * lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2da764c4c82845efbcea6530b3c8120
|
||||
timeCreated: 1523922185
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomPropertyDrawer(typeof(Style))]
|
||||
public class StyleOptionsDrawer : PropertyDrawer
|
||||
{
|
||||
static float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
GUILayout.Space(-lineHeight);
|
||||
EditorGUILayout.PropertyField(property.FindPropertyRelative("Id"), label);
|
||||
}
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Reserve space for the total visible properties.
|
||||
return lineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 971e17905b31043f3914e1efda0ef7d7
|
||||
timeCreated: 1521052834
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loaded 100 of 1285 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user