protected PropertiesReorderableList(SerializedProperty property, Action applyAction) { m_Property = property; m_Apply = applyAction; m_ListItems = new List <string>(); m_ListOptions = GetOptions(); m_EditableParametersForSelectedItem = new ParameterListView { onChange = OnParametersChanged }; m_ParametersForEachListItem = InputControlLayout.ParseNameAndParameterList(m_Property.stringValue) ?? new InputControlLayout.NameAndParameters[0]; foreach (var nameAndParams in m_ParametersForEachListItem) { m_ListItems.Add(nameAndParams.name); } m_ListView = new ReorderableList(m_ListItems, typeof(string)) { headerHeight = 3, onAddDropdownCallback = (rect, list) => { var menu = new GenericMenu(); foreach (var name in m_ListOptions.names) { menu.AddItem(new GUIContent(name), false, OnAddElement, name); } menu.ShowAsContext(); }, onRemoveCallback = list => { var index = list.index; list.list.RemoveAt(index); ArrayHelpers.EraseAt(ref m_ParametersForEachListItem, index); m_EditableParametersForSelectedItem.Clear(); m_Apply(); list.index = -1; }, onReorderCallbackWithDetails = (list, oldIndex, newIndex) => { MemoryHelpers.Swap(ref m_ParametersForEachListItem[oldIndex], ref m_ParametersForEachListItem[newIndex]); OnSelection(list); m_Apply(); }, onSelectCallback = OnSelection }; }
protected PropertiesReorderableList(SerializedProperty property, Action applyAction, string expectedControlLayout) { m_Property = property; m_Apply = applyAction; m_ListItems = new List <string>(); m_ListOptions = GetOptions(); m_EditableParametersForSelectedItem = new ParameterListView { onChange = OnParametersChanged }; m_ParametersForEachListItem = InputControlLayout.ParseNameAndParameterList(m_Property.stringValue) ?? new InputControlLayout.NameAndParameters[0]; m_ExpectedControlLayout = expectedControlLayout; foreach (var nameAndParams in m_ParametersForEachListItem) { var name = ObjectNames.NicifyVariableName(nameAndParams.name); ////REVIEW: finding this kind of stuff should probably have better support globally on the asset; e.g. some //// notification that pops up and allows fixing all occurrences in one click // Find out if we still support this option and indicate it in the list, if we don't. if (m_ListOptions.LookupTypeRegistration(new InternedString(nameAndParams.name)) == null) { name += " (Obsolete)"; } m_ListItems.Add(name); } m_ListView = new ReorderableList(m_ListItems, typeof(string)) { headerHeight = 3, onAddDropdownCallback = (rect, list) => { Type expectedValueType = null; if (!string.IsNullOrEmpty(m_ExpectedControlLayout)) { expectedValueType = EditorInputControlLayoutCache.GetValueType(m_ExpectedControlLayout); } // Add only original names to the menu and not aliases. var menu = new GenericMenu(); foreach (var name in m_ListOptions.internedNames.Where(x => !m_ListOptions.aliases.Contains(x)).OrderBy(x => x.ToString())) { // Skip if not compatible with value type. if (expectedValueType != null) { var type = m_ListOptions.LookupTypeRegistration(name); var valueType = GetValueType(type); if (valueType != null && !expectedValueType.IsAssignableFrom(valueType)) { continue; } } var niceName = ObjectNames.NicifyVariableName(name); menu.AddItem(new GUIContent(niceName), false, OnAddElement, name.ToString()); } menu.ShowAsContext(); }, onRemoveCallback = list => { var index = list.index; list.list.RemoveAt(index); ArrayHelpers.EraseAt(ref m_ParametersForEachListItem, index); m_EditableParametersForSelectedItem.Clear(); m_Apply(); list.index = -1; }, onReorderCallbackWithDetails = (list, oldIndex, newIndex) => { MemoryHelpers.Swap(ref m_ParametersForEachListItem[oldIndex], ref m_ParametersForEachListItem[newIndex]); OnSelection(list); m_Apply(); }, onSelectCallback = OnSelection }; }