[TASK] Initial commit with basic product setup
This commit is contained in:
@@ -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:
|
||||
339
Assets/Mapbox SDK/Mapbox/Unity/Editor/AtlasTemplateGenerator.cs
Normal file
339
Assets/Mapbox SDK/Mapbox/Unity/Editor/AtlasTemplateGenerator.cs
Normal file
@@ -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:
|
||||
9
Assets/Mapbox SDK/Mapbox/Unity/Editor/Build.meta
Normal file
9
Assets/Mapbox SDK/Mapbox/Unity/Editor/Build.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28d2b990a838d44e1b28195d8465d645
|
||||
folderAsset: yes
|
||||
timeCreated: 1495491662
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
#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);
|
||||
string target = proj.TargetGuidByName("Unity-iPhone");
|
||||
|
||||
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:
|
||||
19
Assets/Mapbox SDK/Mapbox/Unity/Editor/ClearFileCache.cs
Normal file
19
Assets/Mapbox SDK/Mapbox/Unity/Editor/ClearFileCache.cs
Normal file
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Mapbox SDK/Mapbox/Unity/Editor/ClearFileCache.cs.meta
Normal file
12
Assets/Mapbox SDK/Mapbox/Unity/Editor/ClearFileCache.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 588d3a5d675244fc1a1d927b580b99a3
|
||||
timeCreated: 1497883479
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
245
Assets/Mapbox SDK/Mapbox/Unity/Editor/EditorHelper.cs
Normal file
245
Assets/Mapbox SDK/Mapbox/Unity/Editor/EditorHelper.cs
Normal file
@@ -0,0 +1,245 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Mapbox.Unity.Map;
|
||||
/// <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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Assets/Mapbox SDK/Mapbox/Unity/Editor/EditorHelper.cs.meta
Normal file
13
Assets/Mapbox SDK/Mapbox/Unity/Editor/EditorHelper.cs.meta
Normal file
@@ -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:
|
||||
85
Assets/Mapbox SDK/Mapbox/Unity/Editor/FactoryDrawer.cs
Normal file
85
Assets/Mapbox SDK/Mapbox/Unity/Editor/FactoryDrawer.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
//using UnityEngine;
|
||||
//using System.Collections;
|
||||
//using UnityEditor;
|
||||
//using Mapbox.Unity.MeshGeneration.Factories;
|
||||
//using System;
|
||||
//using Mapbox.Unity.MeshGeneration;
|
||||
|
||||
//namespace Mapbox.Editor.NodeEditor
|
||||
//{
|
||||
// [CustomPropertyDrawer(typeof(AssignmentTypeAttribute))]
|
||||
// public class TypeAttributeDrawer : PropertyDrawer
|
||||
// {
|
||||
// float y = 0;
|
||||
|
||||
// public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
|
||||
// {
|
||||
// EditorGUI.BeginProperty(position, label, prop);
|
||||
// var att = attribute as AssignmentTypeAttribute;
|
||||
// //var list = prop.FindPropertyRelative("List");
|
||||
// y = position.y;
|
||||
// for (int i = 0; i < prop.arraySize; i++)
|
||||
// {
|
||||
// Rect textFieldPosition = position;
|
||||
// Rect nameRect = new Rect(position.x, y, position.width - 60, 20);
|
||||
// Rect buttonRect = new Rect(position.width - 40, y, 25, 20);
|
||||
|
||||
// GUI.enabled = false;
|
||||
// prop.objectReferenceValue = EditorGUI.ObjectField(nameRect, new GUIContent("Script"), prop.objectReferenceValue, att.Type, false) as ScriptableObject;
|
||||
// GUI.enabled = true;
|
||||
|
||||
// //DrawTextField(nameRect, list.GetArrayElementAtIndex(i), new GUIContent(att.Type.Name));
|
||||
// if (GUI.Button(buttonRect, new GUIContent("E")))
|
||||
// {
|
||||
// Mapbox.Editor.ScriptableCreatorWindow.Open(att.Type, prop);
|
||||
// }
|
||||
// buttonRect = new Rect(position.width - 15, y, 25, 20);
|
||||
// if (GUI.Button(buttonRect, new GUIContent("-")))
|
||||
// {
|
||||
// //prop.DeleteArrayElementAtIndex(i);
|
||||
// }
|
||||
// y += 20;
|
||||
// }
|
||||
|
||||
// Rect buttonRect2 = new Rect(position.x, y, position.width, 20);
|
||||
// if (GUI.Button(buttonRect2, new GUIContent("Add New")))
|
||||
// {
|
||||
// Mapbox.Editor.ScriptableCreatorWindow.Open(att.Type, prop);
|
||||
// }
|
||||
// EditorGUI.EndProperty();
|
||||
// }
|
||||
|
||||
// public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
// {
|
||||
// return base.GetPropertyHeight(property, label);// + property.FindPropertyRelative("List").arraySize * 20 + 10;
|
||||
// }
|
||||
|
||||
// void DrawTextField(Rect position, SerializedProperty prop, GUIContent label)
|
||||
// {
|
||||
// if (prop.objectReferenceValue != null)
|
||||
// {
|
||||
// EditorGUI.BeginChangeCheck();
|
||||
// string value = EditorGUI.TextField(position, label, prop.objectReferenceValue.name + " (" + prop.objectReferenceValue.GetType().Name + ")");
|
||||
// if (EditorGUI.EndChangeCheck())
|
||||
// prop.stringValue = value;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// EditorGUI.BeginChangeCheck();
|
||||
// string value = EditorGUI.TextField(position, label, "Not set");
|
||||
// if (EditorGUI.EndChangeCheck())
|
||||
// prop.stringValue = value;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class TypeRAttribute : PropertyAttribute
|
||||
// {
|
||||
// Type type;
|
||||
|
||||
// public TypeRAttribute(Type t)
|
||||
// {
|
||||
// this.type = t;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
12
Assets/Mapbox SDK/Mapbox/Unity/Editor/FactoryDrawer.cs.meta
Normal file
12
Assets/Mapbox SDK/Mapbox/Unity/Editor/FactoryDrawer.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3e0f99ec9b454e94b7a024c6fe8f743
|
||||
timeCreated: 1504124010
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Mapbox SDK/Mapbox/Unity/Editor/FactoryEditor.cs
Normal file
13
Assets/Mapbox SDK/Mapbox/Unity/Editor/FactoryEditor.cs
Normal file
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Mapbox SDK/Mapbox/Unity/Editor/FactoryEditor.cs.meta
Normal file
12
Assets/Mapbox SDK/Mapbox/Unity/Editor/FactoryEditor.cs.meta
Normal file
@@ -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:
|
||||
196
Assets/Mapbox SDK/Mapbox/Unity/Editor/FeatureSubLayerTreeView.cs
Normal file
196
Assets/Mapbox SDK/Mapbox/Unity/Editor/FeatureSubLayerTreeView.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
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)
|
||||
{
|
||||
// Custom setup
|
||||
//rowHeight = kRowHeights;
|
||||
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:
|
||||
18
Assets/Mapbox SDK/Mapbox/Unity/Editor/FeatureTreeElement.cs
Normal file
18
Assets/Mapbox SDK/Mapbox/Unity/Editor/FeatureTreeElement.cs
Normal file
@@ -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,192 @@
|
||||
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();
|
||||
|
||||
//_hasResponse = true;
|
||||
//_coordinate = res.Features[0].Center;
|
||||
//Response = res;
|
||||
//if (OnGeocoderResponse != null)
|
||||
//{
|
||||
// OnGeocoderResponse(this, EventArgs.Empty);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d99190dd95ea8a245ba1f7c8c3084d0a
|
||||
timeCreated: 1484136312
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/Mapbox SDK/Mapbox/Unity/Editor/LayerModifierEditor.cs
Normal file
33
Assets/Mapbox SDK/Mapbox/Unity/Editor/LayerModifierEditor.cs
Normal file
@@ -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:
|
||||
318
Assets/Mapbox SDK/Mapbox/Unity/Editor/MapManagerEditor.cs
Normal file
318
Assets/Mapbox SDK/Mapbox/Unity/Editor/MapManagerEditor.cs
Normal file
@@ -0,0 +1,318 @@
|
||||
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 = "";
|
||||
/// <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 mapIdGui = new GUIContent
|
||||
{
|
||||
text = "Map Id",
|
||||
tooltip = "Map Id corresponding to the tileset."
|
||||
};
|
||||
|
||||
bool _isGUIContentSet = false;
|
||||
GUIContent[] _sourceTypeContent;
|
||||
static float _lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
objectId = serializedObject.targetObject.GetInstanceID().ToString();
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
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();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
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;
|
||||
int count = sourceTypeProperty.enumDisplayNames.Length;
|
||||
if (!_isGUIContentSet)
|
||||
{
|
||||
_sourceTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
_sourceTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = ((VectorSourceType)extIdx).Description(),
|
||||
};
|
||||
}
|
||||
|
||||
_isGUIContentSet = true;
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(new GUIContent
|
||||
{
|
||||
text = "Data Source",
|
||||
tooltip = "Source tileset for Vector Data"
|
||||
}, sourceTypeProperty.enumValueIndex, _sourceTypeContent);
|
||||
|
||||
sourceTypeValue = (VectorSourceType)sourceTypeProperty.enumValueIndex;
|
||||
|
||||
switch (sourceTypeValue)
|
||||
{
|
||||
case VectorSourceType.MapboxStreets:
|
||||
case VectorSourceType.MapboxStreetsWithBuildingIds:
|
||||
var sourcePropertyValue = MapboxDefaultVector.GetParameters(sourceTypeValue);
|
||||
layerSourceId.stringValue = sourcePropertyValue.Id;
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(layerSourceProperty, mapIdGui);
|
||||
GUI.enabled = true;
|
||||
isActiveProperty.boolValue = true;
|
||||
break;
|
||||
case VectorSourceType.Custom:
|
||||
EditorGUILayout.PropertyField(layerSourceProperty, mapIdGui);
|
||||
isActiveProperty.boolValue = true;
|
||||
break;
|
||||
case VectorSourceType.None:
|
||||
isActiveProperty.boolValue = false;
|
||||
break;
|
||||
default:
|
||||
isActiveProperty.boolValue = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorHelper.CheckForModifiedProperty(layerProperty);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
GUILayout.Space(-2.0f * _lineHeight);
|
||||
ShowSection(serializedObject.FindProperty("_vectorData"), "_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:
|
||||
68
Assets/Mapbox SDK/Mapbox/Unity/Editor/MapVisualizerEditor.cs
Normal file
68
Assets/Mapbox SDK/Mapbox/Unity/Editor/MapVisualizerEditor.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Factories;
|
||||
using Mapbox.Editor.NodeEditor;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CustomEditor(typeof(MapVisualizer))]
|
||||
public class MapVisualizerEditor : UnityEditor.Editor
|
||||
{
|
||||
private MonoScript script;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
script = MonoScript.FromScriptableObject((MapVisualizer)target);
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
GUI.enabled = false;
|
||||
script = EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false) as MonoScript;
|
||||
GUI.enabled = true;
|
||||
|
||||
var texture = serializedObject.FindProperty("_loadingTexture");
|
||||
EditorGUILayout.ObjectField(texture, typeof(Texture2D));
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Factories");
|
||||
var facs = serializedObject.FindProperty("Factories");
|
||||
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(AbstractTileFactory), false) as ScriptableObject;
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (GUILayout.Button(NodeBasedEditor.magnifierTexture, (GUIStyle)"minibuttonleft", GUILayout.Width(30)))
|
||||
{
|
||||
ScriptableCreatorWindow.Open(typeof(AbstractTileFactory), 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(AbstractTileFactory), facs);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b2aaa68d2af74e028ee69096305d33a
|
||||
timeCreated: 1504124010
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,689 @@
|
||||
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 _checkingButtonStyle;
|
||||
|
||||
//GUIStyle _validFieldStyle;
|
||||
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;
|
||||
//_titleStyle.fontSize = 16;
|
||||
_bodyStyle = new GUIStyle(GUI.skin.FindStyle("WordWrapLabel"));
|
||||
//_bodyStyle.fontSize = 14;
|
||||
_linkStyle = new GUIStyle(GUI.skin.FindStyle("PR PrefabLabel"));
|
||||
//_linkStyle.fontSize = 14;
|
||||
_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;
|
||||
|
||||
//_checkingButtonStyle = new GUIStyle(_submitButtonStyle);
|
||||
|
||||
//_validFieldStyle = new GUIStyle(_textFieldStyle);
|
||||
_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);
|
||||
}
|
||||
else
|
||||
{
|
||||
//EditorGUILayout.LabelField("", _errorStyle);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
}
|
||||
|
||||
void DrawChangelog()
|
||||
{
|
||||
//_showChangelogFoldout = EditorGUILayout.Foldout(_showChangelogFoldout, "v" + Constants.SDK_VERSION + " Changelog", true);
|
||||
|
||||
//if (_showChangelogFoldout)
|
||||
//{
|
||||
EditorGUI.indentLevel = 2;
|
||||
//EditorGUILayout.BeginHorizontal(_horizontalGroup);
|
||||
// GUIContent labelContent = new GUIContent("SDK version " + Constants.SDK_VERSION + " changelog, and learn how to contribute at");
|
||||
GUIContent linkContent = new GUIContent("v" + Constants.SDK_VERSION + " changelog");
|
||||
// EditorGUILayout.LabelField(labelContent, _bodyStyle, GUILayout.Width(_bodyStyle.CalcSize(labelContent).x));
|
||||
|
||||
if (GUILayout.Button(linkContent, _linkStyle))
|
||||
{
|
||||
Application.OpenURL("https://github.com/mapbox/mapbox-unity-sdk/blob/develop/documentation/docs/05-changelog.md");
|
||||
}
|
||||
|
||||
// GUILayout.FlexibleSpace();
|
||||
//EditorGUILayout.EndHorizontal();
|
||||
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,35 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Editor.NodeEditor;
|
||||
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,102 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
using Mapbox.Editor.NodeEditor;
|
||||
|
||||
[CustomEditor(typeof(MergedModifierStack))]
|
||||
public class MergedModifierStackEditor : UnityEditor.Editor
|
||||
{
|
||||
private MonoScript script;
|
||||
private void OnEnable()
|
||||
{
|
||||
script = MonoScript.FromScriptableObject((MergedModifierStack)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.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(NodeBasedEditor.magnifierTexture, (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(NodeBasedEditor.magnifierTexture, (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:
|
||||
105
Assets/Mapbox SDK/Mapbox/Unity/Editor/ModifierStackEditor.cs
Normal file
105
Assets/Mapbox SDK/Mapbox/Unity/Editor/ModifierStackEditor.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Mapbox.Editor.NodeEditor;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
|
||||
[CustomEditor(typeof(ModifierStack))]
|
||||
public class ModifierStackEditor : UnityEditor.Editor
|
||||
{
|
||||
|
||||
private MonoScript script;
|
||||
private SerializedProperty _positionType;
|
||||
private void OnEnable()
|
||||
{
|
||||
script = MonoScript.FromScriptableObject((ModifierStack)target);
|
||||
_positionType = serializedObject.FindProperty("moveFeaturePositionTo");
|
||||
}
|
||||
|
||||
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(NodeBasedEditor.magnifierTexture, (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(NodeBasedEditor.magnifierTexture, (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:
|
||||
9
Assets/Mapbox SDK/Mapbox/Unity/Editor/NodeEditor.meta
Normal file
9
Assets/Mapbox SDK/Mapbox/Unity/Editor/NodeEditor.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f67482bbbca707249971449edec649cf
|
||||
folderAsset: yes
|
||||
timeCreated: 1502473442
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mapbox.Editor.NodeEditor
|
||||
{
|
||||
public class Connection
|
||||
{
|
||||
public ConnectionPoint inPoint;
|
||||
public ConnectionPoint outPoint;
|
||||
public Action<Connection> OnClickRemoveConnection;
|
||||
private Vector2 _outVector;
|
||||
|
||||
public Connection(ConnectionPoint inPoint, ConnectionPoint outPoint)
|
||||
{
|
||||
this.inPoint = inPoint;
|
||||
this.outPoint = outPoint;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
_outVector = new Vector2(outPoint.node.rect.xMax, outPoint.rect.center.y);
|
||||
|
||||
Handles.DrawBezier(
|
||||
inPoint.left,
|
||||
_outVector,
|
||||
inPoint.left + Vector2.left * 50f,
|
||||
outPoint.rect.center - Vector2.left * 50f,
|
||||
outPoint.isActive ? Color.white : Color.gray,
|
||||
null,
|
||||
2f
|
||||
);
|
||||
|
||||
//if (Handles.Button((inPoint.rect.center + outPoint.rect.center) * 0.5f, Quaternion.identity, 4, 8, Handles.RectangleCap))
|
||||
//{
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d8dac7dcfe2eb94e89cf9a897eadf22
|
||||
timeCreated: 1501854762
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
namespace Mapbox.Editor.NodeEditor
|
||||
{
|
||||
public enum ConnectionPointType { In, Out }
|
||||
|
||||
public class ConnectionPoint
|
||||
{
|
||||
public Vector2 left;
|
||||
public Vector2 right;
|
||||
public Rect rect;
|
||||
public Rect labelRect;
|
||||
public Rect inLabelRect;
|
||||
public Rect toggleRect;
|
||||
public ConnectionPointType type;
|
||||
public Node node;
|
||||
public GUIStyle style;
|
||||
private VectorSubLayerProperties _activeProp;
|
||||
public bool isActive;
|
||||
|
||||
private string _outLabel;
|
||||
private string _inLabel;
|
||||
public string inLabel
|
||||
{
|
||||
get { return _inLabel; }
|
||||
set
|
||||
{
|
||||
if (_inLabel != value)
|
||||
labelGui = new GUIContent(value.ToString());
|
||||
_inLabel = value;
|
||||
}
|
||||
}
|
||||
private GUIContent labelGui;
|
||||
|
||||
private float _deltaY;
|
||||
private GUIStyle _labelStyle = new GUIStyle()
|
||||
{
|
||||
fontSize = 10,
|
||||
normal = new GUIStyleState() { textColor = Color.white },
|
||||
alignment = TextAnchor.MiddleRight
|
||||
};
|
||||
private GUIStyle _inLabelStyle = new GUIStyle()
|
||||
{
|
||||
fontSize = 10,
|
||||
normal = new GUIStyleState() { textColor = Color.white },
|
||||
alignment = TextAnchor.MiddleRight
|
||||
};
|
||||
|
||||
private static Texture2D activeOutImage;
|
||||
private static Texture2D inactiveOutImage;
|
||||
|
||||
public ConnectionPoint(Node node, string inname, string name, float deltay, ConnectionPointType type, GUIStyle style, VectorSubLayerProperties activeProp = null)
|
||||
{
|
||||
isActive = true;
|
||||
if (activeOutImage == null)
|
||||
{
|
||||
activeOutImage = EditorGUIUtility.Load("builtin skins/darkskin/images/node3.png") as Texture2D;
|
||||
inactiveOutImage = EditorGUIUtility.Load("builtin skins/darkskin/images/node6.png") as Texture2D;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
this._outLabel = Regex.Replace(name, "(\\B[A-Z])", " $1");
|
||||
}
|
||||
else
|
||||
{
|
||||
this._outLabel = "";
|
||||
}
|
||||
inLabel = inname;
|
||||
this.node = node;
|
||||
this.type = type;
|
||||
this.style = style;
|
||||
_deltaY = deltay;
|
||||
rect = new Rect(0, 0, 10f + (string.IsNullOrEmpty(inLabel) ? 0 : 100), 20f);
|
||||
left = new Vector2(rect.x, rect.y + (rect.height / 2));
|
||||
|
||||
labelRect = new Rect(node.rect.xMin, node.rect.y + _deltaY - 15f, node.rect.width - 20, 25);
|
||||
inLabelRect = new Rect(rect.x + 4, rect.y - 1, rect.width, rect.height);
|
||||
|
||||
_activeProp = activeProp;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (_activeProp != null)
|
||||
isActive = _activeProp.coreOptions.isActive;
|
||||
|
||||
rect.y = node.rect.y + _deltaY - rect.height * 0.5f;
|
||||
labelRect.x = node.rect.xMin + (isActive ? -20 : 0);
|
||||
labelRect.y = node.rect.y + _deltaY - 15f;
|
||||
labelRect.width = node.rect.width - 20;
|
||||
inLabelRect.x = rect.x + 4;
|
||||
inLabelRect.y = rect.y - 1;
|
||||
|
||||
toggleRect.x = node.rect.xMin - 30 + node.rect.width;
|
||||
toggleRect.width = 20;
|
||||
toggleRect.y = labelRect.y + 5;
|
||||
toggleRect.height = 20;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ConnectionPointType.In:
|
||||
rect.x = node.rect.x - rect.width + 8f;
|
||||
break;
|
||||
|
||||
case ConnectionPointType.Out:
|
||||
rect.x = node.rect.x + node.rect.width - 8f;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_outLabel))
|
||||
{
|
||||
GUI.Label(labelRect, _outLabel, _labelStyle);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(inLabel))
|
||||
{
|
||||
var v = _inLabelStyle.CalcSize(labelGui);
|
||||
inLabelRect.x = node.rect.x - v.x - 13;
|
||||
inLabelRect.width = v.x + 13;
|
||||
rect.x = node.rect.x - v.x - 5;
|
||||
rect.width = v.x + 15;
|
||||
}
|
||||
left.x = rect.x;
|
||||
left.y = rect.y + (rect.height / 2);
|
||||
|
||||
if (_activeProp != null)
|
||||
{
|
||||
rect.x -= 30;
|
||||
rect.width = 45;
|
||||
rect.y -= 1;
|
||||
rect.height = 21;
|
||||
|
||||
if (_activeProp.coreOptions.isActive)
|
||||
{
|
||||
GUI.DrawTexture(rect, activeOutImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.DrawTexture(rect, inactiveOutImage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUI.Button(rect, "", style))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (_activeProp != null)
|
||||
{
|
||||
_activeProp.coreOptions.isActive = EditorGUI.Toggle(toggleRect, _activeProp.coreOptions.isActive);
|
||||
//_activeProp.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
GUI.Label(inLabelRect, inLabel, _inLabelStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 667c708eac26a1c4aa960535705ebab3
|
||||
timeCreated: 1501854778
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,434 @@
|
||||
//https://github.com/Seneral/Node_Editor_Framework
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Mapbox.Editor.NodeEditor
|
||||
{
|
||||
public static class GUIScaleUtility
|
||||
{
|
||||
// General
|
||||
private static bool compabilityMode;
|
||||
private static bool initiated;
|
||||
|
||||
// cache the reflected methods
|
||||
private static FieldInfo currentGUILayoutCache;
|
||||
private static FieldInfo currentTopLevelGroup;
|
||||
|
||||
// Delegates to the reflected methods
|
||||
private static Func<Rect> GetTopRectDelegate;
|
||||
private static Func<Rect> topmostRectDelegate;
|
||||
|
||||
// Delegate accessors
|
||||
public static Rect getTopRect
|
||||
{
|
||||
get { return (Rect) GetTopRectDelegate.Invoke(); }
|
||||
}
|
||||
|
||||
public static Rect getTopRectScreenSpace
|
||||
{
|
||||
get { return (Rect) topmostRectDelegate.Invoke(); }
|
||||
}
|
||||
|
||||
// Rect stack for manipulating groups
|
||||
public static List<Rect> currentRectStack { get; private set; }
|
||||
private static List<List<Rect>> rectStackGroups;
|
||||
|
||||
// Matrices stack
|
||||
private static List<Matrix4x4> GUIMatrices;
|
||||
private static List<bool> adjustedGUILayout;
|
||||
|
||||
#region Init
|
||||
|
||||
public static void CheckInit()
|
||||
{
|
||||
if (!initiated)
|
||||
Init();
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
// As we can call Begin/Ends inside another, we need to save their states hierarchial in Lists (not Stack, as we need to iterate over them!):
|
||||
currentRectStack = new List<Rect>();
|
||||
rectStackGroups = new List<List<Rect>>();
|
||||
GUIMatrices = new List<Matrix4x4>();
|
||||
adjustedGUILayout = new List<bool>();
|
||||
|
||||
// Fetch rect acessors using Reflection
|
||||
Assembly UnityEngine = Assembly.GetAssembly(typeof(UnityEngine.GUI));
|
||||
Type GUIClipType = UnityEngine.GetType("UnityEngine.GUIClip", true);
|
||||
|
||||
PropertyInfo topmostRect = GUIClipType.GetProperty("topmostRect", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
MethodInfo GetTopmostRect = topmostRect != null ? (topmostRect.GetGetMethod(false) ?? topmostRect.GetGetMethod(true)) : null;
|
||||
MethodInfo GetTopRect = GUIClipType.GetMethod("GetTopRect", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
MethodInfo ClipRect = GUIClipType.GetMethod("Clip", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, Type.DefaultBinder, new Type[] {typeof(Rect)}, new ParameterModifier[] { });
|
||||
|
||||
if (GUIClipType == null || topmostRect == null || GetTopRect == null || ClipRect == null)
|
||||
{
|
||||
Debug.LogWarning("GUIScaleUtility cannot run on this system! Compability mode enabled. For you that means you're not able to use the Node Editor inside more than one group:( Please PM me (Seneral @UnityForums) so I can figure out what causes this! Thanks!");
|
||||
Debug.LogWarning((GUIClipType == null ? "GUIClipType is Null, " : "") + (topmostRect == null ? "topmostRect is Null, " : "") + (GetTopRect == null ? "GetTopRect is Null, " : "") + (ClipRect == null ? "ClipRect is Null, " : ""));
|
||||
compabilityMode = true;
|
||||
initiated = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Create simple acessor delegates
|
||||
GetTopRectDelegate = (Func<Rect>) Delegate.CreateDelegate(typeof(Func<Rect>), GetTopRect);
|
||||
topmostRectDelegate = (Func<Rect>) Delegate.CreateDelegate(typeof(Func<Rect>), GetTopmostRect);
|
||||
|
||||
if (GetTopRectDelegate == null || topmostRectDelegate == null)
|
||||
{
|
||||
Debug.LogWarning("GUIScaleUtility cannot run on this system! Compability mode enabled. For you that means you're not able to use the Node Editor inside more than one group:( Please PM me (Seneral @UnityForums) so I can figure out what causes this! Thanks!");
|
||||
Debug.LogWarning((GUIClipType == null ? "GUIClipType is Null, " : "") + (topmostRect == null ? "topmostRect is Null, " : "") + (GetTopRect == null ? "GetTopRect is Null, " : "") + (ClipRect == null ? "ClipRect is Null, " : ""));
|
||||
compabilityMode = true;
|
||||
initiated = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Sometimes, strange errors pop up (related to Mac?), which we try to catch and enable a compability Mode no supporting zooming in groups
|
||||
/*try
|
||||
{
|
||||
topmostRectDelegate.Invoke ();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning ("GUIScaleUtility cannot run on this system! Compability mode enabled. For you that means you're not able to use the Node Editor inside more than one group:( Please PM me (Seneral @UnityForums) so I can figure out what causes this! Thanks!");
|
||||
Debug.Log (e.Message);
|
||||
compabilityMode = true;
|
||||
}*/
|
||||
|
||||
initiated = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Scale Area
|
||||
|
||||
public static Vector2 getCurrentScale
|
||||
{
|
||||
get { return new Vector2(1 / GUI.matrix.GetColumn(0).magnitude, 1 / GUI.matrix.GetColumn(1).magnitude); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins a scaled local area.
|
||||
/// Returns vector to offset GUI controls with to account for zooming to the pivot.
|
||||
/// Using adjustGUILayout does that automatically for GUILayout rects. Theoretically can be nested!
|
||||
/// </summary>
|
||||
public static Vector2 BeginScale(ref Rect rect, Vector2 zoomPivot, float zoom, bool adjustGUILayout)
|
||||
{
|
||||
Rect screenRect;
|
||||
if (compabilityMode)
|
||||
{
|
||||
// In compability mode, we will assume only one top group and do everything manually, not using reflected calls (-> practically blind)
|
||||
GUI.EndGroup();
|
||||
screenRect = rect;
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
screenRect.y += 23;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// If it's supported, we take the completely generic way using reflected calls
|
||||
GUIScaleUtility.BeginNoClip();
|
||||
screenRect = GUIScaleUtility.GUIToScaledSpace(rect);
|
||||
}
|
||||
|
||||
rect = Scale(screenRect, screenRect.position + zoomPivot, new Vector2(zoom, zoom));
|
||||
|
||||
// Now continue drawing using the new clipping group
|
||||
GUI.BeginGroup(rect);
|
||||
rect.position = Vector2.zero; // Adjust because we entered the new group
|
||||
|
||||
// Because I currently found no way to actually scale to a custom pivot rather than (0, 0),
|
||||
// we'll make use of a cheat and just offset it accordingly to let it appear as if it would scroll to the center
|
||||
// Note, due to that, controls not adjusted are still scaled to (0, 0)
|
||||
Vector2 zoomPosAdjust = rect.center - screenRect.size / 2 + zoomPivot;
|
||||
|
||||
// For GUILayout, we can make this adjustment here if desired
|
||||
adjustedGUILayout.Add(adjustGUILayout);
|
||||
if (adjustGUILayout)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(rect.center.x - screenRect.size.x + zoomPivot.x);
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.Space(rect.center.y - screenRect.size.y + zoomPivot.y);
|
||||
}
|
||||
|
||||
// Take a matrix backup to restore back later on
|
||||
GUIMatrices.Add(GUI.matrix);
|
||||
|
||||
// Scale GUI.matrix. After that we have the correct clipping group again.
|
||||
GUIUtility.ScaleAroundPivot(new Vector2(1 / zoom, 1 / zoom), zoomPosAdjust);
|
||||
|
||||
return zoomPosAdjust;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends a scale region previously opened with BeginScale
|
||||
/// </summary>
|
||||
public static void EndScale()
|
||||
{
|
||||
// Set last matrix and clipping group
|
||||
if (GUIMatrices.Count == 0 || adjustedGUILayout.Count == 0)
|
||||
throw new UnityException("GUIScaleUtility: You are ending more scale regions than you are beginning!");
|
||||
GUI.matrix = GUIMatrices[GUIMatrices.Count - 1];
|
||||
GUIMatrices.RemoveAt(GUIMatrices.Count - 1);
|
||||
|
||||
// End GUILayout zoomPosAdjustment
|
||||
if (adjustedGUILayout[adjustedGUILayout.Count - 1])
|
||||
{
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
adjustedGUILayout.RemoveAt(adjustedGUILayout.Count - 1);
|
||||
|
||||
// End the scaled group
|
||||
GUI.EndGroup();
|
||||
|
||||
if (compabilityMode)
|
||||
{
|
||||
// In compability mode, we don't know the previous group rect, but as we cannot use top groups there either way, we restore the screen group
|
||||
if (!Application.isPlaying) // We're in an editor window
|
||||
GUI.BeginClip(new Rect(0, 23, Screen.width, Screen.height - 23));
|
||||
else
|
||||
GUI.BeginClip(new Rect(0, 0, Screen.width, Screen.height));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Else, restore the clips (groups)
|
||||
GUIScaleUtility.RestoreClips();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Clips Hierarchy
|
||||
|
||||
/// <summary>
|
||||
/// Begins a field without groups. They should be restored using RestoreClips. Can be nested!
|
||||
/// </summary>
|
||||
public static void BeginNoClip()
|
||||
{
|
||||
// Record and close all clips one by one, from bottom to top, until we hit the 'origin'
|
||||
List<Rect> rectStackGroup = new List<Rect>();
|
||||
Rect topMostClip = getTopRect;
|
||||
while (topMostClip != new Rect(-10000, -10000, 40000, 40000))
|
||||
{
|
||||
rectStackGroup.Add(topMostClip);
|
||||
GUI.EndClip();
|
||||
topMostClip = getTopRect;
|
||||
}
|
||||
|
||||
// Store the clips appropriately
|
||||
rectStackGroup.Reverse();
|
||||
rectStackGroups.Add(rectStackGroup);
|
||||
currentRectStack.AddRange(rectStackGroup);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins a field without the last count groups. They should be restored using RestoreClips. Can be nested!
|
||||
/// </summary>
|
||||
public static void MoveClipsUp(int count)
|
||||
{
|
||||
// Record and close all clips one by one, from bottom to top, until reached the count or hit the 'origin'
|
||||
List<Rect> rectStackGroup = new List<Rect>();
|
||||
Rect topMostClip = getTopRect;
|
||||
while (topMostClip != new Rect(-10000, -10000, 40000, 40000) && count > 0)
|
||||
{
|
||||
rectStackGroup.Add(topMostClip);
|
||||
GUI.EndClip();
|
||||
topMostClip = getTopRect;
|
||||
count--;
|
||||
}
|
||||
|
||||
// Store the clips appropriately
|
||||
rectStackGroup.Reverse();
|
||||
rectStackGroups.Add(rectStackGroup);
|
||||
currentRectStack.AddRange(rectStackGroup);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the clips removed in BeginNoClip or MoveClipsUp
|
||||
/// </summary>
|
||||
public static void RestoreClips()
|
||||
{
|
||||
if (rectStackGroups.Count == 0)
|
||||
{
|
||||
Debug.LogError("GUIClipHierarchy: BeginNoClip/MoveClipsUp - RestoreClips count not balanced!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Read and restore clips one by one, from top to bottom
|
||||
List<Rect> rectStackGroup = rectStackGroups[rectStackGroups.Count - 1];
|
||||
for (int clipCnt = 0; clipCnt < rectStackGroup.Count; clipCnt++)
|
||||
{
|
||||
GUI.BeginClip(rectStackGroup[clipCnt]);
|
||||
currentRectStack.RemoveAt(currentRectStack.Count - 1);
|
||||
}
|
||||
|
||||
rectStackGroups.RemoveAt(rectStackGroups.Count - 1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Layout & Matrix Ignores
|
||||
|
||||
/// <summary>
|
||||
/// Ignores the current GUILayout cache and begins a new one. Cannot be nested!
|
||||
/// </summary>
|
||||
public static void BeginNewLayout()
|
||||
{
|
||||
if (compabilityMode)
|
||||
return;
|
||||
// Will mimic a new layout by creating a new group at (0, 0). Will be restored though after ending the new Layout
|
||||
Rect topMostClip = getTopRect;
|
||||
if (topMostClip != new Rect(-10000, -10000, 40000, 40000))
|
||||
GUILayout.BeginArea(new Rect(0, 0, topMostClip.width, topMostClip.height));
|
||||
else
|
||||
GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends the last GUILayout cache
|
||||
/// </summary>
|
||||
public static void EndNewLayout()
|
||||
{
|
||||
if (!compabilityMode)
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins an area without GUIMatrix transformations. Can be nested!
|
||||
/// </summary>
|
||||
public static void BeginIgnoreMatrix()
|
||||
{
|
||||
// Store and clean current matrix
|
||||
GUIMatrices.Add(GUI.matrix);
|
||||
GUI.matrix = Matrix4x4.identity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores last matrix ignored with BeginIgnoreMatrix
|
||||
/// </summary>
|
||||
public static void EndIgnoreMatrix()
|
||||
{
|
||||
if (GUIMatrices.Count == 0)
|
||||
throw new UnityException("GUIScaleutility: You are ending more ignoreMatrices than you are beginning!");
|
||||
// Read and assign previous matrix
|
||||
GUI.matrix = GUIMatrices[GUIMatrices.Count - 1];
|
||||
GUIMatrices.RemoveAt(GUIMatrices.Count - 1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Space Transformations
|
||||
|
||||
/// <summary>
|
||||
/// Scales the position around the pivot with scale
|
||||
/// </summary>
|
||||
public static Vector2 Scale(Vector2 pos, Vector2 pivot, Vector2 scale)
|
||||
{
|
||||
return Vector2.Scale(pos - pivot, scale) + pivot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scales the rect around the pivot with scale
|
||||
/// </summary>
|
||||
public static Rect Scale(Rect rect, Vector2 pivot, Vector2 scale)
|
||||
{
|
||||
rect.position = Vector2.Scale(rect.position - pivot, scale) + pivot;
|
||||
rect.size = Vector2.Scale(rect.size, scale);
|
||||
return rect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the position from the space aquired with BeginNoClip or MoveClipsUp to it's previous space
|
||||
/// </summary>
|
||||
public static Vector2 ScaledToGUISpace(Vector2 scaledPosition)
|
||||
{
|
||||
if (rectStackGroups == null || rectStackGroups.Count == 0)
|
||||
return scaledPosition;
|
||||
// Iterate through the clips and substract positions
|
||||
List<Rect> rectStackGroup = rectStackGroups[rectStackGroups.Count - 1];
|
||||
for (int clipCnt = 0; clipCnt < rectStackGroup.Count; clipCnt++)
|
||||
scaledPosition -= rectStackGroup[clipCnt].position;
|
||||
return scaledPosition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the rect from the space aquired with BeginNoClip or MoveClipsUp to it's previous space.
|
||||
/// DOES NOT scale the rect, only offsets it!
|
||||
/// </summary>
|
||||
public static Rect ScaledToGUISpace(Rect scaledRect)
|
||||
{
|
||||
if (rectStackGroups == null || rectStackGroups.Count == 0)
|
||||
return scaledRect;
|
||||
scaledRect.position = ScaledToGUISpace(scaledRect.position);
|
||||
return scaledRect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the position to the new space aquired with BeginNoClip or MoveClipsUp
|
||||
/// It's way faster to call GUIToScreenSpace before modifying the space though!
|
||||
/// </summary>
|
||||
public static Vector2 GUIToScaledSpace(Vector2 guiPosition)
|
||||
{
|
||||
if (rectStackGroups == null || rectStackGroups.Count == 0)
|
||||
return guiPosition;
|
||||
// Iterate through the clips and add positions ontop
|
||||
List<Rect> rectStackGroup = rectStackGroups[rectStackGroups.Count - 1];
|
||||
for (int clipCnt = 0; clipCnt < rectStackGroup.Count; clipCnt++)
|
||||
guiPosition += rectStackGroup[clipCnt].position;
|
||||
return guiPosition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the rect to the new space aquired with BeginNoClip or MoveClipsUp.
|
||||
/// DOES NOT scale the rect, only offsets it!
|
||||
/// It's way faster to call GUIToScreenSpace before modifying the space though!
|
||||
/// </summary>
|
||||
public static Rect GUIToScaledSpace(Rect guiRect)
|
||||
{
|
||||
if (rectStackGroups == null || rectStackGroups.Count == 0)
|
||||
return guiRect;
|
||||
guiRect.position = GUIToScaledSpace(guiRect.position);
|
||||
return guiRect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the position to screen space.
|
||||
/// You can use GUIToScaledSpace when you want to transform an old rect to the new space aquired with BeginNoClip or MoveClipsUp (slower, try to call this function before any of these two)!
|
||||
/// ATTENTION: This does not work well when any of the top groups is negative, means extends to the top or left of the screen. You may consider to use GUIToScaledSpace then, if possible!
|
||||
/// </summary>
|
||||
public static Vector2 GUIToScreenSpace(Vector2 guiPosition)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
return guiPosition + getTopRectScreenSpace.position - new Vector2(0, 22);
|
||||
#endif
|
||||
return guiPosition + getTopRectScreenSpace.position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the rect to screen space.
|
||||
/// You can use GUIToScaledSpace when you want to transform an old rect to the new space aquired with BeginNoClip or MoveClipsUp (slower, try to call this function before any of these two)!
|
||||
/// ATTENTION: This does not work well when any of the top groups is negative, means extends to the top or left of the screen. You may consider to use GUIToScaledSpace then, if possible!
|
||||
/// </summary>
|
||||
public static Rect GUIToScreenSpace(Rect guiRect)
|
||||
{
|
||||
guiRect.position += getTopRectScreenSpace.position;
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
guiRect.y -= 22;
|
||||
#endif
|
||||
return guiRect;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0569e7bedb842a84489760d9f273f442
|
||||
timeCreated: 1502064204
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
481
Assets/Mapbox SDK/Mapbox/Unity/Editor/NodeEditor/Node.cs
Normal file
481
Assets/Mapbox SDK/Mapbox/Unity/Editor/NodeEditor/Node.cs
Normal file
@@ -0,0 +1,481 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
using System.Linq;
|
||||
using Mapbox.Unity.MeshGeneration.Interfaces;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Unity.Utilities;
|
||||
|
||||
namespace Mapbox.Editor.NodeEditor
|
||||
{
|
||||
public class Node
|
||||
{
|
||||
private bool _expanded = true;
|
||||
|
||||
private bool _isRoot = false;
|
||||
private Vector2 _panDelta;
|
||||
//private Vector2 _topLeft = new Vector2(50, 50);
|
||||
private Vector2 _padding = new Vector2(50, 100);
|
||||
private float _propTopTest = 0f;
|
||||
|
||||
public List<Connection> Connections;
|
||||
public List<ConnectionPoint> ConnectionPoints;
|
||||
public List<Node> Children;
|
||||
|
||||
public object ScriptableObject;
|
||||
public Rect spaceRect;
|
||||
public Rect rect;
|
||||
public Rect buttonRect;
|
||||
public string title;
|
||||
public string subtitle;
|
||||
public bool isDragged;
|
||||
public bool isSelected;
|
||||
|
||||
public ConnectionPoint inPoint;
|
||||
|
||||
public Action<Node> OnRemoveNode;
|
||||
|
||||
private GUIStyle _titleStyle = new GUIStyle()
|
||||
{
|
||||
fontSize = 14,
|
||||
fontStyle = FontStyle.Bold,
|
||||
normal = new GUIStyleState() { textColor = Color.white }
|
||||
};
|
||||
private GUIStyle _subtitleStyle = new GUIStyle()
|
||||
{
|
||||
fontSize = 10,
|
||||
fontStyle = FontStyle.Italic,
|
||||
normal = new GUIStyleState() { textColor = Color.white }
|
||||
};
|
||||
|
||||
private float _headerHeight = 70;
|
||||
private float _propertyHeight = 25;
|
||||
private int _propCount = 0;
|
||||
private float _inbuff;
|
||||
|
||||
//Vector2 position, float width, float height
|
||||
public Node(object so = null)
|
||||
{
|
||||
_propTopTest = 0f;
|
||||
_propCount = 0;
|
||||
Children = new List<Node>();
|
||||
Connections = new List<Connection>();
|
||||
ConnectionPoints = new List<ConnectionPoint>();
|
||||
ScriptableObject = so;
|
||||
|
||||
if (ScriptableObject != null)
|
||||
{
|
||||
if (ScriptableObject is ModifierBase)
|
||||
{
|
||||
title = Regex.Replace(((ModifierBase)ScriptableObject).name, "(\\B[A-Z])", " $1");
|
||||
subtitle = Regex.Replace(ScriptableObject.GetType().Name, "(\\B[A-Z])", " $1");
|
||||
}
|
||||
else
|
||||
{
|
||||
//title = Regex.Replace(ScriptableObject., "(\\B[A-Z])", " $1");
|
||||
title = Regex.Replace(ScriptableObject.GetType().Name, "(\\B[A-Z])", " $1");
|
||||
}
|
||||
}
|
||||
|
||||
var inlabel = "";
|
||||
if (ScriptableObject is VectorSubLayerProperties)
|
||||
inlabel = (ScriptableObject as VectorSubLayerProperties).coreOptions.sublayerName;
|
||||
if (ScriptableObject is PrefabItemOptions)
|
||||
inlabel = (ScriptableObject as PrefabItemOptions).coreOptions.sublayerName;
|
||||
inPoint = new ConnectionPoint(this, inlabel, "", 20, ConnectionPointType.In, NodeBasedEditor.inPointStyle);
|
||||
}
|
||||
|
||||
public float Draw(Vector2 position, float width, float height)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(title))
|
||||
width = title.Length * 10;
|
||||
var boxHeight = _headerHeight + _propCount * _propertyHeight;
|
||||
if (ScriptableObject is ModifierBase)
|
||||
boxHeight = 52;
|
||||
_inbuff = (string.IsNullOrEmpty(inPoint.inLabel) ? 0 : 100);
|
||||
spaceRect = new Rect(position.x + _inbuff, position.y, width, boxHeight);
|
||||
rect = new Rect(position.x + _inbuff, position.y, width, boxHeight);
|
||||
buttonRect = new Rect(rect.xMax - 25, rect.yMin + 10, 20, 20);
|
||||
|
||||
_propTopTest = 0;
|
||||
if (_expanded)
|
||||
{
|
||||
foreach (var c in Children)
|
||||
{
|
||||
var h = c.Draw(new Vector2(spaceRect.xMax + _padding.x, spaceRect.yMin + _propTopTest), 100, 0);
|
||||
_propTopTest += h;
|
||||
spaceRect.height += h;
|
||||
}
|
||||
}
|
||||
|
||||
var so = ScriptableObject as VectorSubLayerProperties;
|
||||
if (so != null)
|
||||
{
|
||||
inPoint.inLabel = so.coreOptions.sublayerName;
|
||||
inPoint.Draw();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_isRoot)
|
||||
inPoint.Draw();
|
||||
}
|
||||
|
||||
var prefabItemObj = ScriptableObject as PrefabItemOptions;
|
||||
if (prefabItemObj != null)
|
||||
{
|
||||
inPoint.inLabel = prefabItemObj.coreOptions.sublayerName;
|
||||
inPoint.Draw();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_isRoot)
|
||||
inPoint.Draw();
|
||||
}
|
||||
spaceRect.height = Math.Max(height, Math.Max(spaceRect.height, boxHeight));
|
||||
if (Children.Count > 0)
|
||||
{
|
||||
spaceRect.height -= Math.Min(_propTopTest, boxHeight);
|
||||
}
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
GUILayout.BeginArea(rect, NodeBasedEditor.selectedNodeStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ScriptableObject is ModifierBase)
|
||||
GUILayout.BeginArea(rect, NodeBasedEditor.leafNodeStyle);
|
||||
else
|
||||
GUILayout.BeginArea(rect, NodeBasedEditor.nodeStyle);
|
||||
}
|
||||
GUILayout.Label(title, _titleStyle);
|
||||
GUILayout.Label(subtitle, _subtitleStyle);
|
||||
GUILayout.EndArea();
|
||||
|
||||
foreach (var p in ConnectionPoints)
|
||||
{
|
||||
p.Draw();
|
||||
}
|
||||
|
||||
DrawConnections();
|
||||
|
||||
if (Children.Count > 0)
|
||||
{
|
||||
if (_expanded)
|
||||
{
|
||||
if (GUI.Button(buttonRect, "", (GUIStyle)"flow overlay foldout"))
|
||||
{
|
||||
_expanded = !_expanded;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUI.Button(buttonRect, "", (GUIStyle)"IN FoldoutStatic"))
|
||||
{
|
||||
_expanded = !_expanded;
|
||||
}
|
||||
}
|
||||
}
|
||||
return spaceRect.height;
|
||||
}
|
||||
|
||||
public bool ProcessEvents(Event e)
|
||||
{
|
||||
switch (e.type)
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
if (e.button == 0)
|
||||
{
|
||||
if (rect.Contains(e.mousePosition))
|
||||
{
|
||||
if (!isDragged)
|
||||
{
|
||||
if (ScriptableObject is ModifierBase)
|
||||
{
|
||||
Selection.objects = new UnityEngine.Object[1] { (ModifierBase)ScriptableObject };
|
||||
}
|
||||
if (ScriptableObject is AbstractMap)
|
||||
{
|
||||
Selection.objects = new UnityEngine.Object[1] { ((AbstractMap)ScriptableObject).gameObject };
|
||||
}
|
||||
}
|
||||
isDragged = true;
|
||||
GUI.changed = true;
|
||||
isSelected = true;
|
||||
//nodeStyle = selectedNodeStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.changed = true;
|
||||
isSelected = false;
|
||||
//nodeStyle = defaultNodeStyle;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.button == 1 && isSelected && rect.Contains(e.mousePosition))
|
||||
{
|
||||
ProcessContextMenu();
|
||||
e.Use();
|
||||
}
|
||||
break;
|
||||
|
||||
case EventType.MouseUp:
|
||||
isDragged = false;
|
||||
break;
|
||||
|
||||
//case EventType.MouseDrag:
|
||||
// if (e.button == 0 && isDragged)
|
||||
// {
|
||||
// rect.position += e.delta;
|
||||
// e.Use();
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ProcessContextMenu()
|
||||
{
|
||||
//GenericMenu genericMenu = new GenericMenu();
|
||||
//genericMenu.AddItem(new GUIContent("Remove node"), false, OnClickRemoveNode);
|
||||
//genericMenu.ShowAsContext();
|
||||
}
|
||||
|
||||
private void OnClickRemoveNode()
|
||||
{
|
||||
if (OnRemoveNode != null)
|
||||
{
|
||||
OnRemoveNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawConnections()
|
||||
{
|
||||
if (Connections != null)
|
||||
{
|
||||
for (int i = 0; i < Connections.Count; i++)
|
||||
{
|
||||
Connections[i].Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dive(object obj, bool showModifiers = true, int depth = 0)
|
||||
{
|
||||
if (obj == null)
|
||||
return;
|
||||
|
||||
_isRoot = depth == 0;
|
||||
if (ScriptableObject is ModifierStackBase)
|
||||
_expanded = showModifiers;
|
||||
|
||||
foreach (FieldInfo fi in obj.GetType().GetFields().Where(prop => prop.IsDefined(typeof(NodeEditorElementAttribute), false)))
|
||||
{
|
||||
//field SO
|
||||
#if ENABLE_WINMD_SUPPORT
|
||||
if (typeof(ILayer).GetTypeInfo().IsAssignableFrom(fi.FieldType.GetTypeInfo()))
|
||||
#else
|
||||
if (typeof(ILayer).IsAssignableFrom(fi.FieldType))
|
||||
#endif
|
||||
{
|
||||
var val = fi.GetValue(obj) as ILayer;
|
||||
if (val != null)
|
||||
{
|
||||
var name = (fi.GetCustomAttributes(typeof(NodeEditorElementAttribute), true)[0] as NodeEditorElementAttribute).Name;
|
||||
var conp = new ConnectionPoint(this, "", name, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle);
|
||||
ConnectionPoints.Add(conp);
|
||||
var newNode = new Node(val);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, conp));
|
||||
|
||||
newNode.Dive(val, showModifiers, depth + 1);
|
||||
_propCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//field list<SO>
|
||||
Type type = fi.FieldType;
|
||||
if (type.IsGenericType && type.GetGenericTypeDefinition()
|
||||
== typeof(List<>))
|
||||
{
|
||||
if (typeof(LayerProperties).IsAssignableFrom(type.GetGenericArguments()[0]))
|
||||
{
|
||||
if (typeof(VectorSubLayerProperties).IsAssignableFrom(type.GetGenericArguments()[0]))
|
||||
{
|
||||
var val = fi.GetValue(obj);
|
||||
if (val is List<VectorSubLayerProperties>)
|
||||
{
|
||||
foreach (VectorSubLayerProperties listitem in val as IEnumerable)
|
||||
{
|
||||
//var prop = new SerializedObject(listitem);
|
||||
var cc = new ConnectionPoint(this, "", listitem.coreOptions.sublayerName, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle, listitem);
|
||||
|
||||
ConnectionPoints.Add(cc);
|
||||
_propCount++;
|
||||
var newNode = new Node(listitem);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, cc));
|
||||
newNode.Dive(listitem, showModifiers, depth + 1);
|
||||
}
|
||||
}
|
||||
else if (val is List<PrefabItemOptions>)
|
||||
{
|
||||
foreach (PrefabItemOptions listitem in val as IEnumerable)
|
||||
{
|
||||
//var prop = new SerializedObject(listitem);
|
||||
var cc = new ConnectionPoint(this, "", listitem.coreOptions.sublayerName, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle, listitem);
|
||||
|
||||
ConnectionPoints.Add(cc);
|
||||
_propCount++;
|
||||
var newNode = new Node(listitem);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, cc));
|
||||
newNode.Dive(listitem, showModifiers, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = (fi.GetCustomAttributes(typeof(NodeEditorElementAttribute), true)[0] as NodeEditorElementAttribute).Name;
|
||||
var conp = new ConnectionPoint(this, "", name, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle);
|
||||
ConnectionPoints.Add(conp);
|
||||
var val = fi.GetValue(obj);
|
||||
if (val is IEnumerable)
|
||||
{
|
||||
foreach (ScriptableObject listitem in val as IEnumerable)
|
||||
{
|
||||
var newNode = new Node(listitem);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, conp));
|
||||
newNode.Dive(listitem, showModifiers, depth + 1);
|
||||
}
|
||||
_propCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = (fi.GetCustomAttributes(typeof(NodeEditorElementAttribute), true)[0] as NodeEditorElementAttribute).Name;
|
||||
var conp = new ConnectionPoint(this, "", name, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle);
|
||||
ConnectionPoints.Add(conp);
|
||||
var val = fi.GetValue(obj);
|
||||
if (val is IEnumerable)
|
||||
{
|
||||
foreach (ModifierBase listitem in val as IEnumerable)
|
||||
{
|
||||
var newNode = new Node(listitem);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, conp));
|
||||
newNode.Dive(listitem, showModifiers, depth + 1);
|
||||
}
|
||||
_propCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof(ScriptableObject).IsAssignableFrom(fi.FieldType))
|
||||
{
|
||||
var val = fi.GetValue(obj) as ModifierBase;
|
||||
if (val != null)
|
||||
{
|
||||
var name = (fi.GetCustomAttributes(typeof(NodeEditorElementAttribute), true)[0] as NodeEditorElementAttribute).Name;
|
||||
var conp = new ConnectionPoint(this, "", name, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle);
|
||||
ConnectionPoints.Add(conp);
|
||||
var newNode = new Node(val);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, conp));
|
||||
|
||||
newNode.Dive(val, showModifiers, depth + 1);
|
||||
_propCount++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach (PropertyInfo pi in obj.GetType().GetProperties().Where(prop => prop.IsDefined(typeof(NodeEditorElementAttribute), false)))
|
||||
{
|
||||
//property SO
|
||||
if (typeof(LayerProperties).IsAssignableFrom(pi.PropertyType))
|
||||
{
|
||||
var val = pi.GetValue(obj, null) as LayerProperties;
|
||||
if (val != null)
|
||||
{
|
||||
var name = (pi.GetCustomAttributes(typeof(NodeEditorElementAttribute), true)[0] as NodeEditorElementAttribute).Name;
|
||||
var conp = new ConnectionPoint(this, "", name, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle);
|
||||
ConnectionPoints.Add(conp);
|
||||
var newNode = new Node(val);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, conp));
|
||||
newNode.Dive(val, showModifiers, depth + 1);
|
||||
_propCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof(ILayer).IsAssignableFrom(pi.PropertyType))
|
||||
{
|
||||
var val = pi.GetValue(obj, null) as ILayer;
|
||||
if (val != null)
|
||||
{
|
||||
var name = (pi.GetCustomAttributes(typeof(NodeEditorElementAttribute), true)[0] as NodeEditorElementAttribute).Name;
|
||||
var conp = new ConnectionPoint(this, "", name, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle);
|
||||
ConnectionPoints.Add(conp);
|
||||
var newNode = new Node(val);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, conp));
|
||||
newNode.Dive(val, showModifiers, depth + 1);
|
||||
_propCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//property list<SO>
|
||||
Type type = pi.PropertyType;
|
||||
if (type.IsGenericType && type.GetGenericTypeDefinition()
|
||||
== typeof(List<>))
|
||||
{
|
||||
if (typeof(LayerProperties).IsAssignableFrom(type.GetGenericArguments()[0]))
|
||||
{
|
||||
var val = pi.GetValue(obj, null);
|
||||
|
||||
var name = (pi.GetCustomAttributes(typeof(NodeEditorElementAttribute), true)[0] as NodeEditorElementAttribute).Name;
|
||||
var conp = new ConnectionPoint(this, "", name, _headerHeight + _propertyHeight * _propCount, ConnectionPointType.Out, NodeBasedEditor.outPointStyle);
|
||||
ConnectionPoints.Add(conp);
|
||||
if (val is IEnumerable)
|
||||
{
|
||||
|
||||
foreach (LayerProperties listitem in val as IEnumerable)
|
||||
{
|
||||
var newNode = new Node(listitem);
|
||||
Children.Add(newNode);
|
||||
newNode.Connections.Add(new Connection(newNode.inPoint, conp));
|
||||
newNode.Dive(listitem, showModifiers, depth + 1);
|
||||
}
|
||||
_propCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ProcessNodeEvents(Event e)
|
||||
{
|
||||
bool guiChanged = ProcessEvents(e);
|
||||
|
||||
foreach (var item in Children)
|
||||
{
|
||||
item.ProcessNodeEvents(e);
|
||||
}
|
||||
|
||||
if (guiChanged)
|
||||
{
|
||||
GUI.changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 679a0efa08a678448a906413bfebad0b
|
||||
timeCreated: 1501854745
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,328 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Unity.Map;
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
|
||||
namespace Mapbox.Editor.NodeEditor
|
||||
{
|
||||
public class NodeBasedEditor : EditorWindow
|
||||
{
|
||||
[NonSerialized]
|
||||
private Vector2 _panDelta;
|
||||
[NonSerialized]
|
||||
private float _nodeHeight = 50;
|
||||
[NonSerialized]
|
||||
private Vector2 _topLeft = new Vector2(50, 50);
|
||||
//[NonSerialized]
|
||||
//private Vector2 _padding = new Vector2(50, 100);
|
||||
|
||||
//private List<Node> nodes;
|
||||
//private List<Connection> connections;
|
||||
private int _activeMap = 0;
|
||||
private List<Node> _maps;
|
||||
//private Node _rootNode;
|
||||
|
||||
public static GUIStyle nodeStyle;
|
||||
public static GUIStyle leafNodeStyle;
|
||||
public static GUIStyle optionStyle;
|
||||
public static GUIStyle selectedNodeStyle;
|
||||
public static GUIStyle inPointStyle;
|
||||
public static GUIStyle outPointStyle;
|
||||
private static Texture2D _magnifierTexture;
|
||||
public static Texture2D magnifierTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_magnifierTexture == null)
|
||||
{
|
||||
_magnifierTexture = EditorGUIUtility.FindTexture("d_ViewToolZoom");
|
||||
}
|
||||
return _magnifierTexture;
|
||||
}
|
||||
}
|
||||
private GUIStyle _optionLabel;
|
||||
|
||||
//private ConnectionPoint selectedInPoint;
|
||||
//private ConnectionPoint selectedOutPoint;
|
||||
|
||||
private Vector2 offset;
|
||||
private Vector2 drag;
|
||||
private float zoomScale = 1;
|
||||
private Vector2 zoomOrigin = new Vector2(0, 20);
|
||||
private Rect _canvasWindowRect { get { return new Rect(0, 20, position.width, position.height - 20); } }
|
||||
private Rect _optionsRect { get { return new Rect(position.width - 250, 20, 250, 60); } }
|
||||
private bool _showOptions = false;
|
||||
private Vector2 _clickedPosition;
|
||||
|
||||
[MenuItem("Mapbox/Map Editor")]
|
||||
private static void OpenWindow()
|
||||
{
|
||||
NodeBasedEditor window = GetWindow<NodeBasedEditor>();
|
||||
window.titleContent = new GUIContent("Map Editor");
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
GUIScaleUtility.CheckInit();
|
||||
//MagnifierTexture = EditorGUIUtility.FindTexture("d_ViewToolZoom");
|
||||
var textOffset = new RectOffset(12, 0, 10, 0);
|
||||
|
||||
nodeStyle = new GUIStyle();
|
||||
nodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node1.png") as Texture2D;
|
||||
nodeStyle.border = new RectOffset(12, 12, 12, 12);
|
||||
nodeStyle.richText = true;
|
||||
nodeStyle.padding = textOffset;
|
||||
|
||||
selectedNodeStyle = new GUIStyle();
|
||||
selectedNodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node1 on.png") as Texture2D;
|
||||
selectedNodeStyle.border = new RectOffset(12, 12, 12, 12);
|
||||
selectedNodeStyle.richText = true;
|
||||
selectedNodeStyle.padding = textOffset;
|
||||
|
||||
leafNodeStyle = new GUIStyle();
|
||||
leafNodeStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/node2.png") as Texture2D;
|
||||
leafNodeStyle.border = new RectOffset(12, 12, 12, 12);
|
||||
leafNodeStyle.richText = true;
|
||||
leafNodeStyle.padding = textOffset;
|
||||
|
||||
inPointStyle = new GUIStyle();
|
||||
inPointStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left.png") as Texture2D;
|
||||
inPointStyle.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left on.png") as Texture2D;
|
||||
inPointStyle.border = new RectOffset(4, 4, 12, 12);
|
||||
|
||||
outPointStyle = new GUIStyle();
|
||||
outPointStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right.png") as Texture2D;
|
||||
outPointStyle.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right on.png") as Texture2D;
|
||||
outPointStyle.border = new RectOffset(4, 4, 12, 12);
|
||||
|
||||
Parse();
|
||||
}
|
||||
|
||||
private void Parse(bool showModifiers = true)
|
||||
{
|
||||
if (_maps == null)
|
||||
_maps = new List<Node>();
|
||||
else
|
||||
_maps.Clear();
|
||||
|
||||
var abstractMaps = FindObjectsOfType<AbstractMap>();
|
||||
|
||||
//foreach (var abstractMap in abstractMaps)
|
||||
//{
|
||||
// foreach (FieldInfo fi in abstractMap.GetType().GetFields().Where(x => x.IsDefined(typeof(NodeEditorElementAttribute), true)))
|
||||
// {
|
||||
// var val = fi.GetValue(abstractMap) as ScriptableObject;
|
||||
// if (typeof(ScriptableObject).IsAssignableFrom(fi.FieldType) && val != null)
|
||||
// {
|
||||
// var map = abstractMap.MapVisualizer;
|
||||
// var mapNode = new Node(map as ScriptableObject);
|
||||
// mapNode.title = map.name;
|
||||
// mapNode.subtitle = "Map Visualizer";
|
||||
// _maps.Add(mapNode);
|
||||
// mapNode.Dive(map, showModifiers);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
foreach (var abstractMap in abstractMaps)
|
||||
{
|
||||
if (abstractMap != null)
|
||||
{
|
||||
var map = abstractMap;
|
||||
var mapNode = new Node(map);
|
||||
//{
|
||||
// title = "Map",
|
||||
// subtitle = "Map Visualizer"
|
||||
//};
|
||||
_maps.Add(mapNode);
|
||||
mapNode.Dive(map, showModifiers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (optionStyle == null)
|
||||
{
|
||||
optionStyle = (GUIStyle)"ObjectPickerPreviewBackground";
|
||||
optionStyle.padding = new RectOffset(10, 10, 10, 10);
|
||||
}
|
||||
|
||||
DrawGrid(20, 0.2f, Color.gray);
|
||||
DrawGrid(100, 0.4f, Color.gray);
|
||||
OnGUIToolBar();
|
||||
|
||||
var test = _canvasWindowRect;
|
||||
var sc = GUIScaleUtility.BeginScale(ref test, zoomOrigin, zoomScale, false);
|
||||
|
||||
if (_activeMap < _maps.Count)
|
||||
{
|
||||
DrawNodes(sc);
|
||||
|
||||
ProcessNodeEvents(Event.current);
|
||||
ProcessEvents(Event.current);
|
||||
|
||||
if (GUI.changed) Repaint();
|
||||
}
|
||||
GUIScaleUtility.EndScale();
|
||||
|
||||
if (_showOptions)
|
||||
{
|
||||
GUILayout.BeginArea(_optionsRect, optionStyle);
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Hide Modifiers", (GUIStyle)"ButtonLeft", GUILayout.Width(115)))
|
||||
{
|
||||
Parse(false);
|
||||
}
|
||||
if (GUILayout.Button("Show Modifiers", (GUIStyle)"ButtonRight", GUILayout.Width(115)))
|
||||
{
|
||||
Parse(true);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
if (GUILayout.Button("Reset Zoom", EditorStyles.miniButton, GUILayout.Width(230)))
|
||||
{
|
||||
zoomScale = 1;
|
||||
}
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUIToolBar()
|
||||
{
|
||||
GUILayout.BeginHorizontal(EditorStyles.toolbar);
|
||||
|
||||
if (GUILayout.Button("Map Visualizers", EditorStyles.toolbarDropDown))
|
||||
{
|
||||
GenericMenu toolsMenu = new GenericMenu();
|
||||
var i = 0;
|
||||
foreach (var item in _maps)
|
||||
{
|
||||
toolsMenu.AddItem(new GUIContent(item.title), false, ChangeMap, i);
|
||||
i++;
|
||||
}
|
||||
// Offset menu from right of editor window
|
||||
toolsMenu.DropDown(new Rect(0, 0, 0, 16));
|
||||
EditorGUIUtility.ExitGUI();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Refresh", EditorStyles.toolbarButton, GUILayout.Width(100)))
|
||||
{
|
||||
Parse();
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (GUILayout.Button("Options", EditorStyles.toolbarButton, GUILayout.Width(100)))
|
||||
{
|
||||
_showOptions = !_showOptions;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void ChangeMap(object i)
|
||||
{
|
||||
_activeMap = (int)i;
|
||||
}
|
||||
|
||||
void OnFocus()
|
||||
{
|
||||
Parse();
|
||||
}
|
||||
|
||||
private void DrawGrid(float gridSpacing, float gridOpacity, Color gridColor)
|
||||
{
|
||||
int widthDivs = Mathf.CeilToInt(position.width / gridSpacing);
|
||||
int heightDivs = Mathf.CeilToInt(position.height / gridSpacing);
|
||||
|
||||
Handles.BeginGUI();
|
||||
Handles.color = new Color(gridColor.r, gridColor.g, gridColor.b, gridOpacity);
|
||||
|
||||
offset += drag * 0.5f;
|
||||
Vector3 newOffset = new Vector3(offset.x % gridSpacing, offset.y % gridSpacing, 0);
|
||||
|
||||
for (int i = 0; i < widthDivs; i++)
|
||||
{
|
||||
Handles.DrawLine(new Vector3(gridSpacing * i, -gridSpacing, 0) + newOffset, new Vector3(gridSpacing * i, position.height, 0f) + newOffset);
|
||||
}
|
||||
|
||||
for (int j = 0; j < heightDivs; j++)
|
||||
{
|
||||
Handles.DrawLine(new Vector3(-gridSpacing, gridSpacing * j, 0) + newOffset, new Vector3(position.width, gridSpacing * j, 0f) + newOffset);
|
||||
}
|
||||
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI();
|
||||
}
|
||||
|
||||
private void DrawNodes(Vector2 sc)
|
||||
{
|
||||
_maps[_activeMap].Draw(_topLeft + _panDelta + sc, 100, _nodeHeight);
|
||||
GUI.changed = true;
|
||||
}
|
||||
|
||||
private void ProcessEvents(Event e)
|
||||
{
|
||||
drag = Vector2.zero;
|
||||
switch (e.type)
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
if (e.button == 0)
|
||||
{
|
||||
_clickedPosition = e.mousePosition;
|
||||
ClearConnectionSelection();
|
||||
}
|
||||
break;
|
||||
|
||||
case EventType.MouseDrag:
|
||||
if (e.button == 0)
|
||||
{
|
||||
if (_canvasWindowRect.Contains(_clickedPosition))
|
||||
{
|
||||
_panDelta += e.delta;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EventType.ScrollWheel:
|
||||
{
|
||||
|
||||
Vector2 delta = Event.current.delta;
|
||||
Vector2 zoomedMousePos = (e.mousePosition - _canvasWindowRect.min) / zoomScale + zoomOrigin;
|
||||
|
||||
float oldZoomScale = zoomScale;
|
||||
|
||||
float zoomDelta = -delta.y / 150.0f;
|
||||
zoomScale -= zoomDelta;
|
||||
zoomScale = Mathf.Clamp(zoomScale, 0.5f, 2.0f);
|
||||
zoomOrigin += (zoomedMousePos - zoomOrigin) - (oldZoomScale / zoomScale) * (zoomedMousePos - zoomOrigin);
|
||||
|
||||
Event.current.Use();
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case EventType.MouseUp:
|
||||
if (e.button == 0)
|
||||
{
|
||||
_clickedPosition = new Vector2(Mathf.Infinity, Mathf.Infinity);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessNodeEvents(Event e)
|
||||
{
|
||||
_maps[_activeMap].ProcessNodeEvents(e);
|
||||
}
|
||||
|
||||
private void ClearConnectionSelection()
|
||||
{
|
||||
//selectedInPoint = null;
|
||||
//selectedOutPoint = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26556c3e20124f847973c22be86cf80a
|
||||
timeCreated: 1501854727
|
||||
licenseType: Free
|
||||
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;//100000;
|
||||
|
||||
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:
|
||||
161
Assets/Mapbox SDK/Mapbox/Unity/Editor/PopupSelectionMenu.cs
Normal file
161
Assets/Mapbox SDK/Mapbox/Unity/Editor/PopupSelectionMenu.cs
Normal file
@@ -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,21 @@
|
||||
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");
|
||||
EditorGUILayout.PropertyField(camera, new GUIContent
|
||||
{
|
||||
text = camera.displayName,
|
||||
tooltip = "Camera to control map extent."
|
||||
}, GUILayout.Height(_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,67 @@
|
||||
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);
|
||||
}
|
||||
//
|
||||
// if ((VectorPrimitiveType)primitiveType.enumValueIndex == VectorPrimitiveType.Line)
|
||||
// {
|
||||
// EditorGUI.BeginChangeCheck();
|
||||
// EditorGUILayout.PropertyField(property.FindPropertyRelative("lineWidth"));
|
||||
// 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 _mapIdGui = new GUIContent
|
||||
{
|
||||
text = "Map Id",
|
||||
tooltip = "Map Id corresponding to the tileset."
|
||||
};
|
||||
|
||||
string CustomSourceMapId
|
||||
{
|
||||
get
|
||||
{
|
||||
return EditorPrefs.GetString(objectId + "ElevationLayerProperties_customSourceMapId");
|
||||
}
|
||||
set
|
||||
{
|
||||
EditorPrefs.SetString(objectId + "ElevationLayerProperties_customSourceMapId", 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, _mapIdGui);
|
||||
GUI.enabled = true;
|
||||
break;
|
||||
case ElevationSourceType.Custom:
|
||||
layerSourceId.stringValue = string.IsNullOrEmpty(CustomSourceMapId) ? MapboxDefaultElevation.GetParameters(ElevationSourceType.MapboxTerrain).Id : CustomSourceMapId;
|
||||
EditorGUILayout.PropertyField(sourceOptionsProperty, _mapIdGui);
|
||||
CustomSourceMapId = 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,26 @@
|
||||
namespace Mapbox.Editor
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
/*
|
||||
[CustomPropertyDrawer(typeof(FeatureBundleList))]
|
||||
public class FeatureBundleListDrawer : PropertyDrawer
|
||||
{
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var features = property.FindPropertyRelative("features");
|
||||
for (int i = 0; i < features.arraySize; i++)
|
||||
{
|
||||
var feature = features.GetArrayElementAtIndex(i);
|
||||
var name = feature.FindPropertyRelative("features");
|
||||
//EditorGUILayout.PropertyField(extrusionGeometryType, extrusionGeometryGUI);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc7416265a7cf4abda73c7224be18d0a
|
||||
timeCreated: 1533675584
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,711 @@
|
||||
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;
|
||||
|
||||
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;
|
||||
int count = sourceTypeProperty.enumDisplayNames.Length;
|
||||
if (!_isGUIContentSet)
|
||||
{
|
||||
_sourceTypeContent = new GUIContent[count];
|
||||
for (int extIdx = 0; extIdx < count; extIdx++)
|
||||
{
|
||||
_sourceTypeContent[extIdx] = new GUIContent
|
||||
{
|
||||
text = displayNames[extIdx],
|
||||
tooltip = ((VectorSourceType)extIdx).Description(),
|
||||
};
|
||||
}
|
||||
_isGUIContentSet = true;
|
||||
}
|
||||
|
||||
sourceTypeValue = (VectorSourceType)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.MapboxStreetsWithBuildingIds:
|
||||
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 Map 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 Map 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();
|
||||
//var presetTypes = property.FindPropertyRelative("presetFeatureTypes");
|
||||
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))
|
||||
{
|
||||
((VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property)).OnSubLayerPropertyAdded(new VectorLayerUpdateArgs { property = EditorHelper.GetTargetObjectOfProperty(subLayer) as MapboxDataProperty });
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
//GeometryMaterialOptions geometryMaterialOptionsReference = MapboxDefaultStyles.GetDefaultAssets();
|
||||
|
||||
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 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;
|
||||
|
||||
|
||||
//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 layerName = layerProperty.FindPropertyRelative("coreOptions.layerName");
|
||||
//var roadLayerName = layerProperty.FindPropertyRelative("roadLayer");
|
||||
//var landuseLayerName = layerProperty.FindPropertyRelative("landuseLayer");
|
||||
|
||||
|
||||
var subLayerName = subLayerCoreOptions.FindPropertyRelative("sublayerName").stringValue;
|
||||
var visualizerLayer = subLayerCoreOptions.FindPropertyRelative("layerName").stringValue;
|
||||
var subLayerType = PresetSubLayerPropertiesFetcher.GetPresetTypeFromLayerName(visualizerLayer);
|
||||
//var maskValue = layerProperty.FindPropertyRelative("_maskValue");
|
||||
//var selectedTypes = layerProperty.FindPropertyRelative("selectedTypes");
|
||||
|
||||
GUILayout.Space(-_lineHeight);
|
||||
layerProperty.FindPropertyRelative("presetFeatureType").intValue = (int)subLayerType;
|
||||
//EditorGUILayout.LabelField("Sub-type : " + "Highway", visualizerNameAndType);
|
||||
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 ***********************************//
|
||||
|
||||
//*********************** TYPE DROPDOWN BEGINS ***********************************//
|
||||
//if (_streetsV7TileStats == null || subTypeValues == null)
|
||||
//{
|
||||
// subTypeValues = GetSubTypeValues(layerProperty, visualizerLayer, sourceType);
|
||||
//}
|
||||
|
||||
//if ((layerName.stringValue == roadLayerName.stringValue || layerName.stringValue == landuseLayerName.stringValue) && subTypeValues!=null)
|
||||
//{
|
||||
// maskValue.intValue = EditorGUILayout.MaskField("Type",maskValue.intValue, subTypeValues);
|
||||
// string selectedOptions = string.Empty;
|
||||
// for (int i = 0; i < subTypeValues.Length; i++)
|
||||
// {
|
||||
// if ((maskValue.intValue & (1 << i)) == (1 << i))
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(selectedOptions))
|
||||
// {
|
||||
// selectedOptions = subTypeValues[i];
|
||||
// continue;
|
||||
// }
|
||||
// selectedOptions += "," + subTypeValues[i];
|
||||
// }
|
||||
// }
|
||||
// selectedTypes.stringValue = selectedOptions;
|
||||
//}
|
||||
//*********************** TYPE DROPDOWN 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)
|
||||
{
|
||||
//tileJSONData.ClearData();
|
||||
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 MapId / 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,242 @@
|
||||
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)
|
||||
{
|
||||
//property.serializedObject.Update();
|
||||
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.normal.textColor = Color.red;
|
||||
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);//(GUIStyle)"minipopUp");
|
||||
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 _mapIdGui = new GUIContent
|
||||
{
|
||||
text = "Map Id",
|
||||
tooltip = "Map Id corresponding to 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, _mapIdGui);
|
||||
GUI.enabled = true;
|
||||
break;
|
||||
case ImagerySourceType.Custom:
|
||||
EditorGUILayout.PropertyField(sourceOptionsProperty, new GUIContent { text = "Map Id / Style URL", tooltip = _mapIdGui.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,57 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//[CustomPropertyDrawer(typeof(TypeVisualizerTuple))]
|
||||
//public class TypeVisualizerBaseDrawer : 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;
|
||||
|
||||
// EditorGUI.PropertyField(position, property.FindPropertyRelative("Stack"));
|
||||
|
||||
// EditorGUI.EndProperty();
|
||||
// }
|
||||
// public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
// {
|
||||
// // Reserve space for the total visible properties.
|
||||
// int rows = 2;
|
||||
// //Debug.Log("Height - " + rows * lineHeight);
|
||||
// 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,26 @@
|
||||
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"));
|
||||
|
||||
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,75 @@
|
||||
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:
|
||||
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:
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user