您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

78 行
2.4 KiB

using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Texture 2D Asset")]
public class Texture2DAssetNode : AbstractMaterialNode, IPropertyFromNode
{
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
public Texture2DAssetNode()
{
name = "Texture 2D Asset";
UpdateNodeAfterDeserialization();
}
public override string documentationURL
{
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Texture-2D-Asset-Node"; }
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Texture2DMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[SerializeField]
private SerializableTexture m_Texture = new SerializableTexture();
[TextureControl("")]
public Texture texture
{
get { return m_Texture.texture; }
set
{
if (m_Texture.texture == value)
return;
m_Texture.texture = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new TextureShaderProperty()
{
overrideReferenceName = GetVariableNameForSlot(OutputSlotId),
generatePropertyBlock = true,
value = m_Texture,
modifiable = false
});
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Texture2D)
{
name = GetVariableNameForSlot(OutputSlotId),
textureValue = texture
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new TextureShaderProperty { value = m_Texture };
if (texture != null)
prop.displayName = texture.name;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}