Exemplo n.º 1
0
        protected NameAndParameterListView(SerializedProperty property, Action applyAction, string expectedControlLayout, TypeTable listOptions, Func <Type, Type> getValueType, string itemName)
        {
            m_ItemName     = itemName;
            m_GetValueType = getValueType;
            m_DeleteButton = EditorGUIUtility.TrIconContent("Toolbar Minus", $"Delete {itemName}");
            m_UpButton     = EditorGUIUtility.TrIconContent(GUIHelpers.LoadIcon("ChevronUp"), $"Move {itemName} up");
            m_DownButton   = EditorGUIUtility.TrIconContent(GUIHelpers.LoadIcon("ChevronDown"), $"Move {itemName} down");

            m_Property    = property;
            m_Apply       = applyAction;
            m_ListOptions = listOptions;

            m_ExpectedControlLayout = expectedControlLayout;
            if (!string.IsNullOrEmpty(m_ExpectedControlLayout))
            {
                m_ExpectedValueType = EditorInputControlLayoutCache.GetValueType(m_ExpectedControlLayout);
            }

            m_ParametersForEachListItem         = NameAndParameters.ParseMultiple(m_Property.stringValue).ToArray();
            m_EditableParametersForEachListItem = new ParameterListView[m_ParametersForEachListItem.Length];

            for (var i = 0; i < m_ParametersForEachListItem.Length; i++)
            {
                m_EditableParametersForEachListItem[i] = new ParameterListView {
                    onChange = OnParametersChanged
                };
                var typeName = m_ParametersForEachListItem[i].name;
                var rowType  = m_ListOptions.LookupTypeRegistration(typeName);
                m_EditableParametersForEachListItem[i].Initialize(rowType, m_ParametersForEachListItem[i].parameters);

                var name = ObjectNames.NicifyVariableName(typeName);

                ////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 (rowType == null)
                {
                    name += " (Obsolete)";
                }
                else if (m_ExpectedValueType != null)
                {
                    var valueType = getValueType(rowType);
                    if (!m_ExpectedValueType.IsAssignableFrom(valueType))
                    {
                        name += " (Ignored)";
                    }
                }
                m_EditableParametersForEachListItem[i].name = name;
            }
        }