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);
        }
        public void TestAllCombos()
        {
            foreach (var slot in m_CFNode.GetInputSlots <MaterialSlot>())
            {
                // Should only be one edge per slot on this graph
                var edge = m_Graph.GetEdges(slot.slotReference).FirstOrDefault();
                if (edge == null)
                {
                    continue;
                }

                var outputNode    = edge.outputSlot.node;
                var outputSlot    = outputNode.GetOutputSlots <MaterialSlot>().First(s => s.id == edge.outputSlot.slotId);
                var curOutputType = outputSlot.valueType.ToConcreteSlotValueType();

                foreach (var slotValType in (SlotValueType[])Enum.GetValues(typeof(SlotValueType)))
                {
                    var newSlot = MaterialSlot.CreateMaterialSlot(slotValType, slot.id, slot.displayName, slot.shaderOutputName,
                                                                  slot.slotType, Vector4.zero);
                    m_CFNode.AddSlot(newSlot);
                    m_Graph.ValidateGraph();

                    // Verify all errors are expected
                    foreach (var message in m_Graph.messageManager.GetNodeMessages())
                    {
                        if (message.Key.Equals(m_CFNode.objectId) && message.Value.Exists(msg =>
                                                                                          msg.severity == ShaderCompilerMessageSeverity.Error))
                        {
                            Assert.IsFalse(SlotValueHelper.AreCompatible(slotValType, curOutputType),
                                           $"{curOutputType} failed to convert to {slotValType} but that conversion is supported. Error: {message.Value.First().message}");
                        }
                        else
                        {
                            Assert.IsTrue(SlotValueHelper.AreCompatible(slotValType, curOutputType),
                                          $"{curOutputType} successfully connected to {slotValType} but that conversion is not supported.");
                        }
                    }

                    m_Graph.ClearErrorsForNode(m_CFNode);
                }

                // Replace original slot
                m_CFNode.AddSlot(slot);
            }
        }
Exemple #3
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);
                }
            }
        }