public RKnobListGUI(List <T> items, GUIContent label, ElementGUI elementGUI, ElementHeight height, ConnectionKnobs knobs, RepositionKnobs reKnobs, DefaultElement newItem) : this(items, label, elementGUI, height, knobs, reKnobs) { #if UNITY_EDITOR list.onAddCallback = (list) => { items.Insert(items.Count, newItem()); }; #endif }
public RKnobListGUI(List <T> items, GUIContent label, ElementGUI elementGUI, ElementHeight height, ConnectionKnobs knobs, RepositionKnobs reKnobs, Dropdown menu) : this(items, label, elementGUI, height, knobs, reKnobs) { #if UNITY_EDITOR list.onAddDropdownCallback = (buttonRect, list) => { menu().Show(Event.current.mousePosition + Event.current.delta); }; #endif }
private RKnobListGUI(List <T> items, GUIContent label, ElementGUI elementGUI, ElementHeight height, ConnectionKnobs knobs, RepositionKnobs reKnobs) { #if UNITY_EDITOR list = new UnityEditorInternal.ReorderableList(items, typeof(T), true, true, true, true); list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (index >= list.count || list.count <= 0)//Fixes error if .doGUI removes an element from the list { return; } elementGUI(items[index], rect); if (Event.current.type == EventType.Repaint) { reKnobs(items[index], rect); } }; list.elementHeightCallback = (index) => { return(height(items[index])); }; list.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, label, new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold }); }; list.drawElementBackgroundCallback = (rect, index, active, focused) => { if (list.count <= 0) { return; } rect.height = height(items[index]); Texture2D tex = new Texture2D(1, 1); tex.SetPixel(0, 0, new Color(0.33f, 0.66f, 1f, 0.66f)); tex.Apply(); if (active) { GUI.DrawTexture(rect, tex as Texture); } }; list.onRemoveCallback = (list) => { foreach (var knob in knobs(items[list.index])) { knob.body.DeleteConnectionPort(knob); } items.RemoveAt(list.index); }; #endif }