initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class ButtonControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
public ButtonControlAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new ButtonControlView(node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
struct ButtonConfig
|
||||
{
|
||||
public string text;
|
||||
public Action action;
|
||||
}
|
||||
|
||||
class ButtonControlView : VisualElement
|
||||
{
|
||||
public ButtonControlView(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
|
||||
m_Node = node;
|
||||
|
||||
Type type = propertyInfo.PropertyType;
|
||||
if (type != typeof(ButtonConfig))
|
||||
{
|
||||
throw new ArgumentException("Property must be a ButtonConfig.", "propertyInfo");
|
||||
}
|
||||
var value = (ButtonConfig)propertyInfo.GetValue(m_Node, null);
|
||||
|
||||
Add(new Button(value.action) { text = value.text });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a7a22fecc3eba0844810adaf43e45f0f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,105 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class ChannelEnumControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
int m_SlotId;
|
||||
|
||||
public ChannelEnumControlAttribute(string label = null, int slotId = 0)
|
||||
{
|
||||
m_Label = label;
|
||||
m_SlotId = slotId;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new ChannelEnumControlView(m_Label, m_SlotId, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class ChannelEnumControlView : VisualElement, AbstractMaterialNodeModificationListener
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
int m_SlotId;
|
||||
|
||||
PopupField<string> m_PopupField;
|
||||
string[] m_ValueNames;
|
||||
|
||||
int m_PreviousChannelCount = -1;
|
||||
|
||||
public ChannelEnumControlView(string label, int slotId, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/ChannelEnumControlView"));
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
m_SlotId = slotId;
|
||||
if (!propertyInfo.PropertyType.IsEnum)
|
||||
throw new ArgumentException("Property must be an enum.", "propertyInfo");
|
||||
Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
|
||||
|
||||
var value = (Enum)m_PropertyInfo.GetValue(m_Node, null);
|
||||
m_ValueNames = Enum.GetNames(value.GetType());
|
||||
|
||||
CreatePopup();
|
||||
}
|
||||
|
||||
void OnValueChanged(ChangeEvent<string> evt)
|
||||
{
|
||||
var index = m_PopupField.index;
|
||||
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
|
||||
if (!index.Equals(value))
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
|
||||
m_PropertyInfo.SetValue(m_Node, index, null);
|
||||
}
|
||||
|
||||
CreatePopup();
|
||||
}
|
||||
|
||||
public void OnNodeModified(ModificationScope scope)
|
||||
{
|
||||
if (scope == ModificationScope.Node)
|
||||
{
|
||||
CreatePopup();
|
||||
m_PopupField.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
|
||||
void CreatePopup()
|
||||
{
|
||||
int channelCount = SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(m_SlotId).concreteValueType);
|
||||
|
||||
if (m_PopupField != null)
|
||||
{
|
||||
if (channelCount == m_PreviousChannelCount)
|
||||
return;
|
||||
|
||||
Remove(m_PopupField);
|
||||
}
|
||||
|
||||
m_PreviousChannelCount = channelCount;
|
||||
List<string> popupEntries = new List<string>();
|
||||
for (int i = 0; i < channelCount; i++)
|
||||
popupEntries.Add(m_ValueNames[i]);
|
||||
|
||||
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
|
||||
if (value >= channelCount)
|
||||
value = 0;
|
||||
|
||||
m_PopupField = new PopupField<string>(popupEntries, value);
|
||||
m_PopupField.RegisterValueChangedCallback(OnValueChanged);
|
||||
Add(m_PopupField);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 74fdde12d8253bd4c874acc555be0585
|
||||
timeCreated: 1507817885
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class ChannelEnumMaskControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
int m_SlotId;
|
||||
|
||||
public ChannelEnumMaskControlAttribute(string label = null, int slotId = 0)
|
||||
{
|
||||
m_Label = label;
|
||||
m_SlotId = slotId;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new ChannelEnumMaskControlView(m_Label, m_SlotId, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class ChannelEnumMaskControlView : VisualElement, AbstractMaterialNodeModificationListener
|
||||
{
|
||||
string m_Label;
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
IMGUIContainer m_Container;
|
||||
int m_SlotId;
|
||||
|
||||
public ChannelEnumMaskControlView(string label, int slotId, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/ChannelEnumMaskControlView"));
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
m_SlotId = slotId;
|
||||
//if (!propertyInfo.PropertyType.IsEnum)
|
||||
//throw new ArgumentException("Property must be an enum.", "propertyInfo");
|
||||
m_Label = label;
|
||||
m_Container = new IMGUIContainer(OnGUIHandler);
|
||||
Add(m_Container);
|
||||
}
|
||||
|
||||
void OnGUIHandler()
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(m_Label);
|
||||
UpdatePopup();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public void OnNodeModified(ModificationScope scope)
|
||||
{
|
||||
if (scope == ModificationScope.Graph)
|
||||
m_Container.MarkDirtyRepaint();
|
||||
}
|
||||
|
||||
private void UpdatePopup()
|
||||
{
|
||||
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
|
||||
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
|
||||
{
|
||||
int channelCount = SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(m_SlotId).concreteValueType);
|
||||
string[] enumEntryNames = Enum.GetNames(typeof(TextureChannel));
|
||||
string[] popupEntries = new string[channelCount];
|
||||
for (int i = 0; i < popupEntries.Length; i++)
|
||||
popupEntries[i] = enumEntryNames[i];
|
||||
value = EditorGUILayout.MaskField("", value, popupEntries, GUILayout.Width(80f));
|
||||
|
||||
if (changeCheckScope.changed)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
|
||||
m_PropertyInfo.SetValue(m_Node, value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c32d860c6f767f14fa889dffac527bc5
|
||||
timeCreated: 1507817885
|
|
@ -0,0 +1,214 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class ChannelMixerControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
float m_Minimum;
|
||||
float m_Maximum;
|
||||
|
||||
public ChannelMixerControlAttribute(string label = null, float minimum = -2f, float maximum = 2f)
|
||||
{
|
||||
m_Label = label;
|
||||
m_Minimum = minimum;
|
||||
m_Maximum = maximum;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new ChannelMixerControlView(m_Label, m_Minimum, m_Maximum, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class ChannelMixerControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
ChannelMixerNode.ChannelMixer m_ChannelMixer;
|
||||
int m_OutChannel;
|
||||
|
||||
Slider m_RedSlider;
|
||||
Slider m_GreenSlider;
|
||||
Slider m_BlueSlider;
|
||||
|
||||
FloatField m_RedInputField;
|
||||
FloatField m_GreenInputField;
|
||||
FloatField m_BlueInputField;
|
||||
|
||||
float m_Minimum;
|
||||
float m_Maximum;
|
||||
bool m_Initialized;
|
||||
|
||||
public ChannelMixerControlView(string label, float minimum, float maximum, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/ChannelMixerControlView"));
|
||||
m_ChannelMixer = (ChannelMixerNode.ChannelMixer)m_PropertyInfo.GetValue(m_Node, null);
|
||||
m_OutChannel = 0;
|
||||
|
||||
m_Minimum = minimum;
|
||||
m_Maximum = maximum;
|
||||
|
||||
if (propertyInfo.PropertyType != typeof(ChannelMixerNode.ChannelMixer))
|
||||
throw new ArgumentException("Property must be of type ChannelMixer.", "propertyInfo");
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label(label));
|
||||
|
||||
var buttonPanel = new VisualElement { name = "buttonPanel" };
|
||||
|
||||
Action changedOutputRed = () => OnClickButton(0);
|
||||
var outputButtonRed = new Button(changedOutputRed);
|
||||
outputButtonRed.Add(new Label("R"));
|
||||
buttonPanel.Add(outputButtonRed);
|
||||
|
||||
Action changedOutputGreen = () => OnClickButton(1);
|
||||
var outputButtonGreen = new Button(changedOutputGreen);
|
||||
outputButtonGreen.Add(new Label("G"));
|
||||
buttonPanel.Add(outputButtonGreen);
|
||||
|
||||
Action changedOutputBlue = () => OnClickButton(2);
|
||||
var outputButtonBlue = new Button(changedOutputBlue);
|
||||
outputButtonBlue.Add(new Label("B"));
|
||||
buttonPanel.Add(outputButtonBlue);
|
||||
|
||||
Add(buttonPanel);
|
||||
|
||||
var redSliderPanel = new VisualElement { name = "sliderPanel" };
|
||||
redSliderPanel.Add(new Label("R"));
|
||||
Action<float> changedRedIn = (s) => { OnChangeSlider(s, 0); };
|
||||
m_RedSlider = new Slider(m_Minimum, m_Maximum);
|
||||
m_RedSlider.RegisterValueChangedCallback((evt) => OnChangeSlider(evt.newValue, 0));
|
||||
|
||||
redSliderPanel.Add(m_RedSlider);
|
||||
m_RedInputField = new FloatField { value = m_ChannelMixer.outRed.x };
|
||||
m_RedInputField.RegisterCallback<ChangeEvent<double>, int>(OnChangeInputField, 0);
|
||||
redSliderPanel.Add(m_RedInputField);
|
||||
Add(redSliderPanel);
|
||||
|
||||
var greenSliderPanel = new VisualElement { name = "sliderPanel" };
|
||||
greenSliderPanel.Add(new Label("G"));
|
||||
m_GreenSlider = new Slider(m_Minimum, m_Maximum);
|
||||
m_GreenSlider.RegisterValueChangedCallback((evt) => OnChangeSlider(evt.newValue, 1));
|
||||
greenSliderPanel.Add(m_GreenSlider);
|
||||
m_GreenInputField = new FloatField { value = m_ChannelMixer.outRed.y };
|
||||
m_GreenInputField.RegisterCallback<ChangeEvent<double>, int>(OnChangeInputField, 1);
|
||||
greenSliderPanel.Add(m_GreenInputField);
|
||||
Add(greenSliderPanel);
|
||||
|
||||
var blueSliderPanel = new VisualElement { name = "sliderPanel" };
|
||||
blueSliderPanel.Add(new Label("B"));
|
||||
m_BlueSlider = new Slider(m_Minimum, m_Maximum);
|
||||
m_BlueSlider.RegisterValueChangedCallback((evt) => OnChangeSlider(evt.newValue, 2));
|
||||
blueSliderPanel.Add(m_BlueSlider);
|
||||
m_BlueInputField = new FloatField { value = m_ChannelMixer.outRed.z };
|
||||
m_BlueInputField.RegisterCallback<ChangeEvent<double>, int>(OnChangeInputField, 2);
|
||||
blueSliderPanel.Add(m_BlueInputField);
|
||||
Add(blueSliderPanel);
|
||||
|
||||
m_Initialized = true;
|
||||
ResetSliders();
|
||||
}
|
||||
|
||||
void ResetSliders()
|
||||
{
|
||||
Vector3 outputChannel = GetOutputChannel();
|
||||
m_RedSlider.value = outputChannel[0];
|
||||
m_GreenSlider.value = outputChannel[1];
|
||||
m_BlueSlider.value = outputChannel[2];
|
||||
}
|
||||
|
||||
void OnChangeSlider(float value, int inChannel)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
return;
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Slider Change");
|
||||
switch (m_OutChannel)
|
||||
{
|
||||
case 1:
|
||||
m_ChannelMixer.outGreen[inChannel] = value;
|
||||
break;
|
||||
case 2:
|
||||
m_ChannelMixer.outBlue[inChannel] = value;
|
||||
break;
|
||||
default:
|
||||
m_ChannelMixer.outRed[inChannel] = value;
|
||||
break;
|
||||
}
|
||||
switch (inChannel)
|
||||
{
|
||||
case 1:
|
||||
m_GreenInputField.value = value;
|
||||
break;
|
||||
case 2:
|
||||
m_BlueInputField.value = value;
|
||||
break;
|
||||
default:
|
||||
m_RedInputField.value = value;
|
||||
break;
|
||||
}
|
||||
m_PropertyInfo.SetValue(m_Node, m_ChannelMixer, null);
|
||||
}
|
||||
|
||||
void OnChangeInputField(ChangeEvent<double> evt, int inChannel)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
return;
|
||||
var value = Mathf.Max(Mathf.Min((float)evt.newValue, m_Maximum), m_Minimum);
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Input Field Change");
|
||||
switch (m_OutChannel)
|
||||
{
|
||||
case 1:
|
||||
m_ChannelMixer.outGreen[inChannel] = value;
|
||||
break;
|
||||
case 2:
|
||||
m_ChannelMixer.outBlue[inChannel] = value;
|
||||
break;
|
||||
default:
|
||||
m_ChannelMixer.outRed[inChannel] = value;
|
||||
break;
|
||||
}
|
||||
switch (inChannel)
|
||||
{
|
||||
case 1:
|
||||
m_GreenSlider.value = value;
|
||||
break;
|
||||
case 2:
|
||||
m_BlueSlider.value = value;
|
||||
break;
|
||||
default:
|
||||
m_RedSlider.value = value;
|
||||
break;
|
||||
}
|
||||
m_PropertyInfo.SetValue(m_Node, m_ChannelMixer, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
|
||||
void OnClickButton(int outChannel)
|
||||
{
|
||||
m_OutChannel = outChannel;
|
||||
ResetSliders();
|
||||
}
|
||||
|
||||
Vector3 GetOutputChannel()
|
||||
{
|
||||
switch (m_OutChannel)
|
||||
{
|
||||
case 1:
|
||||
return m_ChannelMixer.outGreen;
|
||||
case 2:
|
||||
return m_ChannelMixer.outBlue;
|
||||
default:
|
||||
return m_ChannelMixer.outRed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 74a26e3294ebad94fa5d78ee95751556
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
using Color = UnityEditor.ShaderGraph.ColorNode.Color;
|
||||
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class ColorControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
ColorMode m_ColorMode;
|
||||
|
||||
public ColorControlAttribute(string label = null, ColorMode colorMode = ColorMode.Default)
|
||||
{
|
||||
m_Label = label;
|
||||
m_ColorMode = colorMode;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new ColorControlView(m_Label, m_ColorMode, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class ColorControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
Color m_Color;
|
||||
ColorField m_ColorField;
|
||||
|
||||
public ColorControlView(string label, ColorMode colorMode, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/ColorControlView"));
|
||||
if (propertyInfo.PropertyType != typeof(Color))
|
||||
throw new ArgumentException("Property must be of type Color.", "propertyInfo");
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
|
||||
m_Color = (Color)m_PropertyInfo.GetValue(m_Node, null);
|
||||
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label(label));
|
||||
|
||||
m_ColorField = new ColorField { value = m_Color.color, hdr = m_Color.mode == ColorMode.HDR, showEyeDropper = false };
|
||||
m_ColorField.RegisterValueChangedCallback(OnChange);
|
||||
Add(m_ColorField);
|
||||
|
||||
VisualElement enumPanel = new VisualElement { name = "enumPanel" };
|
||||
enumPanel.Add(new Label("Mode"));
|
||||
var enumField = new EnumField(m_Color.mode);
|
||||
enumField.RegisterValueChangedCallback(OnModeChanged);
|
||||
enumPanel.Add(enumField);
|
||||
Add(enumPanel);
|
||||
}
|
||||
|
||||
void OnChange(ChangeEvent<UnityEngine.Color> evt)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Color Change");
|
||||
m_Color.color = evt.newValue;
|
||||
m_PropertyInfo.SetValue(m_Node, m_Color, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
|
||||
void OnModeChanged(ChangeEvent<Enum> evt)
|
||||
{
|
||||
if (!evt.newValue.Equals(m_Color.mode))
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
|
||||
m_Color.mode = (ColorMode)evt.newValue;
|
||||
m_ColorField.hdr = m_Color.mode == ColorMode.HDR;
|
||||
m_PropertyInfo.SetValue(m_Node, m_Color, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 34e77444559b414f9fe81f9775229abf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class CubemapControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
|
||||
public CubemapControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new CubemapControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class CubemapControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
public CubemapControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
if (propertyInfo.PropertyType != typeof(Cubemap))
|
||||
throw new ArgumentException("Property must be of type Texture.", "propertyInfo");
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label(label));
|
||||
|
||||
var cubemapField = new ObjectField { value = (Cubemap)m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Cubemap) };
|
||||
cubemapField.RegisterValueChangedCallback(OnChange);
|
||||
Add(cubemapField);
|
||||
}
|
||||
|
||||
void OnChange(ChangeEvent<UnityEngine.Object> evt)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Cubemap Change");
|
||||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: abdad6e5c36e0994290fcacce2fab066
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class DefaultControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
if (propertyInfo.PropertyType == typeof(Color))
|
||||
return new ColorControlView(null, ColorMode.Default, node, propertyInfo);
|
||||
if (typeof(Enum).IsAssignableFrom(propertyInfo.PropertyType))
|
||||
return new EnumControlView(null, node, propertyInfo);
|
||||
if (propertyInfo.PropertyType == typeof(Texture2D))
|
||||
return new TextureControlView(null, node, propertyInfo);
|
||||
if (propertyInfo.PropertyType == typeof(Texture2DArray))
|
||||
return new TextureArrayControlView(null, node, propertyInfo);
|
||||
if (propertyInfo.PropertyType == typeof(Texture3D))
|
||||
return new Texture3DControlView(null, node, propertyInfo);
|
||||
if (MultiFloatControlView.validTypes.Contains(propertyInfo.PropertyType))
|
||||
return new MultiFloatControlView(null, "X", "Y", "Z", "W", node, propertyInfo);
|
||||
if (typeof(Object).IsAssignableFrom(propertyInfo.PropertyType))
|
||||
return new ObjectControlView(null, node, propertyInfo);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 20e01cb163f347c7819ae286c33baf85
|
||||
timeCreated: 1507642280
|
|
@ -0,0 +1,189 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class DielectricSpecularControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
public DielectricSpecularControlAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new DielectricSpecularControlView(node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class DielectricSpecularControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
DielectricSpecularNode.DielectricMaterial m_DielectricMaterial;
|
||||
|
||||
VisualElement m_RangePanel;
|
||||
Slider m_RangeSlider;
|
||||
FloatField m_RangeField;
|
||||
VisualElement m_IORPanel;
|
||||
Slider m_IORSlider;
|
||||
FloatField m_IORField;
|
||||
|
||||
public DielectricSpecularControlView(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/DielectricSpecularControlView"));
|
||||
m_DielectricMaterial = (DielectricSpecularNode.DielectricMaterial)m_PropertyInfo.GetValue(m_Node, null);
|
||||
|
||||
if (propertyInfo.PropertyType != typeof(DielectricSpecularNode.DielectricMaterial))
|
||||
throw new ArgumentException("Property must be of type DielectricMaterial.", "propertyInfo");
|
||||
|
||||
var enumPanel = new VisualElement { name = "enumPanel" };
|
||||
enumPanel.Add(new Label("Material"));
|
||||
var enumField = new EnumField(m_DielectricMaterial.type);
|
||||
enumField.RegisterValueChangedCallback(OnEnumChanged);
|
||||
enumPanel.Add(enumField);
|
||||
Add(enumPanel);
|
||||
|
||||
m_RangePanel = new VisualElement { name = "sliderPanel" };
|
||||
m_RangePanel.Add(new Label("Range"));
|
||||
m_RangeSlider = new Slider(0.01f, 1) { value = m_DielectricMaterial.range };
|
||||
m_RangeSlider.RegisterValueChangedCallback((evt) => OnChangeRangeSlider(evt.newValue));
|
||||
|
||||
m_RangePanel.Add(m_RangeSlider);
|
||||
m_RangeField = AddField(m_RangePanel, m_RangeSlider, 0, m_DielectricMaterial);
|
||||
m_RangePanel.SetEnabled(m_DielectricMaterial.type == DielectricMaterialType.Common);
|
||||
Add(m_RangePanel);
|
||||
|
||||
m_IORPanel = new VisualElement { name = "sliderPanel" };
|
||||
m_IORPanel.Add(new Label("IOR"));
|
||||
m_IORSlider = new Slider(1, 2.5f) { value = m_DielectricMaterial.indexOfRefraction };
|
||||
m_IORSlider.RegisterValueChangedCallback((evt) => OnChangeIORSlider(evt.newValue));
|
||||
|
||||
m_IORPanel.Add(m_IORSlider);
|
||||
m_IORField = AddField(m_IORPanel, m_IORSlider, 1, m_DielectricMaterial);
|
||||
m_IORPanel.SetEnabled(m_DielectricMaterial.type == DielectricMaterialType.Custom);
|
||||
Add(m_IORPanel);
|
||||
}
|
||||
|
||||
void OnEnumChanged(ChangeEvent<Enum> evt)
|
||||
{
|
||||
if (!evt.newValue.Equals(m_DielectricMaterial.type))
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
|
||||
m_DielectricMaterial.type = (DielectricMaterialType)evt.newValue;
|
||||
m_PropertyInfo.SetValue(m_Node, m_DielectricMaterial, null);
|
||||
|
||||
switch (m_DielectricMaterial.type)
|
||||
{
|
||||
case DielectricMaterialType.Common:
|
||||
m_RangePanel.SetEnabled(true);
|
||||
m_IORPanel.SetEnabled(false);
|
||||
break;
|
||||
case DielectricMaterialType.Custom:
|
||||
m_RangePanel.SetEnabled(false);
|
||||
m_IORPanel.SetEnabled(true);
|
||||
break;
|
||||
default:
|
||||
m_RangePanel.SetEnabled(false);
|
||||
m_IORPanel.SetEnabled(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnChangeRangeSlider(float newValue)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Slider Change");
|
||||
m_DielectricMaterial.range = newValue;
|
||||
m_PropertyInfo.SetValue(m_Node, m_DielectricMaterial, null);
|
||||
if (m_RangeField != null)
|
||||
m_RangeField.value = newValue;
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
|
||||
void OnChangeIORSlider(float newValue)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Slider Change");
|
||||
m_DielectricMaterial.indexOfRefraction = newValue;
|
||||
m_PropertyInfo.SetValue(m_Node, m_DielectricMaterial, null);
|
||||
if (m_IORField != null)
|
||||
m_IORField.value = newValue;
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
|
||||
FloatField AddField(VisualElement panel, Slider slider, int index, DielectricSpecularNode.DielectricMaterial initMaterial)
|
||||
{
|
||||
float initValue;
|
||||
if (index == 1)
|
||||
initValue = initMaterial.indexOfRefraction;
|
||||
else
|
||||
initValue = initMaterial.range;
|
||||
|
||||
var field = new FloatField { userData = index, value = initValue };
|
||||
|
||||
field.RegisterCallback<MouseDownEvent>(Repaint);
|
||||
field.RegisterCallback<MouseMoveEvent>(Repaint);
|
||||
field.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var fieldValue = (float)evt.newValue;
|
||||
if (index == 1)
|
||||
m_DielectricMaterial.indexOfRefraction = fieldValue;
|
||||
else
|
||||
m_DielectricMaterial.range = fieldValue;
|
||||
|
||||
m_PropertyInfo.SetValue(m_Node, m_DielectricMaterial, null);
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
field.Q("unity-text-input").RegisterCallback<FocusOutEvent>(evt =>
|
||||
{
|
||||
if (index == 1)
|
||||
RedrawIORControls(m_DielectricMaterial.indexOfRefraction);
|
||||
else
|
||||
RedrawRangeControls(m_DielectricMaterial.range);
|
||||
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
panel.Add(field);
|
||||
return field;
|
||||
}
|
||||
|
||||
void RedrawRangeControls(float value)
|
||||
{
|
||||
value = Mathf.Max(Mathf.Min(value, 1), 0.01f);
|
||||
m_RangePanel.Remove(m_RangeSlider);
|
||||
m_RangeSlider = new Slider(0.01f, 1) { value = value };
|
||||
m_RangeSlider.RegisterValueChangedCallback((evt) => OnChangeRangeSlider(evt.newValue));
|
||||
m_RangePanel.Add(m_RangeSlider);
|
||||
m_RangePanel.Remove(m_RangeField);
|
||||
m_RangeField.value = value;
|
||||
m_RangePanel.Add(m_RangeField);
|
||||
}
|
||||
|
||||
void RedrawIORControls(float value)
|
||||
{
|
||||
value = Mathf.Max(Mathf.Min(value, 5), 1);
|
||||
m_IORPanel.Remove(m_IORSlider);
|
||||
m_IORSlider = new Slider(1, 2.5f) { value = value };
|
||||
m_IORSlider.RegisterValueChangedCallback((evt) => OnChangeIORSlider(evt.newValue));
|
||||
|
||||
m_IORPanel.Add(m_IORSlider);
|
||||
m_IORPanel.Remove(m_IORField);
|
||||
m_IORField.value = value;
|
||||
m_IORPanel.Add(m_IORField);
|
||||
}
|
||||
|
||||
void Repaint<T>(MouseEventBase<T> evt) where T : MouseEventBase<T>, new()
|
||||
{
|
||||
evt.StopPropagation();
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 20b1492eed8154d8f9a454e3563d9c01
|
||||
timeCreated: 1507817885
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class EnumControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
|
||||
public EnumControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new EnumControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class EnumControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
public EnumControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/EnumControlView"));
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
if (!propertyInfo.PropertyType.IsEnum)
|
||||
throw new ArgumentException("Property must be an enum.", "propertyInfo");
|
||||
Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
|
||||
var enumField = new EnumField((Enum)m_PropertyInfo.GetValue(m_Node, null));
|
||||
enumField.RegisterValueChangedCallback(OnValueChanged);
|
||||
Add(enumField);
|
||||
}
|
||||
|
||||
void OnValueChanged(ChangeEvent<Enum> evt)
|
||||
{
|
||||
var value = (Enum)m_PropertyInfo.GetValue(m_Node, null);
|
||||
if (!evt.newValue.Equals(value))
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
|
||||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3a1e13c5e67541d7ad7ae18ea5a834e4
|
||||
timeCreated: 1507817885
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
interface IEnumConversion
|
||||
{
|
||||
Enum from { get; set; }
|
||||
Enum to { get; set; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class EnumConversionControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new EnumConversionControlView(node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class EnumConversionControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
IEnumConversion value
|
||||
{
|
||||
get { return (IEnumConversion)m_PropertyInfo.GetValue(m_Node, null); }
|
||||
set { m_PropertyInfo.SetValue(m_Node, value, null); }
|
||||
}
|
||||
|
||||
public EnumConversionControlView(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
if (!propertyInfo.PropertyType.GetInterfaces().Any(t => t == typeof(IEnumConversion)))
|
||||
throw new ArgumentException("Property type must implement IEnumConversion.");
|
||||
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/EnumConversionControlView"));
|
||||
var currentValue = value;
|
||||
|
||||
var ec = (IEnumConversion)propertyInfo.GetValue(m_Node, null);
|
||||
propertyInfo.SetValue(m_Node, ec, null);
|
||||
|
||||
var fromField = new EnumField(currentValue.from);
|
||||
fromField.RegisterValueChangedCallback(OnFromChanged);
|
||||
Add(fromField);
|
||||
|
||||
var arrowLabel = new Label("➔");
|
||||
Add(arrowLabel);
|
||||
|
||||
var toField = new EnumField(currentValue.to);
|
||||
toField.RegisterValueChangedCallback(OnToChanged);
|
||||
Add(toField);
|
||||
}
|
||||
|
||||
void OnFromChanged(ChangeEvent<Enum> evt)
|
||||
{
|
||||
var currentValue = value;
|
||||
if (!Equals(currentValue.from, evt.newValue))
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change Colorspace From");
|
||||
currentValue.from = evt.newValue;
|
||||
value = currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
void OnToChanged(ChangeEvent<Enum> evt)
|
||||
{
|
||||
var currentValue = value;
|
||||
if (!Equals(currentValue.to, evt.newValue))
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change Colorspace To");
|
||||
currentValue.to = evt.newValue;
|
||||
value = currentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 50c6ddf46f8445fba2689962d438c227
|
||||
timeCreated: 1512640228
|
|
@ -0,0 +1,92 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
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]
|
||||
class GradientObject : ScriptableObject
|
||||
{
|
||||
public Gradient gradient = new Gradient();
|
||||
}
|
||||
|
||||
class GradientControlView : VisualElement
|
||||
{
|
||||
GUIContent m_Label;
|
||||
|
||||
AbstractMaterialNode m_Node;
|
||||
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
[SerializeField]
|
||||
GradientObject m_GradientObject;
|
||||
|
||||
[SerializeField]
|
||||
SerializedObject m_SerializedObject;
|
||||
|
||||
public GradientControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/GradientControlView"));
|
||||
|
||||
if (propertyInfo.PropertyType != typeof(Gradient))
|
||||
throw new ArgumentException("Property must be of type Gradient.", "propertyInfo");
|
||||
new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
|
||||
|
||||
m_GradientObject = ScriptableObject.CreateInstance<GradientObject>();
|
||||
m_GradientObject.gradient = new Gradient();
|
||||
m_SerializedObject = new SerializedObject(m_GradientObject);
|
||||
|
||||
var gradient = (Gradient)m_PropertyInfo.GetValue(m_Node, null);
|
||||
m_GradientObject.gradient.SetKeys(gradient.colorKeys, gradient.alphaKeys);
|
||||
m_GradientObject.gradient.mode = gradient.mode;
|
||||
|
||||
var gradientPanel = new VisualElement { name = "gradientPanel" };
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
gradientPanel.Add(new Label(label));
|
||||
|
||||
var gradientField = new GradientField() { value = m_GradientObject.gradient, colorSpace = ColorSpace.Linear };
|
||||
gradientField.RegisterValueChangedCallback(OnValueChanged);
|
||||
gradientPanel.Add(gradientField);
|
||||
|
||||
Add(gradientPanel);
|
||||
}
|
||||
|
||||
void OnValueChanged(ChangeEvent<Gradient> evt)
|
||||
{
|
||||
m_SerializedObject.Update();
|
||||
var value = (Gradient)m_PropertyInfo.GetValue(m_Node, null);
|
||||
if (!evt.newValue.Equals(value))
|
||||
{
|
||||
m_GradientObject.gradient.SetKeys(evt.newValue.colorKeys, evt.newValue.alphaKeys);
|
||||
m_GradientObject.gradient.mode = evt.newValue.mode;
|
||||
m_SerializedObject.ApplyModifiedProperties();
|
||||
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
|
||||
m_PropertyInfo.SetValue(m_Node, m_GradientObject.gradient, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cd2268cf57344487791694f9f136712e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
|||
using System.Reflection;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
interface IControlAttribute
|
||||
{
|
||||
VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f008211c3394775bdefde0b20e5c8ff
|
||||
timeCreated: 1507642348
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class IdentifierControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
|
||||
public IdentifierControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new IdentifierControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class IdentifierControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
public IdentifierControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
var style = Resources.Load<StyleSheet>("Styles/Controls/IdentifierControlView");
|
||||
if (style) styleSheets.Add(style);
|
||||
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
if (propertyInfo.PropertyType != typeof(string))
|
||||
throw new ArgumentException("Property must be of type string.", "propertyInfo");
|
||||
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label(label));
|
||||
|
||||
var strField = new IdentifierField() { value = (string)m_PropertyInfo.GetValue(m_Node, null) };
|
||||
strField.RegisterValueChangedCallback(OnChange);
|
||||
Add(strField);
|
||||
}
|
||||
|
||||
void OnChange(ChangeEvent<string> evt)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Identifier Change");
|
||||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a0e142b8abd53a243b029b58247caacc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
class IntegerControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
public IntegerControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/IntegerControlView"));
|
||||
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.RegisterValueChangedCallback(OnChange);
|
||||
|
||||
Add(intField);
|
||||
}
|
||||
|
||||
void OnChange(ChangeEvent<int> evt)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Integer Change");
|
||||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 57d18a57866821542806ab5253cf4310
|
||||
timeCreated: 1507817885
|
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class ObjectControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
|
||||
public ObjectControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new ObjectControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
public ObjectControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
if (!typeof(Object).IsAssignableFrom(propertyInfo.PropertyType))
|
||||
throw new ArgumentException("Property must be assignable to UnityEngine.Object.");
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
label = label ?? propertyInfo.Name;
|
||||
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label { text = label });
|
||||
|
||||
var value = (Object)m_PropertyInfo.GetValue(m_Node, null);
|
||||
var objectField = new ObjectField { objectType = propertyInfo.PropertyType, value = value };
|
||||
objectField.RegisterValueChangedCallback(OnValueChanged);
|
||||
Add(objectField);
|
||||
}
|
||||
|
||||
void OnValueChanged(ChangeEvent<Object> evt)
|
||||
{
|
||||
var value = (Object)m_PropertyInfo.GetValue(m_Node, null);
|
||||
if (evt.newValue != value)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change + " + m_Node.name);
|
||||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3f483132ae7b4689b20fd6b8c59633b5
|
||||
timeCreated: 1507900115
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class PopupControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
//string[] m_Entries;
|
||||
|
||||
public PopupControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
//m_Entries = entries;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new PopupControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
struct PopupList
|
||||
{
|
||||
public int selectedEntry;
|
||||
public string[] popupEntries;
|
||||
|
||||
public PopupList(string[] entries, int defaultEntry)
|
||||
{
|
||||
popupEntries = entries;
|
||||
selectedEntry = defaultEntry;
|
||||
}
|
||||
}
|
||||
|
||||
class PopupControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
PopupField<string> m_PopupField;
|
||||
|
||||
public PopupControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/PopupControlView"));
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
|
||||
Type type = propertyInfo.PropertyType;
|
||||
if (type != typeof(PopupList))
|
||||
{
|
||||
throw new ArgumentException("Property must be a PopupList.", "propertyInfo");
|
||||
}
|
||||
|
||||
Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
|
||||
var value = (PopupList)propertyInfo.GetValue(m_Node, null);
|
||||
m_PopupField = new PopupField<string>(new List<string>(value.popupEntries), value.selectedEntry);
|
||||
m_PopupField.RegisterValueChangedCallback(OnValueChanged);
|
||||
Add(m_PopupField);
|
||||
}
|
||||
|
||||
void OnValueChanged(ChangeEvent<string> evt)
|
||||
{
|
||||
var value = (PopupList)m_PropertyInfo.GetValue(m_Node, null);
|
||||
value.selectedEntry = m_PopupField.index;
|
||||
m_PropertyInfo.SetValue(m_Node, value, null);
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 348b3c9679acca945b0df8cb701908f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,169 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
using System.Globalization;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class SliderControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
bool m_DisplayMinMax;
|
||||
|
||||
public SliderControlAttribute(string label = null, bool displayMinMax = false)
|
||||
{
|
||||
m_Label = label;
|
||||
m_DisplayMinMax = displayMinMax;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new SliderControlView(m_Label, m_DisplayMinMax, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class SliderControlView : VisualElement, AbstractMaterialNodeModificationListener
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
bool m_DisplayMinMax;
|
||||
Vector3 m_Value;
|
||||
|
||||
VisualElement m_SliderPanel;
|
||||
Slider m_Slider;
|
||||
FloatField m_SliderInput;
|
||||
FloatField m_MinField;
|
||||
FloatField m_MaxField;
|
||||
|
||||
public SliderControlView(string label, bool displayMinMax, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/SliderControlView"));
|
||||
m_DisplayMinMax = displayMinMax;
|
||||
|
||||
if (propertyInfo.PropertyType != typeof(Vector3))
|
||||
throw new ArgumentException("Property must be of type Vector3.", "propertyInfo");
|
||||
new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
|
||||
m_Value = (Vector3)m_PropertyInfo.GetValue(m_Node, null);
|
||||
|
||||
m_Slider = new Slider(m_Value.y, m_Value.z) { value = m_Value.x };
|
||||
m_Slider.RegisterValueChangedCallback((evt) => OnChangeSlider(evt.newValue));
|
||||
|
||||
m_SliderInput = new FloatField { value = m_Value.x };
|
||||
m_SliderInput.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var value = (float)evt.newValue;
|
||||
m_Value.x = value;
|
||||
m_PropertyInfo.SetValue(m_Node, m_Value, null);
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
m_SliderInput.Q("unity-text-input").RegisterCallback<FocusOutEvent>(evt =>
|
||||
{
|
||||
float minValue = Mathf.Min(m_Value.x, m_Value.y);
|
||||
float maxValue = Mathf.Max(m_Value.x, m_Value.z);
|
||||
m_Value = new Vector3(m_Value.x, minValue, maxValue);
|
||||
m_MinField.value = minValue;
|
||||
m_MaxField.value = maxValue;
|
||||
UpdateSlider();
|
||||
m_PropertyInfo.SetValue(m_Node, m_Value, null);
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
|
||||
m_SliderPanel = new VisualElement { name = "SliderPanel" };
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
m_SliderPanel.Add(new Label(label));
|
||||
|
||||
m_SliderPanel.Add(m_Slider);
|
||||
m_SliderPanel.Add(m_SliderInput);
|
||||
Add(m_SliderPanel);
|
||||
|
||||
if (m_DisplayMinMax)
|
||||
{
|
||||
var fieldsPanel = new VisualElement { name = "FieldsPanel" };
|
||||
m_MinField = AddMinMaxField(fieldsPanel, "Min", 1);
|
||||
m_MaxField = AddMinMaxField(fieldsPanel, "Max", 2);
|
||||
Add(fieldsPanel);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNodeModified(ModificationScope scope)
|
||||
{
|
||||
if (scope == ModificationScope.Graph)
|
||||
{
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
|
||||
void OnChangeSlider(float newValue)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Slider Change");
|
||||
var value = (Vector3)m_PropertyInfo.GetValue(m_Node, null);
|
||||
value.x = newValue;
|
||||
m_PropertyInfo.SetValue(m_Node, value, null);
|
||||
if (m_SliderInput != null)
|
||||
m_SliderInput.value = newValue;
|
||||
m_PropertyInfo.SetValue(m_Node, m_Value, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
|
||||
void UpdateSlider()
|
||||
{
|
||||
m_SliderPanel.Remove(m_Slider);
|
||||
m_Slider = new Slider(m_Value.y, m_Value.z) { value = m_Value.x };
|
||||
m_Slider.RegisterValueChangedCallback((evt) => OnChangeSlider(evt.newValue));
|
||||
m_SliderPanel.Add(m_Slider);
|
||||
m_SliderPanel.Add(m_SliderInput);
|
||||
}
|
||||
|
||||
FloatField AddMinMaxField(VisualElement panel, string label, int index)
|
||||
{
|
||||
var floatField = new FloatField { value = m_Value[index] };
|
||||
if (label != null)
|
||||
{
|
||||
var labelField = new Label(label);
|
||||
panel.Add(labelField);
|
||||
}
|
||||
|
||||
floatField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
m_Value[index] = (float)evt.newValue;
|
||||
m_PropertyInfo.SetValue(m_Node, m_Value, null);
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
floatField.Q("unity-text-input").RegisterCallback<FocusOutEvent>(evt =>
|
||||
{
|
||||
if (index == 1)
|
||||
{
|
||||
m_Value[index] = Mathf.Min(m_Value[index], m_Value.z);
|
||||
m_MinField.value = m_Value[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Value[index] = Mathf.Max(m_Value[index], m_Value.y);
|
||||
m_MaxField.value = m_Value[index];
|
||||
}
|
||||
float newValue = Mathf.Max(Mathf.Min(m_Value.x, m_Value.z), m_Value.y);
|
||||
m_Value.x = newValue;
|
||||
m_SliderInput.value = newValue;
|
||||
UpdateSlider();
|
||||
m_PropertyInfo.SetValue(m_Node, m_Value, null);
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
|
||||
panel.Add(floatField);
|
||||
return floatField;
|
||||
}
|
||||
|
||||
void Repaint<T>(MouseEventBase<T> evt) where T : MouseEventBase<T>, new()
|
||||
{
|
||||
evt.StopPropagation();
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c74a50771637c2d49980f713bbb7f4ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEditor.Graphing;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class TextControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
public TextControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
if (!TextControlView.validTypes.Contains(propertyInfo.PropertyType))
|
||||
return null;
|
||||
return new TextControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class TextControlView : VisualElement
|
||||
{
|
||||
public static Type[] validTypes = { typeof(string) };
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
string m_Value;
|
||||
int m_UndoGroup = -1;
|
||||
public TextControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/TextControlView"));
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
var container = new VisualElement { name = "container" };
|
||||
var thisLabel = new Label(label);
|
||||
container.Add(thisLabel);
|
||||
m_Value = GetValue();
|
||||
string value = null;
|
||||
var field = new TextField { value = m_Value };
|
||||
field.RegisterCallback<MouseDownEvent>(Repaint);
|
||||
field.RegisterCallback<MouseMoveEvent>(Repaint);
|
||||
field.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
value = GetValue();
|
||||
value = evt.newValue;
|
||||
if (m_Node.GetType() != typeof(SwizzleNode))
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change" + m_Node.name);
|
||||
m_PropertyInfo.SetValue(m_Node, value, null);
|
||||
m_UndoGroup = -1;
|
||||
}
|
||||
});
|
||||
|
||||
// Pressing escape while we are editing causes it to revert to the original value when we gained focus
|
||||
field.Q("unity-text-input").RegisterCallback<KeyDownEvent>(evt =>
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
|
||||
{
|
||||
Undo.RevertAllDownToGroup(m_UndoGroup);
|
||||
m_UndoGroup = -1;
|
||||
evt.StopPropagation();
|
||||
}
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
field.Q("unity-text-input").RegisterCallback<FocusOutEvent>(evt =>
|
||||
{
|
||||
if (m_Node.GetType() == typeof(SwizzleNode))
|
||||
{
|
||||
//Only set node value when mouse clicked away
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change" + m_Node.name);
|
||||
m_PropertyInfo.SetValue(m_Node, value, null);
|
||||
m_UndoGroup = -1;
|
||||
//Validate graph to update downstream input slot
|
||||
m_Node.owner.ValidateGraph();
|
||||
m_Node.Dirty(ModificationScope.Topological);
|
||||
}
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
container.Add(field);
|
||||
Add(container);
|
||||
}
|
||||
|
||||
string GetValue()
|
||||
{
|
||||
var value = m_PropertyInfo.GetValue(m_Node, null);
|
||||
Assert.IsNotNull(value);
|
||||
return (string)value;
|
||||
}
|
||||
|
||||
void Repaint<T>(MouseEventBase<T> evt) where T : MouseEventBase<T>, new()
|
||||
{
|
||||
evt.StopPropagation();
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 29c513b592822a84d99669e7845b9d45
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class Texture3DControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
|
||||
public Texture3DControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new Texture3DControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class Texture3DControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
public Texture3DControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
if (propertyInfo.PropertyType != typeof(Texture3D))
|
||||
throw new ArgumentException("Property must be of type Texture 3D.", "propertyInfo");
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label(label));
|
||||
|
||||
var textureField = new ObjectField { value = (Texture3D)m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Texture3D) };
|
||||
textureField.RegisterValueChangedCallback(OnChange);
|
||||
Add(textureField);
|
||||
}
|
||||
|
||||
void OnChange(ChangeEvent<UnityEngine.Object> evt)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Texture Change");
|
||||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 841bd408b769d48caa3011ed9219df24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class TextureArrayControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
|
||||
public TextureArrayControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new TextureArrayControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class TextureArrayControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
public TextureArrayControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
if (propertyInfo.PropertyType != typeof(Texture2DArray))
|
||||
throw new ArgumentException("Property must be of type Texture 2D Array.", "propertyInfo");
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label(label));
|
||||
|
||||
var textureField = new ObjectField { value = (Texture2DArray)m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Texture2DArray) };
|
||||
textureField.RegisterValueChangedCallback(OnChange);
|
||||
Add(textureField);
|
||||
}
|
||||
|
||||
void OnChange(ChangeEvent<UnityEngine.Object> evt)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Texture Change");
|
||||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0e3e309a7d3ff4d2e81a55970ef9b026
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class TextureControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
|
||||
public TextureControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new TextureControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class TextureControlView : VisualElement
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
public TextureControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
if (propertyInfo.PropertyType != typeof(Texture))
|
||||
throw new ArgumentException("Property must be of type Texture.", "propertyInfo");
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label(label));
|
||||
|
||||
var textureField = new ObjectField { value = (Texture)m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Texture) };
|
||||
textureField.RegisterValueChangedCallback(OnChange);
|
||||
Add(textureField);
|
||||
}
|
||||
|
||||
void OnChange(ChangeEvent<UnityEngine.Object> evt)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Texture Change");
|
||||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 12334ec97337f32408251974c4077033
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[Serializable]
|
||||
struct ToggleData
|
||||
{
|
||||
public bool isOn;
|
||||
public bool isEnabled;
|
||||
|
||||
public ToggleData(bool on, bool enabled)
|
||||
{
|
||||
isOn = on;
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
public ToggleData(bool on)
|
||||
{
|
||||
isOn = on;
|
||||
isEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class ToggleControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
|
||||
public ToggleControlAttribute(string label = null)
|
||||
{
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
return new ToggleControlView(m_Label, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class ToggleControlView : VisualElement, AbstractMaterialNodeModificationListener
|
||||
{
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
|
||||
Label m_Label;
|
||||
Toggle m_Toggle;
|
||||
|
||||
public ToggleControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/ToggleControlView"));
|
||||
|
||||
if (propertyInfo.PropertyType != typeof(ToggleData))
|
||||
throw new ArgumentException("Property must be a Toggle.", "propertyInfo");
|
||||
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
|
||||
var value = (ToggleData)m_PropertyInfo.GetValue(m_Node, null);
|
||||
var panel = new VisualElement { name = "togglePanel" };
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
{
|
||||
m_Label = new Label(label);
|
||||
m_Label.SetEnabled(value.isEnabled);
|
||||
panel.Add(m_Label);
|
||||
}
|
||||
|
||||
m_Toggle = new Toggle();
|
||||
m_Toggle.OnToggleChanged(OnChangeToggle);
|
||||
m_Toggle.SetEnabled(value.isEnabled);
|
||||
m_Toggle.value = value.isOn;
|
||||
panel.Add(m_Toggle);
|
||||
Add(panel);
|
||||
}
|
||||
|
||||
public void OnNodeModified(ModificationScope scope)
|
||||
{
|
||||
var value = (ToggleData)m_PropertyInfo.GetValue(m_Node, null);
|
||||
m_Toggle.SetEnabled(value.isEnabled);
|
||||
if (m_Label != null)
|
||||
m_Label.SetEnabled(value.isEnabled);
|
||||
|
||||
if (scope == ModificationScope.Graph)
|
||||
{
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
|
||||
void OnChangeToggle(ChangeEvent<bool> evt)
|
||||
{
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Toggle Change");
|
||||
var value = (ToggleData)m_PropertyInfo.GetValue(m_Node, null);
|
||||
value.isOn = evt.newValue;
|
||||
m_PropertyInfo.SetValue(m_Node, value, null);
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e83ab8eb10c20c4fbed2700d4f4f11c
|
||||
timeCreated: 1507817885
|
|
@ -0,0 +1,152 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing.Controls
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class MultiFloatControlAttribute : Attribute, IControlAttribute
|
||||
{
|
||||
string m_Label;
|
||||
string m_SubLabel1;
|
||||
string m_SubLabel2;
|
||||
string m_SubLabel3;
|
||||
string m_SubLabel4;
|
||||
|
||||
public MultiFloatControlAttribute(string label = null, string subLabel1 = "X", string subLabel2 = "Y", string subLabel3 = "Z", string subLabel4 = "W")
|
||||
{
|
||||
m_SubLabel1 = subLabel1;
|
||||
m_SubLabel2 = subLabel2;
|
||||
m_SubLabel3 = subLabel3;
|
||||
m_SubLabel4 = subLabel4;
|
||||
m_Label = label;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
if (!MultiFloatControlView.validTypes.Contains(propertyInfo.PropertyType))
|
||||
return null;
|
||||
return new MultiFloatControlView(m_Label, m_SubLabel1, m_SubLabel2, m_SubLabel3, m_SubLabel4, node, propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class MultiFloatControlView : VisualElement
|
||||
{
|
||||
public static Type[] validTypes = { typeof(float), typeof(Vector2), typeof(Vector3), typeof(Vector4) };
|
||||
|
||||
AbstractMaterialNode m_Node;
|
||||
PropertyInfo m_PropertyInfo;
|
||||
Vector4 m_Value;
|
||||
int m_UndoGroup = -1;
|
||||
|
||||
public MultiFloatControlView(string label, string subLabel1, string subLabel2, string subLabel3, string subLabel4, AbstractMaterialNode node, PropertyInfo propertyInfo)
|
||||
{
|
||||
var components = Array.IndexOf(validTypes, propertyInfo.PropertyType) + 1;
|
||||
if (components == -1)
|
||||
throw new ArgumentException("Property must be of type float, Vector2, Vector3 or Vector4.", "propertyInfo");
|
||||
|
||||
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/MultiFloatControlView"));
|
||||
m_Node = node;
|
||||
m_PropertyInfo = propertyInfo;
|
||||
|
||||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
|
||||
if (!string.IsNullOrEmpty(label))
|
||||
Add(new Label(label));
|
||||
|
||||
m_Value = GetValue();
|
||||
AddField(0, subLabel1);
|
||||
if (components > 1)
|
||||
AddField(1, subLabel2);
|
||||
if (components > 2)
|
||||
AddField(2, subLabel3);
|
||||
if (components > 3)
|
||||
AddField(3, subLabel4);
|
||||
}
|
||||
|
||||
void AddField(int index, string subLabel)
|
||||
{
|
||||
var dummy = new VisualElement { name = "dummy" };
|
||||
var label = new Label(subLabel);
|
||||
dummy.Add(label);
|
||||
Add(dummy);
|
||||
var field = new FloatField { userData = index, value = m_Value[index] };
|
||||
var dragger = new FieldMouseDragger<double>(field);
|
||||
dragger.SetDragZone(label);
|
||||
field.RegisterCallback<MouseDownEvent>(Repaint);
|
||||
field.RegisterCallback<MouseMoveEvent>(Repaint);
|
||||
field.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var value = GetValue();
|
||||
value[index] = (float)evt.newValue;
|
||||
SetValue(value);
|
||||
m_UndoGroup = -1;
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
field.Q("unity-text-input").RegisterCallback<InputEvent>(evt =>
|
||||
{
|
||||
if (m_UndoGroup == -1)
|
||||
{
|
||||
m_UndoGroup = Undo.GetCurrentGroup();
|
||||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
|
||||
}
|
||||
float newValue;
|
||||
if (!float.TryParse(evt.newData, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out newValue))
|
||||
newValue = 0f;
|
||||
var value = GetValue();
|
||||
value[index] = newValue;
|
||||
SetValue(value);
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
field.Q("unity-text-input").RegisterCallback<KeyDownEvent>(evt =>
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
|
||||
{
|
||||
Undo.RevertAllDownToGroup(m_UndoGroup);
|
||||
m_UndoGroup = -1;
|
||||
m_Value = GetValue();
|
||||
evt.StopPropagation();
|
||||
}
|
||||
this.MarkDirtyRepaint();
|
||||
});
|
||||
Add(field);
|
||||
}
|
||||
|
||||
object ValueToPropertyType(Vector4 value)
|
||||
{
|
||||
if (m_PropertyInfo.PropertyType == typeof(float))
|
||||
return value.x;
|
||||
if (m_PropertyInfo.PropertyType == typeof(Vector2))
|
||||
return (Vector2)value;
|
||||
if (m_PropertyInfo.PropertyType == typeof(Vector3))
|
||||
return (Vector3)value;
|
||||
return value;
|
||||
}
|
||||
|
||||
Vector4 GetValue()
|
||||
{
|
||||
var value = m_PropertyInfo.GetValue(m_Node, null);
|
||||
if (m_PropertyInfo.PropertyType == typeof(float))
|
||||
return new Vector4((float)value, 0f, 0f, 0f);
|
||||
if (m_PropertyInfo.PropertyType == typeof(Vector2))
|
||||
return (Vector2)value;
|
||||
if (m_PropertyInfo.PropertyType == typeof(Vector3))
|
||||
return (Vector3)value;
|
||||
return (Vector4)value;
|
||||
}
|
||||
|
||||
void SetValue(Vector4 value)
|
||||
{
|
||||
m_PropertyInfo.SetValue(m_Node, ValueToPropertyType(value), null);
|
||||
}
|
||||
|
||||
void Repaint<T>(MouseEventBase<T> evt) where T : MouseEventBase<T>, new()
|
||||
{
|
||||
evt.StopPropagation();
|
||||
this.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a515dc1bacc453b870777d8da9a7211
|
||||
timeCreated: 1507642288
|
Loading…
Add table
Add a link
Reference in a new issue