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

76 行
2.5 KiB

using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Vector 4 Node")]
public class Vector4Node : PropertyNode, IGeneratesBodyCode
{
[SerializeField]
private Vector4 m_Value;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Value";
public Vector4Node()
{
name = "V4Node";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override PropertyType propertyType
{
get { return PropertyType.Vector4; }
}
public Vector4 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
}
}
}