Пример #1
0
        public void AddShaderKeyword(ShaderKeyword chunk)
        {
            if (keywords.Any(x => x.referenceName == chunk.referenceName))
            {
                return;
            }

            keywords.Add(chunk);
        }
Пример #2
0
 void AddMetaKeyword(ShaderKeyword metaKeyword)
 {
     m_MetaKeywords.Add(metaKeyword);
     m_MetaKeywordIds.Add(metaKeyword.objectId);
 }
        void UpdatePorts(ShaderKeyword keyword)
        {
            switch (keyword.keywordType)
            {
            case KeywordType.Boolean:
            {
                // Boolean type has preset slots
                AddSlot(new DynamicVectorMaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, Vector4.zero));
                AddSlot(new DynamicVectorMaterialSlot(1, "On", "On", SlotType.Input, Vector4.zero));
                AddSlot(new DynamicVectorMaterialSlot(2, "Off", "Off", SlotType.Input, Vector4.zero));
                RemoveSlotsNameNotMatching(new int[] { 0, 1, 2 });
                break;
            }

            case KeywordType.Enum:
            {
                // Get slots
                List <MaterialSlot> inputSlots = new List <MaterialSlot>();
                GetInputSlots(inputSlots);

                // Store the edges
                Dictionary <MaterialSlot, List <IEdge> > edgeDict = new Dictionary <MaterialSlot, List <IEdge> >();
                foreach (MaterialSlot slot in inputSlots)
                {
                    edgeDict.Add(slot, (List <IEdge>)slot.owner.owner.GetEdges(slot.slotReference));
                }

                // Remove old slots
                for (int i = 0; i < inputSlots.Count; i++)
                {
                    RemoveSlot(inputSlots[i].id);
                }

                // Add output slot
                AddSlot(new DynamicVectorMaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, Vector4.zero));

                // Add input slots
                int[] slotIds = new int[keyword.entries.Count + 1];
                slotIds[keyword.entries.Count] = OutputSlotId;
                for (int i = 0; i < keyword.entries.Count; i++)
                {
                    // Get slot based on entry id
                    MaterialSlot slot = inputSlots.Where(x =>
                                                         x.id == keyword.entries[i].id &&
                                                         x.RawDisplayName() == keyword.entries[i].displayName &&
                                                         x.shaderOutputName == keyword.entries[i].referenceName).FirstOrDefault();

                    // If slot doesnt exist its new so create it
                    if (slot == null)
                    {
                        slot = new DynamicVectorMaterialSlot(keyword.entries[i].id, keyword.entries[i].displayName, keyword.entries[i].referenceName, SlotType.Input, Vector4.zero);
                    }

                    AddSlot(slot);
                    slotIds[i] = keyword.entries[i].id;
                }
                RemoveSlotsNameNotMatching(slotIds);

                // Reconnect the edges
                foreach (KeyValuePair <MaterialSlot, List <IEdge> > entry in edgeDict)
                {
                    foreach (IEdge edge in entry.Value)
                    {
                        owner.Connect(edge.outputSlot, edge.inputSlot);
                    }
                }
                break;
            }
            }

            ValidateNode();
        }