void CreateNode(object obj, Vector2 nodePosition)
        {
            var texture2D = obj as Texture2D;

            if (texture2D != null)
            {
                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();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

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

                var inputslot = node.FindInputSlot <Texture2DInputMaterialSlot>(SampleTexture2DNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.texture = texture2D;
                }
            }

            var textureArray = obj as Texture2DArray;

            if (textureArray != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Texture Array");

                var node      = new SampleTexture2DArrayNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

                var inputslot = node.FindSlot <Texture2DArrayInputMaterialSlot>(SampleTexture2DArrayNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.textureArray = textureArray;
                }
            }

            var texture3D = obj as Texture3D;

            if (texture3D != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Texture 3D");

                var node      = new SampleTexture3DNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

                var inputslot = node.FindSlot <Texture3DInputMaterialSlot>(SampleTexture3DNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.texture = texture3D;
                }
            }

            var cubemap = obj as Cubemap;

            if (cubemap != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Cubemap");

                var node      = new SampleCubemapNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

                var inputslot = node.FindInputSlot <CubemapInputMaterialSlot>(SampleCubemapNode.CubemapInputId);
                if (inputslot != null)
                {
                    inputslot.cubemap = cubemap;
                }
            }

            var subGraphAsset = obj as SubGraphAsset;

            if (subGraphAsset != null)
            {
                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.asset         = subGraphAsset;
                graph.AddNode(node);
            }

            var blackboardField = obj as BlackboardField;

            if (blackboardField != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Graph Input");

                switch (blackboardField.userData)
                {
                case AbstractShaderProperty property:
                {
                    var node      = new PropertyNode();
                    var drawState = node.drawState;
                    drawState.position = new Rect(nodePosition, drawState.position.size);
                    node.drawState     = drawState;
                    graph.AddNode(node);

                    // Setting the guid requires the graph to be set first.
                    node.propertyGuid = property.guid;
                    break;
                }

                case ShaderKeyword keyword:
                {
                    var node      = new KeywordNode();
                    var drawState = node.drawState;
                    drawState.position = new Rect(nodePosition, drawState.position.size);
                    node.drawState     = drawState;
                    graph.AddNode(node);

                    // Setting the guid requires the graph to be set first.
                    node.keywordGuid = keyword.guid;
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Ejemplo n.º 2
0
        void CreateNode(object obj, Vector2 nodePosition)
        {
            var texture2D = obj as Texture2D;

            if (texture2D != null)
            {
                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();

                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

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

                var inputslot = node.FindInputSlot <Texture2DInputMaterialSlot>(SampleTexture2DNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.texture = texture2D;
                }
            }

            var textureArray = obj as Texture2DArray;

            if (textureArray != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Texture Array");
                var property = new Texture2DArrayShaderProperty {
                    displayName = textureArray.name, value = { textureArray = textureArray }
                };
                graph.AddShaderProperty(property);
                var node      = new SampleTexture2DArrayNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);
                var inputslot = node.FindSlot <Texture2DArrayInputMaterialSlot>(SampleTexture2DArrayNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.textureArray = textureArray;
                }
            }

            var texture3D = obj as Texture3D;

            if (texture3D != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Texture 3D");
                var property = new Texture3DShaderProperty {
                    displayName = texture3D.name, value = { texture = texture3D }
                };
                graph.AddShaderProperty(property);
                var node      = new SampleTexture3DNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);
                var inputslot = node.FindSlot <Texture3DInputMaterialSlot>(SampleTexture3DNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.texture = texture3D;
                }
            }

            var cubemap = obj as Cubemap;

            if (cubemap != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Cubemap");
                var property = new CubemapShaderProperty {
                    displayName = cubemap.name, value = { cubemap = cubemap }
                };
                graph.AddShaderProperty(property);
                var node = new SampleCubemapNode();

                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

                var inputslot = node.FindInputSlot <CubemapInputMaterialSlot>(SampleCubemapNode.CubemapInputId);
                if (inputslot != null)
                {
                    inputslot.cubemap = cubemap;
                }
            }

            var subGraphAsset = obj as SubGraphAsset;

            if (subGraphAsset != null)
            {
                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;
                graph.AddNode(node);
            }

            var blackboardField = obj as BlackboardField;

            if (blackboardField != null)
            {
                AbstractShaderProperty property = blackboardField.userData as AbstractShaderProperty;
                if (property != null)
                {
                    graph.owner.RegisterCompleteObjectUndo("Drag Property");
                    var node = new PropertyNode();

                    var drawState = node.drawState;
                    drawState.position = new Rect(nodePosition, drawState.position.size);
                    node.drawState     = drawState;
                    graph.AddNode(node);

                    // Setting the guid requires the graph to be set first.
                    node.propertyGuid = property.guid;
                }
            }
        }
Ejemplo n.º 3
0
        void CreateNode(object obj, Vector2 nodePosition)
        {
            var texture2D = obj as Texture2D;

            if (texture2D != null)
            {
                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();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

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

                var inputslot = node.FindInputSlot <Texture2DInputMaterialSlot>(SampleTexture2DNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.texture = texture2D;
                }
            }

            var textureArray = obj as Texture2DArray;

            if (textureArray != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Texture Array");

                var node      = new SampleTexture2DArrayNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

                var inputslot = node.FindSlot <Texture2DArrayInputMaterialSlot>(SampleTexture2DArrayNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.textureArray = textureArray;
                }
            }

            var texture3D = obj as Texture3D;

            if (texture3D != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Texture 3D");

                var node      = new SampleTexture3DNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

                var inputslot = node.FindSlot <Texture3DInputMaterialSlot>(SampleTexture3DNode.TextureInputId);
                if (inputslot != null)
                {
                    inputslot.texture = texture3D;
                }
            }

            var cubemap = obj as Cubemap;

            if (cubemap != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Cubemap");

                var node      = new SampleCubemapNode();
                var drawState = node.drawState;
                drawState.position = new Rect(nodePosition, drawState.position.size);
                node.drawState     = drawState;
                graph.AddNode(node);

                var inputslot = node.FindInputSlot <CubemapInputMaterialSlot>(SampleCubemapNode.CubemapInputId);
                if (inputslot != null)
                {
                    inputslot.cubemap = cubemap;
                }
            }

            var subGraphAsset = obj as SubGraphAsset;

            if (subGraphAsset != null)
            {
                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.asset         = subGraphAsset;
                graph.AddNode(node);
            }

            var blackboardField = obj as BlackboardField;

            if (blackboardField != null)
            {
                graph.owner.RegisterCompleteObjectUndo("Drag Graph Input");

                switch (blackboardField.userData)
                {
                case AbstractShaderProperty property:
                {
                    // This could be from another graph, in which case we add a copy of the ShaderInput to this graph.
                    if (graph.properties.FirstOrDefault(p => p.guid == property.guid) == null)
                    {
                        var copy = (AbstractShaderProperty)property.Copy();
                        graph.SanitizeGraphInputName(copy);
                        graph.SanitizeGraphInputReferenceName(copy, property.overrideReferenceName);     // We do want to copy the overrideReferenceName

                        property = copy;
                        graph.AddGraphInput(property);
                    }

                    var node      = new PropertyNode();
                    var drawState = node.drawState;
                    drawState.position = new Rect(nodePosition, drawState.position.size);
                    node.drawState     = drawState;
                    graph.AddNode(node);

                    // Setting the guid requires the graph to be set first.
                    node.propertyGuid = property.guid;
                    break;
                }

                case ShaderKeyword keyword:
                {
                    // This could be from another graph, in which case we add a copy of the ShaderInput to this graph.
                    if (graph.keywords.FirstOrDefault(k => k.guid == keyword.guid) == null)
                    {
                        var copy = (ShaderKeyword)keyword.Copy();
                        graph.SanitizeGraphInputName(copy);
                        graph.SanitizeGraphInputReferenceName(copy, keyword.overrideReferenceName);     // We do want to copy the overrideReferenceName

                        keyword = copy;
                        graph.AddGraphInput(keyword);
                    }

                    var node      = new KeywordNode();
                    var drawState = node.drawState;
                    drawState.position = new Rect(nodePosition, drawState.position.size);
                    node.drawState     = drawState;
                    graph.AddNode(node);

                    // Setting the guid requires the graph to be set first.
                    node.keywordGuid = keyword.guid;
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }