I’ve been working towards a convenient Dictionary<> GUI handler for adding and removing handles to virtual teams, and be able to view them for debugging. So far, I can add teams, remove teams, add remove players from a team, and view players on each team individually. So far this approach is working as hoped. One of my problems is that my scroll view isn’t recognizing overflowing content. Keep in mind, this code was designed for use with a script named ‘TeamHandler.cs’
[TeamHandler.cs]
...
public Dictionary<string, List<Transform>> teams
...
[TeamHandlerEditor.cs]
using System.Collections;
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
[CustomEditor(typeof(TeamHandler))]
public class TeamHandlerEditor : Editor {
Vector2 scrollPos = Vector2.zero;
bool showInput = false;
string selectedTeam = "";
string newTeam;
Transform newPlyr;
public override void OnInspectorGUI () {
TeamHandler teamhandler = (TeamHandler) target;
GUIStyle verticalScrollbar = GUI.skin.verticalScrollbar;
Texture2D tmp = new Texture2D(5,5);
tmp.SetPixel(0,0, Color.white);
verticalScrollbar.onNormal.background = tmp;
verticalScrollbar.fixedHeight = 100;
verticalScrollbar.fixedWidth = 0;
// display teams as buttons
EditorGUILayout.BeginHorizontal();
try {
Dictionary<string, List<Transform>>.KeyCollection keys = teamhandler.teams.Keys;
foreach(string key in keys) {
if (GUILayout.Button(key)) {
selectedTeam = key;
}
if (GUILayout.Button("X", GUILayout.Width(20))) {
// delete team
selectedTeam = "";
teamhandler.teams.Remove(key);
}
}
if (GUILayout.Button("+", GUILayout.Width(20))) {
newTeam = "";
showInput = true;
}
} catch {}
EditorGUILayout.EndHorizontal();
// display all players within selected team
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, verticalScrollbar, GUILayout.Width(Screen.width-40), GUILayout.Height (100));
EditorGUILayout.BeginVertical();
if (teamhandler.teams.ContainsKey(selectedTeam)) {
if (teamhandler.teams[selectedTeam].Count > 0) {
foreach(Transform plyr in teamhandler.teams[selectedTeam]) {
try {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(plyr.name);
if (GUILayout.Button("X", GUILayout.Width(20))) {
// delete team
teamhandler.teams[selectedTeam].Remove(plyr);
return; // recycle
}
EditorGUILayout.EndHorizontal();
} catch {
// ignore errors
}
}
}
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndScrollView();
if (!teamhandler.teams.ContainsKey(selectedTeam) || showInput) {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Team:",GUILayout.Width(40));
newTeam = EditorGUILayout.TextField(newTeam);
if (GUILayout.Button("Add")) {
if (newTeam != "") {
teamhandler.teams.Add(newTeam, new List<Transform>());
selectedTeam = newTeam;
newTeam = "";
showInput = false;
}
}
if (GUILayout.Button("Cancel")) {
showInput = false;
}
EditorGUILayout.EndHorizontal();
} else {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Player:",GUILayout.Width(50));
newPlyr = (Transform) EditorGUILayout.ObjectField(newPlyr, typeof(Transform));
if (GUILayout.Button("Insert")) {
if (newPlyr != null) {
if (!teamhandler.teams.ContainsKey(selectedTeam))
teamhandler.teams.Add(selectedTeam, new List<Transform>() { newPlyr });
else
teamhandler.teams[selectedTeam].Add(newPlyr);
newPlyr = null;
}
}
EditorGUILayout.EndHorizontal();
}
/*myTarget.teams = EditorGUILayout.IntSlider(
"Val-you", myTarget.MyValue, 1, 10);*/
}
}
As I said, this looks, and feels, mostly as it should. Vertical scrolling still not working for overflow content. Bar is forced because it won’t appear by default.
[FIXED] One extra tweak I would like, is the availability to simply drag and drop a transform to the list to add it. Not sure how I’m going to do that, though.

For the drag and drop stuff, checkout [DragAndDrop][1]. [1]: http://docs.unity3d.com/Documentation/ScriptReference/DragAndDrop.html
– iwaldropCould you elaborate on your problem? I'm not sure how to interpret "my scroll view isn't recognizing overflowing content". And that's the only place you mention or describe the problem. Does it scroll and go blank? Does it just stop adding items? What have you tried? Have you made a simple test-case? Also the 2 pictures show 2 entirely different editors from the looks of it. What are they meant to describe? Maybe pictures showing the exact problem would help? Or am I misunderstanding your pics? Sorry to be picky, but it's hard to help with so little information to go on.
– OP_tossAwesome! Glad I helped out! I'm gonna convert the above comment to an answer. If you could mark as correct that'd be greeeeeeaat. Thanks and gl!
– OP_toss