浏览代码

Remove IntegerMaterialSlot

/main
Matt Dean 7 年前
当前提交
333ded2e
共有 4 个文件被更改,包括 2 次插入104 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/IntegerNode.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs
  3. 91
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerMaterialSlot.cs
  4. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerMaterialSlot.cs.meta

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/IntegerNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new IntegerMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs


}
else if (property is IntegerShaderProperty)
{
AddSlot(new IntegerMaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
else if (property is SliderShaderProperty)

91
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerMaterialSlot.cs


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;
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerMaterialSlot.cs.meta


fileFormatVersion: 2
guid: 51c110f32bfa9764295488324d94d836
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存