Exemplo n.º 1
0
        void AddProperty(IShaderProperty property, bool create = false, int index = -1)
        {
            if (m_PropertyRows.ContainsKey(property.guid))
            {
                return;
            }
            var field = new BlackboardField(m_ExposedIcon, property.displayName, property.propertyType.ToString())
            {
                userData = property
            };
            var row = new BlackboardRow(field, new BlackboardFieldPropertyView(m_Graph, property));

            row.userData = property;
            if (index < 0)
            {
                index = m_PropertyRows.Count;
            }
            if (index == m_PropertyRows.Count)
            {
                m_Section.Add(row);
            }
            else
            {
                m_Section.Insert(index, row);
            }
            m_PropertyRows[property.guid] = row;

            if (create)
            {
                field.RenameGo();
                row.expanded = true;
                m_Graph.owner.RegisterCompleteObjectUndo("Create Property");
                m_Graph.AddShaderProperty(property);
            }
        }
        void AddProperty(IShaderProperty property, bool create = false, int index = -1)
        {
            if (m_PropertyRows.ContainsKey(property.guid))
            {
                return;
            }

            if (create)
            {
                property.displayName = m_Graph.SanitizePropertyName(property.displayName);
            }

            var icon  = property.generatePropertyBlock ? exposedIcon : null;
            var field = new BlackboardField(icon, property.displayName, property.propertyType.ToString())
            {
                userData = property
            };

            var propertyView = new BlackboardFieldPropertyView(field, m_Graph, property);
            var row          = new BlackboardRow(field, propertyView);
            var pill         = row.Q <Pill>();

            pill.RegisterCallback <MouseEnterEvent>(evt => OnMouseHover(evt, property));
            pill.RegisterCallback <MouseLeaveEvent>(evt => OnMouseHover(evt, property));
            pill.RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent);

            row.userData = property;
            if (index < 0)
            {
                index = m_PropertyRows.Count;
            }
            if (index == m_PropertyRows.Count)
            {
                m_Section.Add(row);
            }
            else
            {
                m_Section.Insert(index, row);
            }
            m_PropertyRows[property.guid] = row;

            if (create)
            {
                row.expanded = true;
                m_Graph.owner.RegisterCompleteObjectUndo("Create Property");
                m_Graph.AddShaderProperty(property);
                field.OpenTextEditor();
            }
        }
 void AddProperty(IShaderProperty property)
 {
     m_Graph.owner.RegisterCompleteObjectUndo("Add Property");
     m_Graph.AddShaderProperty(property);
 }
Exemplo n.º 4
0
        void CreateNode(object obj, Vector2 nodePosition)
        {
            var texture2D = obj as Texture2D;

            if (texture2D != null)
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Drag Texture");

                bool isNormalMap = false;
                if (EditorUtility.IsPersistent(texture2D) &&
                    !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(texture2D)))
                {
                    var importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture2D)) as TextureImporter;
                    if (importer != null)
                    {
                        isNormalMap = importer.textureType == TextureImporterType.NormalMap;
                    }
                }

                var node = new SampleTexture2DNode();
                if (isNormalMap)
                {
                    node.textureType = TextureType.Normal;
                }

                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                m_Graph.AddNode(node);
                var inputslot = node.FindSlot <Texture2DInputMaterialSlot>(SampleTexture2DNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.texture = texture2D;
                }
            }

            var cubemap = obj as Cubemap;

            if (cubemap != null)
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Drag Cubemap");
                var property = new CubemapShaderProperty {
                    displayName = cubemap.name, value = { cubemap = cubemap }
                };
                m_Graph.AddShaderProperty(property);
                var node      = new SampleCubemapNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                m_Graph.AddNode(node);
                var inputslot = node.FindSlot <CubemapInputMaterialSlot>(SampleCubemapNode.CubemapInputId);
                if (inputslot != null)
                {
                    inputslot.cubemap = cubemap;
                }
            }

            var subGraphAsset = obj as MaterialSubGraphAsset;

            if (subGraphAsset != null)
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Drag Sub-Graph");
                var node      = new SubGraphNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                node.subGraphAsset = subGraphAsset;
                m_Graph.AddNode(node);
            }

            var blackboardField = obj as BlackboardField;

            if (blackboardField != null)
            {
                var property = blackboardField.userData as IShaderProperty;
                if (property != null)
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Drag Shader Property");
                    var node      = new PropertyNode();
                    var drawState = node.drawState;
                    drawState.position = new Rect(nodePosition, drawState.position.size);
                    node.drawState     = drawState;
                    m_Graph.AddNode(node);
                    node.propertyGuid = property.guid;
                }
            }
        }