Created
July 13, 2016 04:26
-
-
Save tm8r/567891493dbb51967b29df359e62085d to your computer and use it in GitHub Desktop.
ManyItemsWindow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections.Generic; | |
public class ManyItemsWindow : EditorWindow | |
{ | |
static ManyItemsWindow window; | |
static readonly Vector2 windowMinSize = new Vector2 (700f, 300f); | |
const float lineHeight = 16f; | |
const string itemFormat = "item_{0:00000}"; | |
Dictionary<string, bool> items; | |
List<string> keyList; | |
bool initialized; | |
Vector2 scrollPosition = Vector2.zero; | |
float rootHeight = 0f; | |
[MenuItem ("Tools/ManyItemsWindow")] | |
static void Open () | |
{ | |
if (window == null) { | |
window = CreateInstance<ManyItemsWindow> (); | |
} | |
window.minSize = windowMinSize; | |
window.ShowUtility (); | |
} | |
void OnGUI () | |
{ | |
if (!initialized) { | |
Initialize (); | |
} | |
GUILayout.BeginVertical (); | |
var itemRoot = EditorGUILayout.BeginHorizontal (); | |
scrollPosition = GUILayout.BeginScrollView (scrollPosition); | |
// 上部の描画が不要なエリアをスペースで埋める | |
var startIndex = (int)(scrollPosition.y / lineHeight); | |
GUILayout.Space (startIndex * lineHeight); | |
var listCount = keyList.Count; | |
var endIndex = listCount; | |
if (rootHeight > 0f) { | |
endIndex = startIndex + (int)(rootHeight / lineHeight); | |
if (endIndex > listCount) { | |
endIndex = listCount; | |
} | |
} | |
for (int i = startIndex; i < endIndex; i++) { | |
var key = keyList [i]; | |
items [key] = GUILayout.Toggle (items [key], key, GUILayout.Height (lineHeight)); | |
} | |
// 下部の描画が不要なエリアをスペースで埋める | |
GUILayout.Space ((listCount - endIndex) * lineHeight); | |
GUILayout.EndScrollView (); | |
EditorGUILayout.EndHorizontal (); | |
GUILayout.FlexibleSpace (); | |
if (GUILayout.Button ("Close")) { | |
window.Close (); | |
} | |
GUILayout.EndVertical (); | |
// スクロールエリアの描画が完了したタイミングで更新 | |
if (itemRoot.height > 0f) { | |
rootHeight = itemRoot.height; | |
} | |
} | |
void Initialize () | |
{ | |
initialized = true; | |
items = new Dictionary<string, bool> (); | |
for (var i = 0; i < 10000; i++) { | |
items.Add (i.ToString (itemFormat), false); | |
} | |
keyList = new List<string> (items.Keys); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment