您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
91 行
2.8 KiB
91 行
2.8 KiB
using System;
|
|
using UnityEditor.Graphing;
|
|
using UnityEditor.ShaderGraph.Drawing.Slots;
|
|
using UnityEngine;
|
|
using UnityEngine.Experimental.UIElements;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
[Serializable]
|
|
public class Vector1MaterialSlot : MaterialSlot, IMaterialSlotHasValue<float>
|
|
{
|
|
[SerializeField]
|
|
private float m_Value;
|
|
|
|
[SerializeField]
|
|
private float m_DefaultValue;
|
|
|
|
public Vector1MaterialSlot()
|
|
{}
|
|
|
|
public Vector1MaterialSlot(
|
|
int slotId,
|
|
string displayName,
|
|
string shaderOutputName,
|
|
SlotType slotType,
|
|
float value,
|
|
ShaderStage shaderStage = ShaderStage.Dynamic,
|
|
bool hidden = false)
|
|
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
|
|
{
|
|
m_DefaultValue = value;
|
|
m_Value = value;
|
|
}
|
|
|
|
public float defaultValue { get { return m_DefaultValue; } }
|
|
|
|
public float value
|
|
{
|
|
get { return m_Value; }
|
|
set { m_Value = value; }
|
|
}
|
|
|
|
public override VisualElement InstantiateControl()
|
|
{
|
|
return new MultiFloatSlotControlView(owner, 1, () => new Vector4(value, 0f, 0f, 0f), (newValue) => value = newValue.x);
|
|
}
|
|
|
|
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
|
|
{
|
|
return value.ToString();
|
|
}
|
|
|
|
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
|
{
|
|
if (!generationMode.IsPreview())
|
|
return;
|
|
|
|
var matOwner = owner as AbstractMaterialNode;
|
|
if (matOwner == null)
|
|
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
|
|
|
|
var property = new FloatShaderProperty()
|
|
{
|
|
overrideReferenceName = matOwner.GetVariableNameForSlot(id),
|
|
generatePropertyBlock = false,
|
|
value = value
|
|
};
|
|
properties.AddShaderProperty(property);
|
|
}
|
|
|
|
public override SlotValueType valueType { get { return SlotValueType.Vector1; } }
|
|
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Vector1; } }
|
|
|
|
public override PreviewProperty GetPreviewProperty(string name)
|
|
{
|
|
var pp = new PreviewProperty(PropertyType.Float)
|
|
{
|
|
name = name,
|
|
floatValue = value
|
|
};
|
|
return pp;
|
|
}
|
|
|
|
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
|
{
|
|
var slot = foundSlot as Vector1MaterialSlot;
|
|
if (slot != null)
|
|
value = slot.value;
|
|
}
|
|
}
|
|
}
|