Matt Dean
7 年前
当前提交
333ded2e
共有 4 个文件被更改,包括 2 次插入 和 104 次删除
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/IntegerNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs
-
91MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerMaterialSlot.cs.meta
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Slots; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class IntegerMaterialSlot : MaterialSlot, IMaterialSlotHasValue<int> |
|||
{ |
|||
[SerializeField] |
|||
private int m_Value; |
|||
|
|||
[SerializeField] |
|||
private int m_DefaultValue; |
|||
|
|||
public IntegerMaterialSlot() |
|||
{} |
|||
|
|||
public IntegerMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
int value, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
m_DefaultValue = value; |
|||
m_Value = value; |
|||
} |
|||
|
|||
public int defaultValue { get { return m_DefaultValue; } } |
|||
|
|||
public int 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 = (int)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 IntegerShaderProperty() |
|||
{ |
|||
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 IntegerMaterialSlot; |
|||
if (slot != null) |
|||
value = slot.value; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 51c110f32bfa9764295488324d94d836 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue