You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mapbox-sdk/Unity/Editor/PropertyDrawers/MapOptionsDrawer.cs

78 lines
2.7 KiB

1 year ago
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();
}
}
}