Matt Dean
7 年前
当前提交
2f6e839e
共有 11 个文件被更改,包括 337 次插入 和 0 次删除
-
13MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
-
91MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerMaterialSlot.cs.meta
-
56MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IntegerShaderProperty.cs.meta
-
86MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/IntegerNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/IntegerNode.cs.meta
-
53MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/IntegerControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/IntegerControl.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: |
|
|||
using System; |
|||
using System.Text; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class IntegerShaderProperty : AbstractShaderProperty<int> |
|||
{ |
|||
public IntegerShaderProperty() |
|||
{ |
|||
displayName = "Integer"; |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Float; } |
|||
} |
|||
|
|||
public override Vector4 defaultValue |
|||
{ |
|||
get { return new Vector4(value, value, value, value); } |
|||
} |
|||
|
|||
public override string GetPropertyBlockString() |
|||
{ |
|||
var result = new StringBuilder(); |
|||
result.Append(referenceName); |
|||
result.Append("(\""); |
|||
result.Append(displayName); |
|||
result.Append("\", Int) = "); |
|||
result.Append(value); |
|||
return result.ToString(); |
|||
} |
|||
|
|||
public override string GetPropertyDeclarationString(string delimiter = ";") |
|||
{ |
|||
return string.Format("float {0}{1}", referenceName, delimiter); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewMaterialProperty() |
|||
{ |
|||
return new PreviewProperty(PropertyType.Float) |
|||
{ |
|||
name = referenceName, |
|||
floatValue = value |
|||
}; |
|||
} |
|||
|
|||
public override INode ToConcreteNode() |
|||
{ |
|||
return new IntegerNode { value = value }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5980fe29fe1b01c4fa3fb434dd9eb9e2 |
|||
timeCreated: 1505346922 |
|
|||
using System.Collections.Generic; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input", "Basic", "Integer")] |
|||
public class IntegerNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode |
|||
{ |
|||
[SerializeField] |
|||
private int m_Value; |
|||
|
|||
public const int OutputSlotId = 0; |
|||
private const string kOutputSlotName = "Out"; |
|||
|
|||
public IntegerNode() |
|||
{ |
|||
name = "Integer"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new IntegerMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId }); |
|||
} |
|||
|
|||
[IntegerControl("")] |
|||
public int value |
|||
{ |
|||
get { return m_Value; } |
|||
set |
|||
{ |
|||
if (m_Value == value) |
|||
return; |
|||
|
|||
m_Value = value; |
|||
|
|||
Dirty(ModificationScope.Node); |
|||
} |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
if (!generationMode.IsPreview()) |
|||
return; |
|||
|
|||
properties.AddShaderProperty(new IntegerShaderProperty() |
|||
{ |
|||
overrideReferenceName = GetVariableNameForNode(), |
|||
generatePropertyBlock = false, |
|||
value = value |
|||
}); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_Value + ";", true); |
|||
} |
|||
|
|||
public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
return GetVariableNameForNode(); |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(new PreviewProperty(PropertyType.Float) |
|||
{ |
|||
name = GetVariableNameForNode(), |
|||
floatValue = m_Value |
|||
}); |
|||
} |
|||
|
|||
public IShaderProperty AsShaderProperty() |
|||
{ |
|||
return new IntegerShaderProperty { value = value }; |
|||
} |
|||
|
|||
public int outputSlotId { get { return OutputSlotId; } } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e449bdf3b245898489ebab4f709ded62 |
|||
timeCreated: 1445864587 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class IntegerControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
|
|||
public IntegerControlAttribute(string label = null) |
|||
{ |
|||
m_Label = label; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new IntegerControlView(m_Label, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class IntegerControlView : VisualElement |
|||
{ |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
|
|||
public IntegerControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
if (propertyInfo.PropertyType != typeof(int)) |
|||
throw new ArgumentException("Property must be of type integer.", "propertyInfo"); |
|||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name); |
|||
|
|||
if (!string.IsNullOrEmpty(label)) |
|||
Add(new Label(label)); |
|||
|
|||
var intField = new IntegerField { value = (int)m_PropertyInfo.GetValue(m_Node, null) }; |
|||
intField.OnValueChanged(OnChange); |
|||
Add(intField); |
|||
} |
|||
|
|||
void OnChange(ChangeEvent<long> evt) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Integer Change"); |
|||
m_PropertyInfo.SetValue(m_Node, (int)evt.newValue, null); |
|||
Dirty(ChangeType.Repaint); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 57d18a57866821542806ab5253cf4310 |
|||
timeCreated: 1507817885 |
撰写
预览
正在加载...
取消
保存
Reference in new issue