initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,86 @@
using System;
using System.Reflection;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Drawing.Inspector;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
using UnityEditor.Graphing.Util;
using UnityEngine;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
internal interface IGetNodePropertyDrawerPropertyData
{
void GetPropertyData(Action setNodesAsDirtyCallback, Action updateNodeViewsCallback);
}
[SGPropertyDrawer(typeof(AbstractMaterialNode))]
public class AbstractMaterialNodePropertyDrawer : IPropertyDrawer, IGetNodePropertyDrawerPropertyData
{
public Action inspectorUpdateDelegate { get; set; }
Action m_setNodesAsDirtyCallback;
Action m_updateNodeViewsCallback;
public void GetPropertyData(Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
m_setNodesAsDirtyCallback = setNodesAsDirtyCallback;
m_updateNodeViewsCallback = updateNodeViewsCallback;
}
internal virtual void AddCustomNodeProperties(VisualElement parentElement, AbstractMaterialNode node, Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
}
VisualElement CreateGUI(AbstractMaterialNode node, InspectableAttribute attribute, out VisualElement propertyVisualElement)
{
VisualElement nodeSettings = new VisualElement();
var nameLabel = PropertyDrawerUtils.CreateLabel($"{node.name} Node", 0, FontStyle.Bold);
nodeSettings.Add(nameLabel);
if (node.sgVersion < node.latestVersion)
{
string deprecationText = null;
string buttonText = null;
string labelText = null;
MessageType messageType = MessageType.Warning;
if (node is IHasCustomDeprecationMessage nodeWithCustomDeprecationSettings)
{
nodeWithCustomDeprecationSettings.GetCustomDeprecationMessage(out deprecationText, out buttonText, out labelText, out messageType);
}
var help = HelpBoxRow.TryGetDeprecatedHelpBoxRow($"{node.name} Node", () =>
{
m_setNodesAsDirtyCallback?.Invoke();
node.owner.owner.RegisterCompleteObjectUndo($"Update {node.name} Node");
node.ChangeVersion(node.latestVersion);
inspectorUpdateDelegate?.Invoke();
m_updateNodeViewsCallback?.Invoke();
node.Dirty(ModificationScope.Graph);
}, deprecationText, buttonText, labelText, messageType);
if (help != null)
{
nodeSettings.Insert(0, help);
}
}
PropertyDrawerUtils.AddDefaultNodeProperties(nodeSettings, node, m_setNodesAsDirtyCallback, m_updateNodeViewsCallback);
AddCustomNodeProperties(nodeSettings, node, m_setNodesAsDirtyCallback, m_updateNodeViewsCallback);
propertyVisualElement = null;
return nodeSettings;
}
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
(AbstractMaterialNode)actualObject,
attribute,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6436de6b57634b32a3c95d37c1b9b2c0
timeCreated: 1588712275

View file

@ -0,0 +1,55 @@
using System;
using System.Reflection;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Drawing;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(bool))]
class BoolPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(bool newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
bool fieldToDraw,
string labelName,
out VisualElement propertyToggle,
int indentLevel = 0)
{
var row = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
// Create and assign toggle as out variable here so that callers can also do additional work with enabling/disabling if needed
propertyToggle = new Toggle();
row.Add((Toggle)propertyToggle, (toggle) =>
{
toggle.value = fieldToDraw;
});
if (valueChangedCallback != null)
{
var toggle = (Toggle)propertyToggle;
toggle.OnToggleChanged(evt => valueChangedCallback(evt.newValue));
}
row.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return row;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(
PropertyInfo propertyInfo,
object actualObject,
InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newBoolValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newBoolValue }),
(bool)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c6b03af40f8944e4a3c303c7875029d0
timeCreated: 1588094617

View file

@ -0,0 +1,48 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Color))]
class ColorPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Color newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Color fieldToDraw,
string labelName,
out VisualElement propertyColorField,
int indentLevel = 0)
{
var colorField = new ColorField { value = fieldToDraw, showEyeDropper = false, hdr = false };
if (valueChangedCallback != null)
{
colorField.RegisterValueChangedCallback(evt => { valueChangedCallback((Color)evt.newValue); });
}
propertyColorField = colorField;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyColorField);
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Color)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4773ec31c0c943a8b8fe7eca5bbe8c16
timeCreated: 1588106342

View file

@ -0,0 +1,49 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Cubemap))]
class CubemapPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Cubemap newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Cubemap fieldToDraw,
string labelName,
out VisualElement propertyCubemapField,
int indentLevel = 0)
{
var objectField = new ObjectField { value = fieldToDraw, objectType = typeof(Cubemap) };
if (valueChangedCallback != null)
{
objectField.RegisterValueChangedCallback(evt => { valueChangedCallback((Cubemap)evt.newValue); });
}
propertyCubemapField = objectField;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyCubemapField);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Cubemap)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e000b1294b904558acc68a1527795048
timeCreated: 1588106499

View file

@ -0,0 +1,59 @@
using System;
using System.Reflection;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Drawing.Inspector;
using UnityEngine.UIElements;
using UnityEngine;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(CustomFunctionNode))]
public class CustomFunctionNodePropertyDrawer : IPropertyDrawer, IGetNodePropertyDrawerPropertyData
{
Action m_setNodesAsDirtyCallback;
Action m_updateNodeViewsCallback;
void IGetNodePropertyDrawerPropertyData.GetPropertyData(Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
m_setNodesAsDirtyCallback = setNodesAsDirtyCallback;
m_updateNodeViewsCallback = updateNodeViewsCallback;
}
VisualElement CreateGUI(CustomFunctionNode node, InspectableAttribute attribute,
out VisualElement propertyVisualElement)
{
var propertySheet = new PropertySheet(PropertyDrawerUtils.CreateLabel($"{node.name} Node", 0, FontStyle.Bold));
PropertyDrawerUtils.AddDefaultNodeProperties(propertySheet, node, m_setNodesAsDirtyCallback, m_updateNodeViewsCallback);
var inputListView = new ReorderableSlotListView(node, SlotType.Input, true);
inputListView.OnAddCallback += list => inspectorUpdateDelegate();
inputListView.OnRemoveCallback += list => inspectorUpdateDelegate();
inputListView.OnListRecreatedCallback += () => inspectorUpdateDelegate();
propertySheet.Add(inputListView);
var outputListView = new ReorderableSlotListView(node, SlotType.Output, true);
outputListView.OnAddCallback += list => inspectorUpdateDelegate();
outputListView.OnRemoveCallback += list => inspectorUpdateDelegate();
outputListView.OnListRecreatedCallback += () => inspectorUpdateDelegate();
propertySheet.Add(outputListView);
propertySheet.Add(new HlslFunctionView(node));
propertyVisualElement = null;
return propertySheet;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject,
InspectableAttribute attribute)
{
return this.CreateGUI(
(CustomFunctionNode)actualObject,
attribute,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5b314925e5a04562b330a7147571e838
timeCreated: 1588810391

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(IEnumerable<string>))]
class DropdownPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(int newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
IEnumerable<string> fieldToDraw,
string labelName,
out VisualElement textArrayField,
int indentLevel = 0)
{
var propertyRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
textArrayField = new PopupField<string>(fieldToDraw.ToList(), 0);
propertyRow.Add(textArrayField);
var popupField = (PopupField<string>)textArrayField;
popupField.RegisterValueChangedCallback(evt =>
{
valueChangedCallback(popupField.index);
});
propertyRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return propertyRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newSelectedIndex => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newSelectedIndex }),
(IEnumerable<string>)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var textArrayField);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f9a394b3df374578ae75b90960ee4790
timeCreated: 1588106059

View file

@ -0,0 +1,54 @@
using System;
using System.Reflection;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Enum))]
class EnumPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Enum newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Enum fieldToDraw,
string labelName,
Enum defaultValue,
out VisualElement propertyVisualElement,
int indentLevel = 0)
{
var row = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
propertyVisualElement = new EnumField(defaultValue);
row.Add((EnumField)propertyVisualElement, (field) =>
{
field.value = fieldToDraw;
});
if (valueChangedCallback != null)
{
var enumField = (EnumField)propertyVisualElement;
enumField.RegisterValueChangedCallback(evt => valueChangedCallback(evt.newValue));
}
return row;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(
PropertyInfo propertyInfo,
object actualObject,
InspectableAttribute attribute)
{
return this.CreateGUI(newEnumValue =>
propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newEnumValue }),
(Enum)propertyInfo.GetValue(actualObject),
attribute.labelName,
(Enum)attribute.defaultValue,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f08c6b905c574da0b669976fa5353fa8
timeCreated: 1588094508

View file

@ -0,0 +1,49 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(float))]
class FloatPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(float newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
float fieldToDraw,
string labelName,
out VisualElement propertyFloatField,
int indentLevel = 0)
{
var floatField = new FloatField { label = "X", value = fieldToDraw };
floatField.labelElement.style.minWidth = 15;
if (valueChangedCallback != null)
{
floatField.RegisterValueChangedCallback(evt => { valueChangedCallback((float)evt.newValue); });
}
propertyFloatField = floatField;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyFloatField);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(float)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d316720413684b89abb49286f25a4e94
timeCreated: 1588106146

View file

@ -0,0 +1,50 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Gradient))]
class GradientPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Gradient newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Gradient fieldToDraw,
string labelName,
out VisualElement propertyGradientField,
int indentLevel = 0)
{
var objectField = new GradientField { value = fieldToDraw, colorSpace = ColorSpace.Linear };
if (valueChangedCallback != null)
{
objectField.RegisterValueChangedCallback(evt => { valueChangedCallback((Gradient)evt.newValue); });
}
propertyGradientField = objectField;
// Any core widgets used by the inspector over and over should come from some kind of factory
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyGradientField);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Gradient)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6095116b11f143f0a9d9a47f7733261b
timeCreated: 1588106639

View file

@ -0,0 +1,210 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditorInternal;
using UnityEditor.ShaderGraph.Serialization;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(GraphData))]
public class GraphDataPropertyDrawer : IPropertyDrawer
{
public delegate void ChangeGraphDefaultPrecisionCallback(GraphPrecision newDefaultGraphPrecision);
public delegate void PostTargetSettingsChangedCallback();
PostTargetSettingsChangedCallback m_postChangeTargetSettingsCallback;
ChangeGraphDefaultPrecisionCallback m_changeGraphDefaultPrecisionCallback;
Dictionary<Target, bool> m_TargetFoldouts = new Dictionary<Target, bool>();
public void GetPropertyData(
PostTargetSettingsChangedCallback postChangeValueCallback,
ChangeGraphDefaultPrecisionCallback changeGraphDefaultPrecisionCallback)
{
m_postChangeTargetSettingsCallback = postChangeValueCallback;
m_changeGraphDefaultPrecisionCallback = changeGraphDefaultPrecisionCallback;
}
VisualElement GetSettings(GraphData graphData, Action onChange)
{
var element = new VisualElement() { name = "graphSettings" };
if (graphData.isSubGraph)
return element;
void RegisterActionToUndo(string actionName)
{
graphData.owner.RegisterCompleteObjectUndo(actionName);
}
// Add Label
var targetSettingsLabel = new Label("Target Settings");
targetSettingsLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
element.Add(new PropertyRow(targetSettingsLabel));
var targetList = new ReorderableListView<JsonData<Target>>(
graphData.m_ActiveTargets,
"Active Targets",
false, // disallow reordering (active list is sorted)
target => target.value.displayName);
targetList.GetAddMenuOptions = () => graphData.GetPotentialTargetDisplayNames();
targetList.OnAddMenuItemCallback +=
(list, addMenuOptionIndex, addMenuOption) =>
{
RegisterActionToUndo("Add Target");
graphData.SetTargetActive(addMenuOptionIndex);
m_postChangeTargetSettingsCallback();
};
targetList.RemoveItemCallback +=
(list, itemIndex) =>
{
RegisterActionToUndo("Remove Target");
graphData.SetTargetInactive(list[itemIndex].value);
m_postChangeTargetSettingsCallback();
};
element.Add(targetList);
// Iterate active TargetImplementations
foreach (var target in graphData.activeTargets)
{
// Ensure enabled state is being tracked and get value
bool foldoutActive;
if (!m_TargetFoldouts.TryGetValue(target, out foldoutActive))
{
foldoutActive = true;
m_TargetFoldouts.Add(target, foldoutActive);
}
// Create foldout
var foldout = new Foldout() { text = target.displayName, value = foldoutActive, name = "foldout" };
element.Add(foldout);
foldout.AddToClassList("MainFoldout");
foldout.RegisterValueChangedCallback(evt =>
{
// Update foldout value and rebuild
m_TargetFoldouts[target] = evt.newValue;
foldout.value = evt.newValue;
onChange();
});
if (foldout.value)
{
// Get settings for Target
var context = new TargetPropertyGUIContext();
// Indent the content of the foldout
context.globalIndentLevel++;
target.GetPropertiesGUI(ref context, onChange, RegisterActionToUndo);
context.globalIndentLevel--;
element.Add(context);
}
}
#if VFX_GRAPH_10_0_0_OR_NEWER
// Inform the user that VFXTarget is deprecated, if they are using one.
var activeTargetSRP = graphData.m_ActiveTargets.Where(t => !(t.value is VFXTarget));
if (graphData.m_ActiveTargets.Any(t => t.value is VFXTarget) //Use Old VFXTarget
&& activeTargetSRP.Any()
&& activeTargetSRP.All(o => o.value.CanSupportVFX()))
{
var vfxWarning = new HelpBoxRow(MessageType.Info);
var vfxWarningLabel = new Label("The Visual Effect target is deprecated.\n" +
"Use the SRP target(s) instead, and enable 'Support VFX Graph' in the Graph Inspector.\n" +
"Then, you can remove the Visual Effect Target.");
vfxWarningLabel.style.color = new StyleColor(Color.white);
vfxWarningLabel.style.whiteSpace = WhiteSpace.Normal;
vfxWarning.Add(vfxWarningLabel);
element.Add(vfxWarning);
}
#endif
return element;
}
// used to display UI to select GraphPrecision in the GraphData inspector
enum UI_GraphPrecision
{
Single = GraphPrecision.Single,
Half = GraphPrecision.Half,
};
enum UI_SubGraphPrecision
{
Single = GraphPrecision.Single,
Half = GraphPrecision.Half,
Switchable = GraphPrecision.Graph,
};
internal VisualElement CreateGUI(GraphData graphData)
{
var propertySheet = new VisualElement() { name = "graphSettings" };
if (graphData == null)
{
Debug.Log("Attempting to draw something that isn't of type GraphData with a GraphDataPropertyDrawer");
return propertySheet;
}
if (!graphData.isSubGraph)
{
// precision selector for shader graphs
var enumPropertyDrawer = new EnumPropertyDrawer();
propertySheet.Add(enumPropertyDrawer.CreateGUI(
newValue => { m_changeGraphDefaultPrecisionCallback((GraphPrecision)newValue); },
(UI_GraphPrecision)graphData.graphDefaultPrecision,
"Precision",
UI_GraphPrecision.Single,
out var propertyVisualElement));
}
if (graphData.isSubGraph)
{
{
var enum2PropertyDrawer = new EnumPropertyDrawer();
propertySheet.Add(enum2PropertyDrawer.CreateGUI(
newValue => { m_changeGraphDefaultPrecisionCallback((GraphPrecision)newValue); },
(UI_SubGraphPrecision)graphData.graphDefaultPrecision,
"Precision",
UI_SubGraphPrecision.Switchable,
out var propertyVisualElement2));
}
var enumPropertyDrawer = new EnumPropertyDrawer();
propertySheet.Add(enumPropertyDrawer.CreateGUI(
newValue =>
{
graphData.owner.RegisterCompleteObjectUndo("Change Preview Mode");
graphData.previewMode = (PreviewMode)newValue;
},
graphData.previewMode,
"Preview",
PreviewMode.Inherit,
out var propertyVisualElement));
}
propertySheet.Add(GetSettings(graphData, () => this.m_postChangeTargetSettingsCallback()));
return propertySheet;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI((GraphData)actualObject);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4d28f79bb9e147e0837f0411a2269513
timeCreated: 1586821312

View file

@ -0,0 +1,9 @@
using static UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers.ShaderInputPropertyDrawer;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
interface IShaderPropertyDrawer
{
internal void HandlePropertyField(PropertySheet propertySheet, PreChangeValueCallback preChangeValueCallback, PostChangeValueCallback postChangeValueCallback);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f2710f417f893e4db3c7f3649adfa0e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,50 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(int))]
class IntegerPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(int newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
int fieldToDraw,
string labelName,
out VisualElement propertyFloatField,
int indentLevel = 0)
{
var integerField = new IntegerField { value = fieldToDraw };
if (valueChangedCallback != null)
{
integerField.RegisterValueChangedCallback(evt => { valueChangedCallback(evt.newValue); });
}
propertyFloatField = integerField;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyFloatField);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(int)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f2163038c8be4befb58f6aff22e6bd00
timeCreated: 1588106107

View file

@ -0,0 +1,372 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Matrix4x4))]
class MatrixPropertyDrawer : IPropertyDrawer
{
public enum MatrixDimensions
{
Two,
Three,
Four
}
public MatrixDimensions dimension { get; set; }
public delegate Vector4 GetMatrixRowDelegate(int rowNumber);
internal Action PreValueChangeCallback;
internal delegate void ValueChangedCallback(Matrix4x4 newValue);
internal Action PostValueChangeCallback;
// Matrix4x4, Matrix3x3, Matrix2x2 are all value types,
// hence the local value doesn't stay up to date after modified
// Need a callback to fetch the row data directly from the source
internal GetMatrixRowDelegate MatrixRowFetchCallback;
void HandleMatrix2Property(
ValueChangedCallback valueChangedCallback,
PropertySheet propertySheet,
Matrix4x4 matrix2Property,
string labelName = "Default")
{
var vector2PropertyDrawer = new Vector2PropertyDrawer();
vector2PropertyDrawer.preValueChangeCallback = PreValueChangeCallback;
vector2PropertyDrawer.postValueChangeCallback = PostValueChangeCallback;
propertySheet.Add(vector2PropertyDrawer.CreateGUI(
newValue =>
{
Vector2 row1 = MatrixRowFetchCallback(1);
valueChangedCallback(new Matrix4x4()
{
m00 = newValue.x,
m01 = newValue.y,
m02 = 0,
m03 = 0,
m10 = row1.x,
m11 = row1.y,
m12 = 0,
m13 = 0,
m20 = 0,
m21 = 0,
m22 = 0,
m23 = 0,
m30 = 0,
m31 = 0,
m32 = 0,
m33 = 0,
});
},
matrix2Property.GetRow(0),
labelName,
out var row0Field
));
propertySheet.Add(vector2PropertyDrawer.CreateGUI(
newValue =>
{
Vector2 row0 = MatrixRowFetchCallback(0);
valueChangedCallback(new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = 0,
m03 = 0,
m10 = newValue.x,
m11 = newValue.y,
m12 = 0,
m13 = 0,
m20 = 0,
m21 = 0,
m22 = 0,
m23 = 0,
m30 = 0,
m31 = 0,
m32 = 0,
m33 = 0,
});
},
matrix2Property.GetRow(1),
"",
out var row1Field
));
}
void HandleMatrix3Property(
ValueChangedCallback valueChangedCallback,
PropertySheet propertySheet,
Matrix4x4 matrix3Property,
string labelName = "Default")
{
var vector3PropertyDrawer = new Vector3PropertyDrawer();
vector3PropertyDrawer.preValueChangeCallback = PreValueChangeCallback;
vector3PropertyDrawer.postValueChangeCallback = PostValueChangeCallback;
propertySheet.Add(vector3PropertyDrawer.CreateGUI(
newValue =>
{
Vector3 row1 = MatrixRowFetchCallback(1);
Vector3 row2 = MatrixRowFetchCallback(2);
valueChangedCallback(new Matrix4x4()
{
m00 = newValue.x,
m01 = newValue.y,
m02 = newValue.z,
m03 = 0,
m10 = row1.x,
m11 = row1.y,
m12 = row1.z,
m13 = 0,
m20 = row2.x,
m21 = row2.y,
m22 = row2.z,
m23 = 0,
m30 = 0,
m31 = 0,
m32 = 0,
m33 = 0,
});
},
matrix3Property.GetRow(0),
labelName,
out var row0Field
));
propertySheet.Add(vector3PropertyDrawer.CreateGUI(
newValue =>
{
Vector3 row0 = MatrixRowFetchCallback(0);
Vector3 row2 = MatrixRowFetchCallback(2);
valueChangedCallback(new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = row0.z,
m03 = 0,
m10 = newValue.x,
m11 = newValue.y,
m12 = newValue.z,
m13 = 0,
m20 = row2.x,
m21 = row2.y,
m22 = row2.z,
m23 = 0,
m30 = 0,
m31 = 0,
m32 = 0,
m33 = 0,
});
},
matrix3Property.GetRow(1),
"",
out var row1Field
));
propertySheet.Add(vector3PropertyDrawer.CreateGUI(
newValue =>
{
Vector3 row0 = MatrixRowFetchCallback(0);
Vector3 row1 = MatrixRowFetchCallback(1);
valueChangedCallback(new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = row0.z,
m03 = 0,
m10 = row1.x,
m11 = row1.y,
m12 = row1.z,
m13 = 0,
m20 = newValue.x,
m21 = newValue.y,
m22 = newValue.z,
m23 = 0,
m30 = 0,
m31 = 0,
m32 = 0,
m33 = 0,
});
},
matrix3Property.GetRow(2),
"",
out var row2Field
));
}
void HandleMatrix4Property(
ValueChangedCallback valueChangedCallback,
PropertySheet propertySheet,
Matrix4x4 matrix4Property,
string labelName = "Default")
{
var vector4PropertyDrawer = new Vector4PropertyDrawer();
vector4PropertyDrawer.preValueChangeCallback = PreValueChangeCallback;
vector4PropertyDrawer.postValueChangeCallback = PostValueChangeCallback;
propertySheet.Add(vector4PropertyDrawer.CreateGUI(
newValue =>
{
Vector4 row1 = MatrixRowFetchCallback(1);
Vector4 row2 = MatrixRowFetchCallback(2);
Vector4 row3 = MatrixRowFetchCallback(3);
valueChangedCallback(new Matrix4x4()
{
m00 = newValue.x,
m01 = newValue.y,
m02 = newValue.z,
m03 = newValue.w,
m10 = row1.x,
m11 = row1.y,
m12 = row1.z,
m13 = row1.w,
m20 = row2.x,
m21 = row2.y,
m22 = row2.z,
m23 = row2.w,
m30 = row3.x,
m31 = row3.y,
m32 = row3.z,
m33 = row3.w,
});
},
matrix4Property.GetRow(0),
labelName,
out var row0Field
));
propertySheet.Add(vector4PropertyDrawer.CreateGUI(
newValue =>
{
Vector4 row0 = MatrixRowFetchCallback(0);
Vector4 row2 = MatrixRowFetchCallback(2);
Vector4 row3 = MatrixRowFetchCallback(3);
valueChangedCallback(new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = row0.z,
m03 = row0.w,
m10 = newValue.x,
m11 = newValue.y,
m12 = newValue.z,
m13 = newValue.w,
m20 = row2.x,
m21 = row2.y,
m22 = row2.z,
m23 = row2.w,
m30 = row3.x,
m31 = row3.y,
m32 = row3.z,
m33 = row3.w,
});
},
matrix4Property.GetRow(1),
"",
out var row1Field
));
propertySheet.Add(vector4PropertyDrawer.CreateGUI(
newValue =>
{
Vector4 row0 = MatrixRowFetchCallback(0);
Vector4 row1 = MatrixRowFetchCallback(1);
Vector4 row3 = MatrixRowFetchCallback(3);
valueChangedCallback(new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = row0.z,
m03 = row0.w,
m10 = row1.x,
m11 = row1.y,
m12 = row1.z,
m13 = row1.w,
m20 = newValue.x,
m21 = newValue.y,
m22 = newValue.z,
m23 = newValue.w,
m30 = row3.x,
m31 = row3.y,
m32 = row3.z,
m33 = row3.w,
});
},
matrix4Property.GetRow(2),
"",
out var row2Field));
propertySheet.Add(vector4PropertyDrawer.CreateGUI(
newValue =>
{
Vector4 row0 = MatrixRowFetchCallback(0);
Vector4 row1 = MatrixRowFetchCallback(1);
Vector4 row2 = MatrixRowFetchCallback(2);
valueChangedCallback(new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = row0.z,
m03 = row0.w,
m10 = row1.x,
m11 = row1.y,
m12 = row1.z,
m13 = row1.w,
m20 = row2.x,
m21 = row2.y,
m22 = row2.z,
m23 = row2.w,
m30 = newValue.x,
m31 = newValue.y,
m32 = newValue.z,
m33 = newValue.w,
});
},
matrix4Property.GetRow(3),
"",
out var row3Field
));
}
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Matrix4x4 fieldToDraw,
string labelName,
out VisualElement propertyMatrixField,
int indentLevel = 0)
{
var propertySheet = new PropertySheet();
switch (dimension)
{
case MatrixDimensions.Two:
HandleMatrix2Property(valueChangedCallback, propertySheet, fieldToDraw, labelName);
break;
case MatrixDimensions.Three:
HandleMatrix3Property(valueChangedCallback, propertySheet, fieldToDraw, labelName);
break;
case MatrixDimensions.Four:
HandleMatrix4Property(valueChangedCallback, propertySheet, fieldToDraw, labelName);
break;
}
propertyMatrixField = propertySheet;
return propertyMatrixField;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Matrix4x4)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e28fc1d401304229b06d7d0cb83dafce
timeCreated: 1588106778

View file

@ -0,0 +1,34 @@
using System;
using UnityEditor.UIElements;
using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(PositionNode))]
class PositionNodePropertyDrawer : AbstractMaterialNodePropertyDrawer
{
internal override void AddCustomNodeProperties(VisualElement parentElement, AbstractMaterialNode nodeBase, Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
var node = nodeBase as PositionNode;
var previewField = new EnumField(node.m_PositionSource);
var propertyRow = new PropertyRow(new Label("Source"));
propertyRow.Add(previewField, (field) =>
{
field.RegisterValueChangedCallback(evt =>
{
if (evt.newValue.Equals(node.m_PositionSource))
return;
setNodesAsDirtyCallback?.Invoke();
node.owner.owner.RegisterCompleteObjectUndo("Change position source");
node.m_PositionSource = (UnityEditor.ShaderGraph.Internal.PositionSource)evt.newValue;
updateNodeViewsCallback?.Invoke();
node.Dirty(ModificationScope.Graph);
});
});
parentElement.Add(propertyRow);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5a49cf3652c693645931ba8ef38e8e1e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
#if PROCEDURAL_VT_IN_GRAPH
[SGPropertyDrawer(typeof(ProceduralVirtualTextureNode))]
class ProceduralVirtualTextureNodePropertyDrawer : AbstractMaterialNodePropertyDrawer
{
// Use the same HLSLDeclarationStrings as used by the ShaderInputPropertyDrawer, for consistency
static string[] allHLSLDeclarationStrings = new string[]
{
"Do Not Declare", // HLSLDeclaration.DoNotDeclare
"Global", // HLSLDeclaration.Global
"Per Material", // HLSLDeclaration.UnityPerMaterial
"Hybrid Per Instance", // HLSLDeclaration.HybridPerInstance
};
internal override void AddCustomNodeProperties(VisualElement parentElement, AbstractMaterialNode nodeBase, Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
var node = nodeBase as ProceduralVirtualTextureNode;
var hlslDecls = Enum.GetValues(typeof(HLSLDeclaration));
var allowedDecls = new List<HLSLDeclaration>();
for (int i = 0; i < hlslDecls.Length; i++)
{
HLSLDeclaration decl = (HLSLDeclaration)hlslDecls.GetValue(i);
var allowed = node.AllowHLSLDeclaration(decl);
if (allowed)
allowedDecls.Add(decl);
}
var propertyRow = new PropertyRow(new Label("Shader Declaration"));
var popupField = new PopupField<HLSLDeclaration>(
allowedDecls,
node.shaderDeclaration,
(h => allHLSLDeclarationStrings[(int)h]),
(h => allHLSLDeclarationStrings[(int)h]));
popupField.RegisterValueChangedCallback(
evt =>
{
if (node.shaderDeclaration == evt.newValue)
return;
setNodesAsDirtyCallback?.Invoke();
node.owner.owner.RegisterCompleteObjectUndo("Change PVT shader declaration");
node.shaderDeclaration = (UnityEditor.ShaderGraph.Internal.HLSLDeclaration)evt.newValue;
updateNodeViewsCallback?.Invoke();
node.Dirty(ModificationScope.Graph);
});
propertyRow.Add(popupField);
parentElement.Add(propertyRow);
}
}
#endif // PROCEDURAL_VT_IN_GRAPH
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b642e4519e344864db5588b8ed75c329
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,25 @@
using System;
using System.Reflection;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(SampleTexture2DArrayNode))]
class SampleTexture2DArrayNodePropertyDrawer : AbstractMaterialNodePropertyDrawer
{
internal override void AddCustomNodeProperties(VisualElement parentElement, AbstractMaterialNode nodeBase, Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
var node = nodeBase as SampleTexture2DArrayNode;
PropertyDrawerUtils.AddCustomCheckboxProperty(
parentElement, nodeBase, setNodesAsDirtyCallback, updateNodeViewsCallback,
"Use Global Mip Bias", "Change Enable Global Mip Bias",
() => node.enableGlobalMipBias, (val) => node.enableGlobalMipBias = val);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c9a458e42c243844a8725ccc1e32f53b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,25 @@
using System;
using System.Reflection;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(SampleTexture2DNode))]
class SampleTexture2DNodePropertyDrawer : AbstractMaterialNodePropertyDrawer
{
internal override void AddCustomNodeProperties(VisualElement parentElement, AbstractMaterialNode nodeBase, Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
var node = nodeBase as SampleTexture2DNode;
PropertyDrawerUtils.AddCustomCheckboxProperty(
parentElement, nodeBase, setNodesAsDirtyCallback, updateNodeViewsCallback,
"Use Global Mip Bias", "Change Enable Global Mip Bias",
() => node.enableGlobalMipBias, (val) => node.enableGlobalMipBias = val);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18b701456606a9f4ea2b0a8c601ab24b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,145 @@
using System;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(SampleVirtualTextureNode))]
public class SampleVirtualTextureNodePropertyDrawer : IPropertyDrawer
{
VisualElement CreateGUI(SampleVirtualTextureNode node, InspectableAttribute attribute,
out VisualElement propertyVisualElement)
{
PropertySheet propertySheet = new PropertySheet();
var enumPropertyDrawer = new EnumPropertyDrawer();
propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
{
if (node.addressMode == (SampleVirtualTextureNode.AddressMode)newValue)
return;
node.owner.owner.RegisterCompleteObjectUndo("Address Mode Change");
node.addressMode = (SampleVirtualTextureNode.AddressMode)newValue;
},
node.addressMode,
"Address Mode",
SampleVirtualTextureNode.AddressMode.VtAddressMode_Wrap,
out var addressModeVisualElement));
propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
{
if (node.lodCalculation == (SampleVirtualTextureNode.LodCalculation)newValue)
return;
node.owner.owner.RegisterCompleteObjectUndo("Lod Mode Change");
node.lodCalculation = (SampleVirtualTextureNode.LodCalculation)newValue;
},
node.lodCalculation,
"Lod Mode",
SampleVirtualTextureNode.LodCalculation.VtLevel_Automatic,
out var lodCalculationVisualElement));
propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
{
if (node.sampleQuality == (SampleVirtualTextureNode.QualityMode)newValue)
return;
node.owner.owner.RegisterCompleteObjectUndo("Quality Change");
node.sampleQuality = (SampleVirtualTextureNode.QualityMode)newValue;
},
node.sampleQuality,
"Quality",
SampleVirtualTextureNode.QualityMode.VtSampleQuality_High,
out var qualityVisualElement));
var boolPropertyDrawer = new BoolPropertyDrawer();
propertySheet.Add(boolPropertyDrawer.CreateGUI((newValue) =>
{
if (node.noFeedback == !newValue)
return;
node.owner.owner.RegisterCompleteObjectUndo("Feedback Settings Change");
node.noFeedback = !newValue;
},
!node.noFeedback,
"Automatic Streaming",
out var propertyToggle));
propertySheet.Add(boolPropertyDrawer.CreateGUI((newValue) =>
{
if (node.enableGlobalMipBias == newValue)
return;
node.owner.owner.RegisterCompleteObjectUndo("Enable Global Mip Bias VT Change");
node.enableGlobalMipBias = newValue;
},
node.enableGlobalMipBias,
"Use Global Mip Bias",
out var enableGlobalMipBias));
// display warning if the current master node doesn't support virtual texturing
// TODO: Add warning when no active subTarget supports VT
// if (!node.owner.isSubGraph)
// {
// bool supportedByMasterNode =
// node.owner.GetNodes<IMasterNode>().FirstOrDefault()?.supportsVirtualTexturing ?? false;
// if (!supportedByMasterNode)
// propertySheet.Add(new HelpBoxRow(MessageType.Warning),
// (row) => row.Add(new Label(
// "The current master node does not support Virtual Texturing, this node will do regular 2D sampling.")));
// }
// display warning if the current render pipeline doesn't support virtual texturing
HelpBoxRow help = new HelpBoxRow(MessageType.Warning);
string labelText;
IVirtualTexturingEnabledRenderPipeline vtRp =
GraphicsSettings.currentRenderPipeline as IVirtualTexturingEnabledRenderPipeline;
if (vtRp == null)
labelText = "The current render pipeline does not support Virtual Texturing, this node will do regular 2D sampling.";
else if (vtRp.virtualTexturingEnabled == false)
labelText = "The current render pipeline has disabled Virtual Texturing, this node will do regular 2D sampling.";
else
{
#if !ENABLE_VIRTUALTEXTURES
labelText = "Virtual Texturing is disabled globally (possibly by the render pipeline settings), this node will do regular 2D sampling.";
#else
labelText = "";
#endif
}
if (!string.IsNullOrEmpty(labelText))
{
var label = new Label(labelText)
{
name = "message-warn"
};
label.style.whiteSpace = WhiteSpace.Normal;
propertySheet.Add(help, (row) => row.Add(label));
}
propertyVisualElement = propertySheet;
return propertySheet;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject,
InspectableAttribute attribute)
{
return this.CreateGUI(
(SampleVirtualTextureNode)actualObject,
attribute,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ba5078c03394fbc8daa0a30927da29d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,34 @@
using System;
using UnityEditor.UIElements;
using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(SamplerStateNode))]
class SamplerStateNodeNodePropertyDrawer : AbstractMaterialNodePropertyDrawer
{
internal override void AddCustomNodeProperties(VisualElement parentElement, AbstractMaterialNode nodeBase, Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
var node = nodeBase as SamplerStateNode;
var previewField = new EnumField(node.anisotropic);
var propertyRow = new PropertyRow(new Label("Anisotropic Filtering"));
propertyRow.Add(previewField, (field) =>
{
field.RegisterValueChangedCallback(evt =>
{
if (evt.newValue.Equals(node.anisotropic))
return;
setNodesAsDirtyCallback?.Invoke();
node.owner.owner.RegisterCompleteObjectUndo("Change anisotropic filtering");
node.anisotropic = (TextureSamplerState.Anisotropic)evt.newValue;
updateNodeViewsCallback?.Invoke();
node.Dirty(ModificationScope.Graph);
});
});
parentElement.Add(propertyRow);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d58a109f5d7f9154a862ddc85c4d1cc1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bf8c61714a08403bb754cbc99f1963a8
timeCreated: 1586807917

View file

@ -0,0 +1,52 @@
using System;
using System.Reflection;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Drawing.Inspector;
using UnityEngine.UIElements;
using UnityEngine;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(SubGraphOutputNode))]
public class SubGraphOutputNodePropertyDrawer : IPropertyDrawer, IGetNodePropertyDrawerPropertyData
{
Action m_setNodesAsDirtyCallback;
Action m_updateNodeViewsCallback;
public void GetPropertyData(Action setNodesAsDirtyCallback, Action updateNodeViewsCallback)
{
m_setNodesAsDirtyCallback = setNodesAsDirtyCallback;
m_updateNodeViewsCallback = updateNodeViewsCallback;
}
VisualElement CreateGUI(SubGraphOutputNode node, InspectableAttribute attribute,
out VisualElement propertyVisualElement)
{
var propertySheet = new PropertySheet(PropertyDrawerUtils.CreateLabel($"{node.name} Node", 0, FontStyle.Bold));
PropertyDrawerUtils.AddDefaultNodeProperties(propertySheet, node, m_setNodesAsDirtyCallback, m_updateNodeViewsCallback);
var inputListView = new ReorderableSlotListView(node, SlotType.Input, false);
inputListView.OnAddCallback += list => inspectorUpdateDelegate();
inputListView.OnRemoveCallback += list => inspectorUpdateDelegate();
inputListView.OnListRecreatedCallback += () => inspectorUpdateDelegate();
inputListView.AllowedTypeCallback = SlotValueHelper.AllowedAsSubgraphOutput;
propertySheet.Add(inputListView);
propertyVisualElement = propertySheet;
return propertySheet;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject,
InspectableAttribute attribute)
{
return this.CreateGUI(
(SubGraphOutputNode)actualObject,
attribute,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e628cecc47c94d4da6cd8ac547e1a4ef
timeCreated: 1588810477

View file

@ -0,0 +1,53 @@
using System;
using System.Reflection;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Drawing;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(string))]
class TextPropertyDrawer : IPropertyDrawer
{
public TextField textField;
public Label label;
internal delegate void ValueChangedCallback(string newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
string fieldToDraw,
string labelName,
int indentLevel = 0)
{
label = PropertyDrawerUtils.CreateLabel(labelName, indentLevel);
var propertyRow = new PropertyRow(label);
textField = new TextField(512, false, false, ' ') { isDelayed = true };
propertyRow.Add(textField,
textField =>
{
textField.value = fieldToDraw;
});
if (valueChangedCallback != null)
{
textField.RegisterValueChangedCallback(evt => valueChangedCallback(evt.newValue));
}
propertyRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return propertyRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newStringValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newStringValue }),
(string)propertyInfo.GetValue(actualObject),
attribute.labelName);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e68777ed02ae4f5db2f87972b309ae0e
timeCreated: 1588105779

View file

@ -0,0 +1,49 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Texture2DArray))]
class Texture2DArrayPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Texture2DArray newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Texture2DArray fieldToDraw,
string labelName,
out VisualElement propertyColorField,
int indentLevel = 0)
{
var objectField = new ObjectField { value = fieldToDraw, objectType = typeof(Texture2DArray) };
if (valueChangedCallback != null)
{
objectField.RegisterValueChangedCallback(evt => { valueChangedCallback((Texture2DArray)evt.newValue); });
}
propertyColorField = objectField;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyColorField);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Texture2DArray)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2d40dca50e4f4bd2ad13b8d9b7cf0242
timeCreated: 1588106412

View file

@ -0,0 +1,49 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Texture))]
class Texture2DPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Texture newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Texture fieldToDraw,
string labelName,
out VisualElement propertyColorField,
int indentLevel = 0)
{
var objectField = new ObjectField { value = fieldToDraw, objectType = typeof(Texture) };
if (valueChangedCallback != null)
{
objectField.RegisterValueChangedCallback(evt => { valueChangedCallback((Texture)evt.newValue); });
}
propertyColorField = objectField;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyColorField);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Texture)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b37bc2e95bab46b781fef0da2e9a2ece
timeCreated: 1588106384

View file

@ -0,0 +1,49 @@
using System;
using System.Reflection;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Texture3D))]
class Texture3DPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Texture3D newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Texture fieldToDraw,
string labelName,
out VisualElement propertyColorField,
int indentLevel = 0)
{
var objectField = new ObjectField { value = fieldToDraw, objectType = typeof(Texture3D) };
if (valueChangedCallback != null)
{
objectField.RegisterValueChangedCallback(evt => { valueChangedCallback((Texture3D)evt.newValue); });
}
propertyColorField = objectField;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyColorField);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Texture3D)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 63458f45f3af4d04b99a4ccd21430c8a
timeCreated: 1588106453

View file

@ -0,0 +1,56 @@
using System;
using System.Reflection;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(ToggleData))]
class ToggleDataPropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(ToggleData newValue);
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
ToggleData fieldToDraw,
string labelName,
out VisualElement propertyToggle,
int indentLevel = 0)
{
var row = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
// Create and assign toggle as out variable here so that callers can also do additional work with enabling/disabling if needed
propertyToggle = new Toggle();
row.Add((Toggle)propertyToggle, (toggle) =>
{
toggle.value = fieldToDraw.isOn;
});
if (valueChangedCallback != null)
{
var toggle = (Toggle)propertyToggle;
toggle.OnToggleChanged(evt => valueChangedCallback(new ToggleData(evt.newValue)));
}
row.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return row;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(
PropertyInfo propertyInfo,
object actualObject,
InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newBoolValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newBoolValue }),
(ToggleData)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 57c3182c4f4d4ee8a6eccd63407c695d
timeCreated: 1588094576

View file

@ -0,0 +1,104 @@
using System;
using System.Reflection;
using UnityEditor;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Vector2))]
class Vector2PropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Vector2 newValue);
public Action preValueChangeCallback { get; set; }
public Action postValueChangeCallback { get; set; }
EventCallback<KeyDownEvent> m_KeyDownCallback;
EventCallback<FocusOutEvent> m_FocusOutCallback;
public int mUndoGroup { get; set; } = -1;
public Vector2PropertyDrawer()
{
CreateCallbacks();
}
void CreateCallbacks()
{
m_KeyDownCallback = new EventCallback<KeyDownEvent>(evt =>
{
// Record Undo for input field edit
if (mUndoGroup == -1)
{
mUndoGroup = Undo.GetCurrentGroup();
preValueChangeCallback?.Invoke();
}
// Handle escaping input field edit
if (evt.keyCode == KeyCode.Escape && mUndoGroup > -1)
{
Undo.RevertAllDownToGroup(mUndoGroup);
mUndoGroup = -1;
evt.StopPropagation();
}
// Dont record Undo again until input field is unfocused
mUndoGroup++;
postValueChangeCallback?.Invoke();
});
m_FocusOutCallback = new EventCallback<FocusOutEvent>(evt =>
{
// Reset UndoGroup when done editing input field
mUndoGroup = -1;
});
}
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Vector2 fieldToDraw,
string labelName,
out VisualElement propertyVec2Field,
int indentLevel = 0)
{
var vector2Field = new Vector2Field { value = fieldToDraw };
var inputFields = vector2Field.Query("unity-text-input").ToList();
foreach (var inputField in inputFields)
{
inputField.RegisterCallback<KeyDownEvent>(m_KeyDownCallback);
inputField.RegisterCallback<FocusOutEvent>(m_FocusOutCallback);
}
// Bind value changed event to callback to handle dragger behavior before actually settings the value
vector2Field.RegisterValueChangedCallback(evt =>
{
// Only true when setting value via FieldMouseDragger
// Undo recorded once per dragger release
if (mUndoGroup == -1)
preValueChangeCallback?.Invoke();
valueChangedCallback(evt.newValue);
postValueChangeCallback?.Invoke();
});
propertyVec2Field = vector2Field;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyVec2Field);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Vector2)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aa85af60c0d1444181e900d4406b8fab
timeCreated: 1588106188

View file

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Vector3))]
class Vector3PropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Vector3 newValue);
public Action preValueChangeCallback { get; set; }
public Action postValueChangeCallback { get; set; }
EventCallback<KeyDownEvent> m_KeyDownCallback;
EventCallback<FocusOutEvent> m_FocusOutCallback;
public int mUndoGroup { get; set; } = -1;
void CreateCallbacks()
{
m_KeyDownCallback = new EventCallback<KeyDownEvent>(evt =>
{
// Record Undo for input field edit
if (mUndoGroup == -1)
{
mUndoGroup = Undo.GetCurrentGroup();
preValueChangeCallback?.Invoke();
}
// Handle escaping input field edit
if (evt.keyCode == KeyCode.Escape && mUndoGroup > -1)
{
Undo.RevertAllDownToGroup(mUndoGroup);
mUndoGroup = -1;
evt.StopPropagation();
}
// Dont record Undo again until input field is unfocused
mUndoGroup++;
postValueChangeCallback?.Invoke();
});
m_FocusOutCallback = new EventCallback<FocusOutEvent>(evt =>
{
// Reset UndoGroup when done editing input field
mUndoGroup = -1;
});
}
public Vector3PropertyDrawer()
{
CreateCallbacks();
}
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Vector3 fieldToDraw,
string labelName,
out VisualElement propertyVec3Field,
int indentLevel = 0)
{
var vector3Field = new Vector3Field { value = fieldToDraw };
var inputFields = vector3Field.Query("unity-text-input").ToList();
foreach (var inputField in inputFields)
{
inputField.RegisterCallback<KeyDownEvent>(m_KeyDownCallback);
inputField.RegisterCallback<FocusOutEvent>(m_FocusOutCallback);
}
vector3Field.RegisterValueChangedCallback(evt =>
{
// Only true when setting value via FieldMouseDragger
// Undo recorded once per dragger release
if (mUndoGroup == -1)
preValueChangeCallback?.Invoke();
valueChangedCallback(evt.newValue);
postValueChangeCallback?.Invoke();
});
propertyVec3Field = vector3Field;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyVec3Field);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Vector3)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 11cd8a6794214c528e811067773e9e6e
timeCreated: 1588106256

View file

@ -0,0 +1,104 @@
using System;
using System.Reflection;
using UnityEditor;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers
{
[SGPropertyDrawer(typeof(Vector4))]
class Vector4PropertyDrawer : IPropertyDrawer
{
internal delegate void ValueChangedCallback(Vector4 newValue);
public Action preValueChangeCallback { get; set; }
public Action postValueChangeCallback { get; set; }
EventCallback<KeyDownEvent> m_KeyDownCallback;
EventCallback<FocusOutEvent> m_FocusOutCallback;
public int mUndoGroup { get; set; } = -1;
void CreateCallbacks()
{
m_KeyDownCallback = new EventCallback<KeyDownEvent>(evt =>
{
// Record Undo for input field edit
if (mUndoGroup == -1)
{
mUndoGroup = Undo.GetCurrentGroup();
preValueChangeCallback?.Invoke();
}
// Handle escaping input field edit
if (evt.keyCode == KeyCode.Escape && mUndoGroup > -1)
{
Undo.RevertAllDownToGroup(mUndoGroup);
mUndoGroup = -1;
evt.StopPropagation();
}
// Dont record Undo again until input field is unfocused
mUndoGroup++;
postValueChangeCallback?.Invoke();
});
m_FocusOutCallback = new EventCallback<FocusOutEvent>(evt =>
{
// Reset UndoGroup when done editing input field
mUndoGroup = -1;
});
}
public Vector4PropertyDrawer()
{
CreateCallbacks();
}
internal VisualElement CreateGUI(
ValueChangedCallback valueChangedCallback,
Vector4 fieldToDraw,
string labelName,
out VisualElement propertyVec4Field,
int indentLevel = 0)
{
var vector4Field = new Vector4Field { value = fieldToDraw };
var inputFields = vector4Field.Query("unity-text-input").ToList();
foreach (var inputField in inputFields)
{
inputField.RegisterCallback<KeyDownEvent>(m_KeyDownCallback);
inputField.RegisterCallback<FocusOutEvent>(m_FocusOutCallback);
}
vector4Field.RegisterValueChangedCallback(evt =>
{
// Only true when setting value via FieldMouseDragger
// Undo recorded once per dragger release
if (mUndoGroup == -1)
preValueChangeCallback?.Invoke();
valueChangedCallback(evt.newValue);
postValueChangeCallback?.Invoke();
});
propertyVec4Field = vector4Field;
var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));
defaultRow.Add(propertyVec4Field);
defaultRow.styleSheets.Add(Resources.Load<StyleSheet>("Styles/PropertyRow"));
return defaultRow;
}
public Action inspectorUpdateDelegate { get; set; }
public VisualElement DrawProperty(PropertyInfo propertyInfo, object actualObject, InspectableAttribute attribute)
{
return this.CreateGUI(
// Use the setter from the provided property as the callback
newValue => propertyInfo.GetSetMethod(true).Invoke(actualObject, new object[] { newValue }),
(Vector4)propertyInfo.GetValue(actualObject),
attribute.labelName,
out var propertyVisualElement);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 55f775cc6637496c92d1b8df4030ada4
timeCreated: 1588106301