Matt Dean
7 年前
当前提交
cfb57499
共有 9 个文件被更改,包括 273 次插入 和 0 次删除
-
13MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
15MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
-
61MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SliderShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SliderShaderProperty.cs.meta
-
86MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/SliderNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/SliderNode.cs.meta
-
71MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/SliderControl.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/SliderControl.cs.meta
|
|||
using System; |
|||
using System.Text; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class SliderShaderProperty : AbstractShaderProperty<Vector3> |
|||
{ |
|||
public SliderShaderProperty() |
|||
{ |
|||
displayName = "Slider"; |
|||
value = new Vector3(0, 0, 1); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Float; } |
|||
} |
|||
|
|||
public override Vector4 defaultValue |
|||
{ |
|||
get { return new Vector4(value.x, value.y, value.z, value.x); } |
|||
} |
|||
|
|||
public override string GetPropertyBlockString() |
|||
{ |
|||
var result = new StringBuilder(); |
|||
result.Append(referenceName); |
|||
result.Append("(\""); |
|||
result.Append(displayName); |
|||
result.Append("\", Range("); |
|||
result.Append(value.y); |
|||
result.Append(", "); |
|||
result.Append(value.z); |
|||
result.Append(")) = "); |
|||
result.Append(value.x); |
|||
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.x |
|||
}; |
|||
} |
|||
|
|||
public override INode ToConcreteNode() |
|||
{ |
|||
return new SliderNode { value = value }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 116edc957722a90438d51cf6610694d3 |
|||
timeCreated: 1505346922 |
|
|||
using System.Collections.Generic; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input", "Basic", "Slider")] |
|||
public class SliderNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode |
|||
{ |
|||
[SerializeField] |
|||
private Vector3 m_Value = new Vector3(0f, 0f, 1f); |
|||
|
|||
public const int OutputSlotId = 0; |
|||
private const string kOutputSlotName = "Out"; |
|||
|
|||
public SliderNode() |
|||
{ |
|||
name = "Slider"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId }); |
|||
} |
|||
|
|||
[SliderControl("")] |
|||
public Vector3 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 SliderShaderProperty() |
|||
{ |
|||
overrideReferenceName = GetVariableNameForNode(), |
|||
generatePropertyBlock = false, |
|||
value = value |
|||
}); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_Value.x + ";", 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.x |
|||
}); |
|||
} |
|||
|
|||
public IShaderProperty AsShaderProperty() |
|||
{ |
|||
return new SliderShaderProperty { value = value }; |
|||
} |
|||
|
|||
public int outputSlotId { get { return OutputSlotId; } } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 39d5ba890306e584c9fb4fede8c37f9c |
|||
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; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class SliderControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
|
|||
public SliderControlAttribute(string label = null) |
|||
{ |
|||
m_Label = label; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new SliderControlView(m_Label, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class SliderControlView : VisualElement, INodeModificationListener |
|||
{ |
|||
GUIContent m_Label; |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
IMGUIContainer m_Container; |
|||
|
|||
public SliderControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
if (propertyInfo.PropertyType != typeof(Vector3)) |
|||
throw new ArgumentException("Property must be of type Vector3.", "propertyInfo"); |
|||
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)); |
|||
m_Container = new IMGUIContainer(OnGUIHandler); |
|||
Add(m_Container); |
|||
} |
|||
|
|||
public void OnNodeModified(ModificationScope scope) |
|||
{ |
|||
if (scope == ModificationScope.Graph) |
|||
m_Container.Dirty(ChangeType.Repaint); |
|||
} |
|||
|
|||
void OnGUIHandler() |
|||
{ |
|||
var value = (Vector3)m_PropertyInfo.GetValue(m_Node, null); |
|||
|
|||
using (var changeCheckScope = new EditorGUI.ChangeCheckScope()) |
|||
{ |
|||
var slider = EditorGUILayout.Slider(value.x, value.y, value.z); |
|||
GUILayout.BeginHorizontal(); |
|||
EditorGUIUtility.labelWidth = 32f; |
|||
var minField = EditorGUILayout.FloatField("Min", value.y); |
|||
var maxField = EditorGUILayout.FloatField("Max", value.z); |
|||
GUILayout.EndHorizontal(); |
|||
|
|||
if (changeCheckScope.changed) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); |
|||
m_PropertyInfo.SetValue(m_Node, new Vector3(slider, minField, maxField), null); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c74a50771637c2d49980f713bbb7f4ea |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue