|
|
|
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using UnityEditor.Graphing.Util; |
|
|
|
using UnityEngine.Experimental.UIElements.StyleSheets; |
|
|
|
using Toggle = UnityEngine.Experimental.UIElements.Toggle; |
|
|
|
|
|
|
|
namespace UnityEditor.ShaderGraph.Drawing |
|
|
|
|
|
|
readonly AbstractMaterialGraph m_Graph; |
|
|
|
|
|
|
|
Toggle m_UseCustomReferenceNameToggle; |
|
|
|
IShaderProperty m_Property; |
|
|
|
|
|
|
|
static Type s_ContextualMenuManipulator = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypesOrNothing()).FirstOrDefault(t => t.FullName == "UnityEngine.Experimental.UIElements.ContextualMenuManipulator"); |
|
|
|
m_Property = property; |
|
|
|
m_UseCustomReferenceNameToggle = new Toggle(() => |
|
|
|
{ |
|
|
|
property.useCustomReferenceName = m_UseCustomReferenceNameToggle.on; |
|
|
|
m_ReferenceNameField.SetEnabled(property.useCustomReferenceName); |
|
|
|
m_ReferenceNameField.value = property.referenceName; |
|
|
|
DirtyNodes(ModificationScope.Graph); |
|
|
|
}); |
|
|
|
m_UseCustomReferenceNameToggle.on = property.useCustomReferenceName; |
|
|
|
m_ReferenceNameField.SetEnabled(property.useCustomReferenceName); |
|
|
|
if (!property.useCustomReferenceName) |
|
|
|
return; |
|
|
|
property.customReferenceName = newName.newValue; |
|
|
|
string newReferenceName = m_Graph.SanitizePropertyReferenceName(newName.newValue); |
|
|
|
property.overrideReferenceName = newReferenceName; |
|
|
|
m_ReferenceNameField.value = newReferenceName; |
|
|
|
m_ReferenceNameField.style.fontStyle = StyleValue<FontStyle>.Create(FontStyle.Bold); |
|
|
|
AddRow("Specify reference name", m_UseCustomReferenceNameToggle); |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(property.overrideReferenceName)) |
|
|
|
m_ReferenceNameField.style.fontStyle = StyleValue<FontStyle>.Create(FontStyle.Bold); |
|
|
|
|
|
|
|
if (property is Vector1ShaderProperty) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddToClassList("sgblackboardFieldPropertyView"); |
|
|
|
|
|
|
|
this.AddManipulator((IManipulator)Activator.CreateInstance(s_ContextualMenuManipulator, (Action<ContextualMenuPopulateEvent>)BuildContextualMenu)); |
|
|
|
} |
|
|
|
|
|
|
|
void BuildContextualMenu(ContextualMenuPopulateEvent evt) |
|
|
|
{ |
|
|
|
evt.menu.AppendAction("Reset reference name", e => |
|
|
|
{ |
|
|
|
m_Property.overrideReferenceName = null; |
|
|
|
m_ReferenceNameField.value = m_Property.referenceName; |
|
|
|
m_ReferenceNameField.style.fontStyle = StyleValue<FontStyle>.Create(FontStyle.Normal); |
|
|
|
DirtyNodes(ModificationScope.Graph); |
|
|
|
}, ContextualMenu.MenuAction.AlwaysEnabled); |
|
|
|
} |
|
|
|
|
|
|
|
VisualElement AddRow(string labelText, VisualElement control) |
|
|
|