public void Init(Rect position, SerializedProperty property, GUIContent label) {
			
			if (property == null) return;
			if (this.inited == true) return;
			
			this.window = (property.serializedObject.targetObject as LayoutWindowType);

			this.items = new List<SerializedProperty>();
			this.components = new List<UnityEngine.UI.Windows.Types.Layout.Component>();
			for (int i = 0; i < property.arraySize; ++i) {
				
				var element = property.GetArrayElementAtIndex(i);
				if (this.window.layout.layout == null) continue;
				
				var rootElement = this.window.layout.layout.GetRootByTag(this.window.layout.components[i].tag);
				if (rootElement != null && rootElement.showInComponentsList == true) {
					
					this.components.Add(this.window.layout.components[i]);
					this.items.Add(element);
					
				}
				
			}
			
			this.onItemDraw = (rect, item) => {
				
				var h = 0f;
				return LayoutSettingsEditor.OnItemDraw(this.window, this.items, this.components, true, true, rect, item, out h);
				
			};
			
			System.Func<int, float> getHeight = (index) => {
				
				var h = 56f;
				LayoutSettingsEditor.OnItemDraw(this.window, this.items, this.components, false, true, new Rect(), this.items[index], out h);
				
				return h;
				
			};
			
			this.elements = new ReorderableListControl(ReorderableListFlags.HideAddButton |
			                                           ReorderableListFlags.HideRemoveButtons |
			                                           ReorderableListFlags.DisableAutoScroll |
			                                           ReorderableListFlags.DisableReordering);
			
			this.adapter = new ComponentsListAdaptor<SerializedProperty>(this.items, this.onItemDraw, getHeight);
			
			this.inited = true;
			
		}
Beispiel #2
0
 /// <inheritdoc cref="DoListField{T}(IList{T}, ReorderableListControl.ItemDrawer{T}, ReorderableListControl.DrawEmpty, float, ReorderableListFlags)"/>
 public static void ListField <T>(IList <T> list, ReorderableListControl.ItemDrawer <T> drawItem, float itemHeight)
 {
     DoListField <T>(list, drawItem, null, itemHeight, 0);
 }
Beispiel #3
0
 /// <inheritdoc cref="DoListFieldAbsolute{T}(Rect, IList{T}, ReorderableListControl.ItemDrawer{T}, ReorderableListControl.DrawEmptyAbsolute, float, ReorderableListFlags)"/>
 public static void ListFieldAbsolute <T>(Rect position, IList <T> list, ReorderableListControl.ItemDrawer <T> drawItem, ReorderableListControl.DrawEmptyAbsolute drawEmpty)
 {
     DoListFieldAbsolute <T>(position, list, drawItem, drawEmpty, DefaultItemHeight, 0);
 }
Beispiel #4
0
 /// <inheritdoc cref="DoListFieldAbsolute{T}(Rect, IList{T}, ReorderableListControl.ItemDrawer{T}, ReorderableListControl.DrawEmptyAbsolute, float, ReorderableListFlags)"/>
 public static void ListFieldAbsolute <T>(Rect position, IList <T> list, ReorderableListControl.ItemDrawer <T> drawItem, float itemHeight, ReorderableListFlags flags)
 {
     DoListFieldAbsolute <T>(position, list, drawItem, null, itemHeight, flags);
 }
Beispiel #5
0
 /// <inheritdoc cref="DoListField{T}(IList{T}, ReorderableListControl.ItemDrawer{T}, ReorderableListControl.DrawEmpty, float, ReorderableListFlags)"/>
 public static void ListField <T>(IList <T> list, ReorderableListControl.ItemDrawer <T> drawItem, ReorderableListControl.DrawEmpty drawEmpty, float itemHeight, ReorderableListFlags flags)
 {
     DoListField <T>(list, drawItem, drawEmpty, itemHeight, flags);
 }
Beispiel #6
0
 /// <inheritdoc cref="DoListField{T}(IList{T}, ReorderableListControl.ItemDrawer{T}, ReorderableListControl.DrawEmpty, float, ReorderableListFlags)"/>
 public static void ListField <T>(IList <T> list, ReorderableListControl.ItemDrawer <T> drawItem, ReorderableListControl.DrawEmpty drawEmpty)
 {
     DoListField <T>(list, drawItem, drawEmpty, DefaultItemHeight, 0);
 }
Beispiel #7
0
        /// <summary>
        /// Draw list field control.
        /// </summary>
        /// <param name="list">The list which can be reordered.</param>
        /// <param name="drawItem">Callback to draw list item.</param>
        /// <param name="drawEmpty">Callback to draw custom content for empty list (optional).</param>
        /// <param name="itemHeight">Height of a single list item.</param>
        /// <param name="flags">Optional flags to pass into list field.</param>
        /// <typeparam name="T">Type of list item.</typeparam>
        private static void DoListField <T>(IList <T> list, ReorderableListControl.ItemDrawer <T> drawItem, ReorderableListControl.DrawEmpty drawEmpty, float itemHeight, ReorderableListFlags flags)
        {
            var adaptor = new GenericListAdaptor <T>(list, drawItem, itemHeight);

            ReorderableListControl.DrawControlFromState(adaptor, drawEmpty, flags);
        }
Beispiel #8
0
        /// <summary>
        /// Draw list field control with absolute positioning.
        /// </summary>
        /// <param name="position">Position of control.</param>
        /// <param name="list">The list which can be reordered.</param>
        /// <param name="drawItem">Callback to draw list item.</param>
        /// <param name="drawEmpty">Callback to draw custom content for empty list (optional).</param>
        /// <param name="itemHeight">Height of a single list item.</param>
        /// <param name="flags">Optional flags to pass into list field.</param>
        /// <typeparam name="T">Type of list item.</typeparam>
        private static void DoListFieldAbsolute <T>(Rect position, IList <T> list, ReorderableListControl.ItemDrawer <T> drawItem, ReorderableListControl.DrawEmptyAbsolute drawEmpty, float itemHeight, ReorderableListFlags flags)
        {
            var adaptor = new GenericListAdaptor <T>(list, drawItem, itemHeight);

            ReorderableListControl.DrawControlFromState(position, adaptor, drawEmpty, flags);
        }
Beispiel #9
0
 public CreateLanguageListAdaptor(List <SmartCultureInfo> list, ReorderableListControl.ItemDrawer <SmartCultureInfo> itemDrawer, float itemHeight)
     : base(list, itemDrawer, itemHeight)
 {
 }
 /// <summary>
 /// Initializes a new instance of <see cref="GenericListAdaptor{T}"/>.
 /// </summary>
 /// <param name="list">The list which can be reordered.</param>
 /// <param name="itemDrawer">Callback to draw list item.</param>
 /// <param name="itemHeight">Height of list item in pixels.</param>
 public GenericListAdaptor(IList <T> list, ReorderableListControl.ItemDrawer <T> itemDrawer, float itemHeight)
 {
     this._list           = list;
     this._itemDrawer     = itemDrawer ?? ReorderableListGUI.DefaultItemDrawer;
     this.FixedItemHeight = itemHeight;
 }
Beispiel #11
0
 /// <inheritdoc cref="DoListField{T}(IList{T}, ReorderableListControl.ItemDrawer{T}, ReorderableListControl.DrawEmpty, float, ReorderableListFlags)"/>
 public static void ListField <T>(IList <T> list, ReorderableListControl.ItemDrawer <T> drawItem, ReorderableListFlags flags)
 {
     DoListField <T>(list, drawItem, null, DefaultItemHeight, flags);
 }
 /// <summary>
 /// Initializes a new instance of <see cref="GenericListAdaptor{T}"/>.
 /// </summary>
 /// <param name="list">The list which can be reordered.</param>
 /// <param name="itemDrawer">Callback to draw list item.</param>
 /// <param name="itemHeight">Height of list item in pixels.</param>
 public ComponentsListAdaptor(IList <T> list, ReorderableListControl.ItemDrawer <T> itemDrawer, System.Func <int, float> getHeight) : base(list, itemDrawer, itemHeight: 0f)
 {
     this.getHeight = getHeight;
 }
Beispiel #13
0
    public static void StringMapField <TValue>(IDictionary <string, TValue> dictionary, ReorderableListControl.ItemDrawer <TValue> drawItem)
    {
        // Draw entries.
        string keyToRemove = null;

        var changedEntries = new List <KeyValuePair <string, TValue> >();

        foreach (var kvp in dictionary)
        {
            EditorGUILayout.BeginHorizontal();

            var wasGUIenabled = GUI.enabled;
            GUI.enabled = false;
            EditorGUILayout.TextField(kvp.Key);
            GUI.enabled = wasGUIenabled;

            var position = EditorGUILayout.GetControlRect(false, 16);

            var currentValue = kvp.Value;
            var newValue     = drawItem(position, currentValue);

            // Draw remove button.
            if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
            {
                keyToRemove = kvp.Key;
            }
            else
            {
                changedEntries.Add(new KeyValuePair <string, TValue>(kvp.Key, newValue));
            }

            EditorGUILayout.EndHorizontal();
        }

        // Remove whichever key the user selected, if any.
        if (keyToRemove != null)
        {
            dictionary.Remove(keyToRemove);
        }

        // Update any changed entries.
        foreach (var kvp in changedEntries)
        {
            dictionary[kvp.Key] = kvp.Value;
        }

        // Draw add entry section.
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
        {
            StringMapAddKeyWindow.Create(
                dictionary.Keys.ToList(),
                newKey => dictionary.Add(newKey, default(TValue)));
        }

        EditorGUILayout.EndHorizontal();
    }