Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

151 changes: 151 additions & 0 deletions sdkproject/Assets/Mapbox/Unity/Editor/FeatureSubLayerTreeView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
namespace Mapbox.Editor
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.IMGUI.Controls;
using UnityEditor;
using Mapbox.Unity.Map;

public class FeatureSubLayerTreeView : TreeView
{
public SerializedProperty Layers;
private float kToggleWidth = 18f;
public int uniqueId = 3000;
public FeatureSubLayerTreeView(TreeViewState state)
: base(state)
{
//uniqueId = treeViewControlID;
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);
item.FindPropertyRelative("coreOptions.isActive").boolValue = EditorGUI.Toggle(toggleRect, item.FindPropertyRelative("coreOptions.isActive").boolValue);
args.item.displayName = item.FindPropertyRelative("coreOptions.sublayerName").stringValue;
base.RowGUI(args);
}
}
}
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 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);
item.FindPropertyRelative("coreOptions.isActive").boolValue = EditorGUI.Toggle(toggleRect, item.FindPropertyRelative("coreOptions.isActive").boolValue);
args.item.displayName = item.FindPropertyRelative("coreOptions.sublayerName").stringValue;
base.RowGUI(args);
}
}
}
18 changes: 7 additions & 11 deletions sdkproject/Assets/Mapbox/Unity/Editor/GeocodeAttributeDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@ public class GeocodeAttributeDrawer : PropertyDrawer

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUILayout.BeginHorizontal();
if (string.IsNullOrEmpty(label.text))
{
float buttonWidth = EditorGUIUtility.singleLineHeight * 4;

property.stringValue = EditorGUILayout.TextField(property.stringValue);
}
else
{
property.stringValue = EditorGUILayout.TextField(label, property.stringValue);
}
if (GUILayout.Button(new GUIContent(searchButtonContent), (GUIStyle)"minibutton", GUILayout.MaxWidth(100)))
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))
{
GeocodeAttributeSearchWindow.Open(property);
}
GUILayout.EndHorizontal();
}
}
}
Loading