void CreatePopup()
        {
            int channelCount = SlotValueHelper.GetChannelCount(m_Node.FindSlot <MaterialSlot>(m_SlotId).concreteValueType);

            if (m_PopupField != null)
            {
                if (channelCount == m_PreviousChannelCount)
                {
                    return;
                }

                Remove(m_PopupField);
            }

            m_PreviousChannelCount = channelCount;
            List <string> popupEntries = new List <string>();

            for (int i = 0; i < channelCount; i++)
            {
                popupEntries.Add(m_ValueNames[i]);
            }

            var value = (int)m_PropertyInfo.GetValue(m_Node, null);

            if (value >= channelCount)
            {
                value = 0;
            }

            m_PopupField = new PopupField <string>(popupEntries, value);
            m_PopupField.RegisterValueChangedCallback(OnValueChanged);
            Add(m_PopupField);
        }
Esempio n. 2
0
        private void UpdatePopup()
        {
            var value = (int)m_PropertyInfo.GetValue(m_Node, null);

            using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
            {
                int      channelCount   = SlotValueHelper.GetChannelCount(m_Node.FindSlot <MaterialSlot>(m_SlotId).concreteValueType);
                string[] enumEntryNames = Enum.GetNames(typeof(TextureChannel));
                string[] popupEntries   = new string[channelCount];
                for (int i = 0; i < popupEntries.Length; i++)
                {
                    popupEntries[i] = enumEntryNames[i];
                }
                value = EditorGUILayout.MaskField(m_Label, value, popupEntries);

                if (changeCheckScope.changed)
                {
                    m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
                    m_PropertyInfo.SetValue(m_Node, value, null);
                }
            }
        }