Tim Cooper
9 年前
当前提交
94238998
共有 8 个文件被更改,包括 211 次插入 和 7 次删除
-
4UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
-
4UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
-
4UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/UVNode.cs
-
23UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs
-
110UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs
-
12UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs.meta
-
49UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/FloatProperty.cs
-
12UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/FloatProperty.cs.meta
|
|||
using System; |
|||
using UnityEditor.Graphs; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Generate/Vector 1 Node")] |
|||
class Vector1Node : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
[SerializeField] |
|||
private float m_Value; |
|||
|
|||
private const string kOutputSlotName = "Value"; |
|||
|
|||
public override void Init() |
|||
{ |
|||
base.Init(); |
|||
name = "V1Node"; |
|||
AddSlot(new Slot(SlotType.OutputSlot, kOutputSlotName)); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Float; } |
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (HasBoundProperty() || !generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderProperty(new FloatPropertyChunk(GetPropertyName(), GetPropertyName(), m_Value, true)); |
|||
} |
|||
|
|||
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode) |
|||
{ |
|||
return GetPropertyName(); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (HasBoundProperty() || !generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk("float " + GetPropertyName() + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (HasBoundProperty() || generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + " " + GetPropertyName() + " = " + m_Value + ";", true); |
|||
} |
|||
|
|||
public override float GetNodeUIHeight(float width) |
|||
{ |
|||
return 2*EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public override bool NodeUI(Rect drawArea) |
|||
{ |
|||
base.NodeUI(drawArea); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Value = EditorGUI.FloatField(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), "Value", m_Value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
var boundProp = boundProperty as FloatProperty; |
|||
if (boundProp != null) |
|||
{ |
|||
boundProp.defaultValue = m_Value; |
|||
} |
|||
UpdatePreviewProperties(); |
|||
ForwardPreviewMaterialPropertyUpdate(); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public override void BindProperty(ShaderProperty property, bool rebuildShaders) |
|||
{ |
|||
base.BindProperty(property, rebuildShaders); |
|||
|
|||
var vectorProp = property as FloatProperty; |
|||
if (vectorProp) |
|||
{ |
|||
m_Value = vectorProp.defaultValue; |
|||
} |
|||
|
|||
if (rebuildShaders) |
|||
RegeneratePreviewShaders(); |
|||
else |
|||
{ |
|||
UpdatePreviewProperties(); |
|||
ForwardPreviewMaterialPropertyUpdate(); |
|||
} |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = GetPropertyName(), |
|||
m_PropType = PropertyType.Float, |
|||
m_Float = m_Value |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 87c4299b09d95d64c99884296038ceeb |
|||
timeCreated: 1445864587 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class FloatProperty : ShaderProperty |
|||
{ |
|||
[SerializeField] private float m_DefaultValue; |
|||
|
|||
public override object value |
|||
{ |
|||
get { return m_DefaultValue; } |
|||
set { m_DefaultValue = (float)value; } |
|||
} |
|||
|
|||
public float defaultValue |
|||
{ |
|||
get { return m_DefaultValue; } |
|||
set { m_DefaultValue = value; } |
|||
} |
|||
|
|||
public override void PropertyOnGUI(out bool nameChanged, out bool valuesChanged) |
|||
{ |
|||
base.PropertyOnGUI(out nameChanged, out valuesChanged); |
|||
EditorGUI.BeginChangeCheck(); |
|||
m_DefaultValue = EditorGUILayout.FloatField("Vector", m_DefaultValue); |
|||
valuesChanged |= EditorGUI.EndChangeCheck(); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Float; } |
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderProperty(new FloatPropertyChunk(name, m_PropertyDescription, m_DefaultValue, false)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk("float4 " + name + ";", true); |
|||
} |
|||
|
|||
public override string GenerateDefaultValue() |
|||
{ |
|||
return "half4 (" + m_DefaultValue + "," + m_DefaultValue + "," + m_DefaultValue + "," + m_DefaultValue + ")"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 20e6a2fccb2d4c84680ac4ded12a8957 |
|||
timeCreated: 1445864587 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue