Matt Dean
7 年前
当前提交
bbb186d6
共有 18 个文件被更改,包括 1 次插入 和 290 次删除
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyType.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientMaterialSlot.cs.meta
-
58MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientShaderProperty.cs.meta
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs.meta
-
91MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs
-
34MaterialGraphProject/Assets/UnityShaderEditor/ShaderGraph.cginc
-
9MaterialGraphProject/Assets/UnityShaderEditor/ShaderGraph.cginc.meta
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class GradientMaterialSlot : MaterialSlot |
|||
{ |
|||
public GradientMaterialSlot() |
|||
{ |
|||
} |
|||
|
|||
public GradientMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{ |
|||
} |
|||
|
|||
public static readonly string DefaultGradientName = "ShaderGraph_DefaultGradient()"; |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Gradient; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Gradient; } } |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
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))); |
|||
|
|||
return DefaultGradientName; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0aac1b4e9fc8a1e4999e9069cf862832 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Text; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class GradientShaderProperty : AbstractShaderProperty<Gradient> |
|||
{ |
|||
[SerializeField] |
|||
private bool m_Modifiable = true; |
|||
|
|||
public GradientShaderProperty() |
|||
{ |
|||
value = new Gradient(); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Gradient; } |
|||
} |
|||
|
|||
public bool modifiable |
|||
{ |
|||
get { return m_Modifiable; } |
|||
set { m_Modifiable = value; } |
|||
} |
|||
|
|||
public override Vector4 defaultValue |
|||
{ |
|||
get { return new Vector4(); } |
|||
} |
|||
|
|||
public override string GetPropertyBlockString() |
|||
{ |
|||
return ""; |
|||
} |
|||
|
|||
public override string GetPropertyDeclarationString() |
|||
{ |
|||
return ""; |
|||
} |
|||
|
|||
public override string GetInlinePropertyDeclarationString() |
|||
{ |
|||
return "Gradient ShaderGraph_DefaultGradient;"; |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewMaterialProperty() |
|||
{ |
|||
return new PreviewProperty() |
|||
{ |
|||
m_Name = referenceName, |
|||
m_PropType = PropertyType.Gradient |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 186ecc17664ca614d9663a3fa18dede9 |
|||
timeCreated: 1505346949 |
|
|||
fileFormatVersion: 2 |
|||
guid: 4655415e388e6914ebefaaf9e2148ff1 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 41930fdac13e47db8faedb82e6411a4f |
|||
timeCreated: 1507882043 |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class GradientControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
|
|||
public GradientControlAttribute(string label = null) |
|||
{ |
|||
m_Label = label; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new GradientControlView(m_Label, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class GradientObject : ScriptableObject |
|||
{ |
|||
public Gradient gradient = new Gradient(); |
|||
} |
|||
|
|||
public class GradientControlView : VisualElement |
|||
{ |
|||
GUIContent m_Label; |
|||
|
|||
AbstractMaterialNode m_Node; |
|||
|
|||
PropertyInfo m_PropertyInfo; |
|||
|
|||
string m_PrevWindow = ""; |
|||
|
|||
[SerializeField] |
|||
GradientObject m_GradientObject; |
|||
|
|||
[SerializeField] |
|||
SerializedObject m_SerializedObject; |
|||
|
|||
[SerializeField] |
|||
SerializedProperty m_SerializedProperty; |
|||
|
|||
public GradientControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)); |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
if (propertyInfo.PropertyType != typeof(Gradient)) |
|||
throw new ArgumentException("Property must be of type Gradient.", "propertyInfo"); |
|||
m_GradientObject = ScriptableObject.CreateInstance<GradientObject>(); |
|||
m_GradientObject.gradient = new Gradient(); |
|||
m_SerializedObject = new SerializedObject(m_GradientObject); |
|||
m_SerializedProperty = m_SerializedObject.FindProperty("gradient"); |
|||
Add(new IMGUIContainer(OnGUIHandler)); |
|||
} |
|||
|
|||
void OnGUIHandler() |
|||
{ |
|||
m_SerializedObject.Update(); |
|||
var gradient = (Gradient)m_PropertyInfo.GetValue(m_Node, null); |
|||
m_GradientObject.gradient.SetKeys(gradient.colorKeys, gradient.alphaKeys); |
|||
|
|||
|
|||
using (var changeCheckScope = new EditorGUI.ChangeCheckScope()) |
|||
{ |
|||
EditorGUILayout.PropertyField(m_SerializedProperty, m_Label, true, null); |
|||
m_SerializedObject.ApplyModifiedProperties(); |
|||
if (changeCheckScope.changed) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); |
|||
m_PropertyInfo.SetValue(m_Node, m_GradientObject.gradient, null); |
|||
} |
|||
} |
|||
|
|||
var e = Event.current; |
|||
|
|||
if (EditorWindow.focusedWindow != null && m_PrevWindow != EditorWindow.focusedWindow.ToString() && EditorWindow.focusedWindow.ToString() != "(UnityEditor.GradientPicker)") |
|||
{ |
|||
m_PropertyInfo.SetValue(m_Node, m_GradientObject.gradient, null); |
|||
m_PrevWindow = EditorWindow.focusedWindow.ToString(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
// Gradient Type |
|||
struct Gradient |
|||
{ |
|||
int type; |
|||
int colorsLength; |
|||
int alphasLength; |
|||
float4 colors[8]; |
|||
float2 alphas[8]; |
|||
}; |
|||
|
|||
Gradient ShaderGraph_DefaultGradient() |
|||
{ |
|||
Gradient g; |
|||
g.type = 0; |
|||
g.colorsLength = 2; |
|||
g.alphasLength = 2; |
|||
g.colors[0] = float4(0, 0, 0, 0); |
|||
g.colors[1] = float4(1, 1, 1, 1); |
|||
g.colors[2] = float4(0, 0, 0, 0); |
|||
g.colors[3] = float4(0, 0, 0, 0); |
|||
g.colors[4] = float4(0, 0, 0, 0); |
|||
g.colors[5] = float4(0, 0, 0, 0); |
|||
g.colors[6] = float4(0, 0, 0, 0); |
|||
g.colors[7] = float4(0, 0, 0, 0); |
|||
g.alphas[0] = float2(1, 0); |
|||
g.alphas[1] = float2(1, 1); |
|||
g.alphas[2] = float2(0, 0); |
|||
g.alphas[3] = float2(0, 0); |
|||
g.alphas[4] = float2(0, 0); |
|||
g.alphas[5] = float2(0, 0); |
|||
g.alphas[6] = float2(0, 0); |
|||
g.alphas[7] = float2(0, 0); |
|||
return g; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2a7388374397c47f1a598ae9ea3f2069 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue