private void DrawPresets(string libraryPath)
{
if (GUIClip.visibleRect.width > 0)
{
m_LastRepaintedWidth = GUIClip.visibleRect.width;
}
if (m_LastRepaintedWidth < 0)
{
GUILayoutUtility.GetRect(1, 1); // Ensure consistent call
HandleUtility.Repaint(); // Wait until we have a proper width
return;
}
PresetLibrary lib = PresetLibraryManager.instance.GetLibrary(m_SaveLoadHelper, libraryPath) as PresetLibrary;
if (lib == null)
{
Debug.Log("Could not load preset library '" + libraryPath + "'");
return;
}
SetupGrid(m_LastRepaintedWidth, lib.Count(), itemViewMode);
int showNumPresets = Mathf.Min(lib.Count(), maxShowNumPresets);
int hiddenNumPresets = lib.Count() - showNumPresets;
float contentHeight = m_Grid.CalcRect(showNumPresets - 1, 0f).yMax + (hiddenNumPresets > 0 ? 20f : 0f);
Rect reservedRect = GUILayoutUtility.GetRect(1, contentHeight);
float spaceBetweenPresetAndText = presetSize.x + 6f;
for (int index = 0; index < showNumPresets; ++index)
{
Rect r = m_Grid.CalcRect(index, reservedRect.y);
Rect presetRect = new Rect(r.x, r.y, presetSize.x, presetSize.y);
lib.Draw(presetRect, index);
if (itemViewMode == PresetLibraryEditorState.ItemViewMode.List)
{
Rect nameRect = new Rect(r.x + spaceBetweenPresetAndText, r.y, r.width - spaceBetweenPresetAndText, r.height);
string name = lib.GetName(index);
GUI.Label(nameRect, name);
}
}
if (hiddenNumPresets > 0)
{
Rect textRect = new Rect(m_Grid.CalcRect(0, 0).x, reservedRect.y + contentHeight - 20f, reservedRect.width, 20f);
GUI.Label(textRect, string.Format("+ {0} more...", hiddenNumPresets));
}
}