Exemplo n.º 1
0
        /// <summary>
        /// Adds a new attribute to the list.
        /// </summary>
        private void OnAttributeListAdd(ReorderableList list)
        {
            var attributes = m_AttributeManager.Attributes;

            if (attributes == null)
            {
                attributes = new Attribute[1];
            }
            else
            {
                Array.Resize(ref attributes, attributes.Length + 1);
            }

            var attribute = Activator.CreateInstance(typeof(Attribute)) as Attribute;
            var name      = "New Attribute";

            // Use the name of the last attribute element.
            if (m_ReorderableAttributeList.index > -1 && m_ReorderableAttributeList.index < attributes.Length - 1)
            {
                name = attributes[m_ReorderableAttributeList.index].Name;
            }
            // The name must be unique.
            if (!IsUniqueName(attributes, name))
            {
                var postfixIndex = 1;
                while (!IsUniqueName(attributes, name + " " + postfixIndex))
                {
                    postfixIndex++;
                }
                name += " " + postfixIndex;
            }
            attribute.Name = name;
            attributes[attributes.Length - 1] = attribute;
            m_AttributeManager.Attributes     = attributes;

            // Select the newly added attribute.
            m_ReorderableAttributeList.index = attributes.Length - 1;
            EditorPrefs.SetInt(SelectedAttributeIndexKey, m_ReorderableAttributeList.index);
            InspectorUtility.SetDirty(m_AttributeManager);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns the state index key for the specified attribute.
 /// </summary>
 private string GetSelectedAttributeStateIndexKey(Attribute attribute)
 {
     return(c_EditorPrefsSelectedAttributeStateIndexKey + "." + target.GetType() + "." + target.name + "." + attribute.Name);
 }