From 9f5d188006a91fe791466d2989ae6552690ebd8f Mon Sep 17 00:00:00 2001 From: nightmask3 Date: Fri, 15 May 2020 13:23:35 -0700 Subject: [PATCH 01/10] Changes to get branch to compile # Conflicts: # com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs --- .../Editor/Data/Graphs/GraphData.cs | 4 +- .../Editor/Data/Interfaces/IInspectable.cs | 52 ++++++++++--------- .../ShaderGUIOverridePropertyDrawer.cs | 9 ++-- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs b/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs index d78942565de..1466748c660 100644 --- a/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs +++ b/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs @@ -733,7 +733,7 @@ public List BuildPropertyDisplayNameList(AbstractShaderProperty ignorePr } } } - + return result; } @@ -901,7 +901,7 @@ void ReplacePropertyNodeWithConcreteNodeNoValidate(PropertyNode propertyNode, bo var node = property.ToConcreteNode() as AbstractMaterialNode; if (node == null) // Some nodes have no concrete form - { + { if (deleteNodeIfNoConcreteFormExists) RemoveNodeNoValidate(propertyNode); return; diff --git a/com.unity.shadergraph/Editor/Data/Interfaces/IInspectable.cs b/com.unity.shadergraph/Editor/Data/Interfaces/IInspectable.cs index 950b179fd1a..198cc7c1f44 100644 --- a/com.unity.shadergraph/Editor/Data/Interfaces/IInspectable.cs +++ b/com.unity.shadergraph/Editor/Data/Interfaces/IInspectable.cs @@ -1,25 +1,27 @@ -using System; -using System.Reflection; -using Data.Interfaces; -using Drawing.Inspector; -using UnityEngine.UIElements; - -namespace UnityEditor.ShaderGraph.Drawing -{ - interface IInspectable - { - // Implementors can override this in order to display their desired string when selected and viewed through the inscetor - string inspectorTitle { get; } - - // This function should return the underlying data object that user wishes to expose to the Inspector - object GetObjectToInspect(); - - // This function should return the property information of whatever object has been marked up for metadata gathering by the inspector - // This might be the same as the object returned by GetObjectToInspect(), it might not - PropertyInfo[] GetPropertyInfo(); - - // Used to provide any data needed by the property drawer from the inspectable - // The inspectorUpdateDelegate is used to trigger an inspector update - void SupplyDataToPropertyDrawer(IPropertyDrawer propertyDrawer, Action inspectorUpdateDelegate); - } -} +using System; +using System.Reflection; +using Data.Interfaces; +using Drawing.Inspector; +using UnityEngine.UIElements; + +namespace UnityEditor.ShaderGraph.Drawing +{ + interface IInspectable + { + // Implementors can override this in order to display their desired string when selected and viewed through the inscetor + string inspectorTitle { get; } + + // This function should return the underlying data object that user wishes to expose to the Inspector + // In the case of data properties like Integers/Floats etc this is the object that contains the properties + // In the case of complex types like GraphData this is the GraphData itself, its up to the PropertyDrawer to define what it needs + object GetObjectToInspect(); + + // This function should return the property information of whatever object has been marked up for metadata gathering by the inspector + // This might be the same as the object returned by GetObjectToInspect(), it might not + PropertyInfo[] GetPropertyInfo(); + + // Used to provide any data needed by the property drawer from the inspectable + // The inspectorUpdateDelegate is used to trigger an inspector update + void SupplyDataToPropertyDrawer(IPropertyDrawer propertyDrawer, Action inspectorUpdateDelegate); + } +} diff --git a/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/ShaderGUIOverridePropertyDrawer.cs b/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/ShaderGUIOverridePropertyDrawer.cs index 57be7eae086..00e2cdf3ccd 100644 --- a/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/ShaderGUIOverridePropertyDrawer.cs +++ b/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/ShaderGUIOverridePropertyDrawer.cs @@ -53,7 +53,8 @@ private VisualElement CreateGUI( shaderGUIOverrideField = null; string storedValue = actualObject.ShaderGUIOverride; - string preferredGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode); + string preferredGUI = String.Empty; + //string preferredGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode); var boolPropertyDrawer = new BoolPropertyDrawer(); propertySheet.Add(boolPropertyDrawer.CreateGUI( @@ -132,7 +133,8 @@ void ProcessShaderGUIField(string newValue) string sanitizedInput = Regex.Replace(newValue, @"(?:[^A-Za-z0-9._])|(?:\s)", ""); if (HasPreferredGUI() && string.IsNullOrEmpty(sanitizedInput)) { - var defaultGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode); + var defaultGUI = String.Empty; + //var defaultGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode); m_ShaderGUIOverrideInfo.ShaderGUIOverride = defaultGUI; } else @@ -200,7 +202,8 @@ private bool ValidCustomEditorType(string customEditorName) private bool HasPreferredGUI() { - return !string.IsNullOrEmpty(GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode)); + return false; + //return !string.IsNullOrEmpty(GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode)); } } } From 11a226d91165404f67e3b9e7c28b2a691cd728ed Mon Sep 17 00:00:00 2001 From: nightmask3 Date: Fri, 15 May 2020 13:27:29 -0700 Subject: [PATCH 02/10] Moved target and subtarget settings to Internal Inspector # Conflicts: # com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs # com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs --- .../Editor/Drawing/Inspector/InspectorView.cs | 30 ++++--- .../GraphDataPropertyDrawer.cs | 78 ++++++++++++++++++- .../Editor/Drawing/Views/GraphEditorView.cs | 9 ++- .../Editor/Drawing/Views/MaterialGraphView.cs | 13 +++- 4 files changed, 106 insertions(+), 24 deletions(-) diff --git a/com.unity.shadergraph/Editor/Drawing/Inspector/InspectorView.cs b/com.unity.shadergraph/Editor/Drawing/Inspector/InspectorView.cs index 2c77a0e7a14..f72ea75739f 100644 --- a/com.unity.shadergraph/Editor/Drawing/Inspector/InspectorView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Inspector/InspectorView.cs @@ -1,16 +1,16 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; - using Data.Interfaces; - using UnityEditor.Experimental.GraphView; - using UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers; - using UnityEditor.ShaderGraph.Drawing.Views; - using UnityEngine; - using UnityEngine.UIElements; - - namespace UnityEditor.ShaderGraph.Drawing.Inspector - { +using Data.Interfaces; +using UnityEditor.Experimental.GraphView; +using UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers; +using UnityEditor.ShaderGraph.Drawing.Views; +using UnityEngine; +using UnityEngine.UIElements; + +namespace UnityEditor.ShaderGraph.Drawing.Inspector +{ class InspectorView : GraphSubWindow { // References @@ -18,7 +18,6 @@ class InspectorView : GraphSubWindow // There's persistent data that is stored in the graph settings property drawer that we need to hold onto between interactions IPropertyDrawer m_graphSettingsPropertyDrawer = new GraphDataPropertyDrawer(); - Action m_previewUpdateDelegate; protected override string windowTitle => "Inspector"; protected override string elementName => "InspectorView"; protected override string styleName => "InspectorView"; @@ -35,10 +34,8 @@ void RegisterPropertyDrawer(Type propertyDrawerType) Debug.Log("Attempted to register a property drawer that isn't marked up with the SGPropertyDrawer attribute!"); } - public InspectorView(GraphView graphView, Action updatePreviewDelegate) : base(graphView) + public InspectorView(GraphView graphView) : base(graphView) { - m_previewUpdateDelegate = updatePreviewDelegate; - var unregisteredPropertyDrawerTypes = TypeCache.GetTypesDerivedFrom().ToList(); foreach (var type in unregisteredPropertyDrawerTypes) @@ -95,12 +92,11 @@ void DrawInspectable( IInspectable inspectable, IPropertyDrawer propertyDrawerToUse = null) { - InspectorUtils.GatherInspectorContent(m_PropertyDrawerList, outputVisualElement, inspectable, TriggerInspectorAndPreviewUpdate, propertyDrawerToUse); + InspectorUtils.GatherInspectorContent(m_PropertyDrawerList, outputVisualElement, inspectable, TriggerInspectorUpdate, propertyDrawerToUse); } - void TriggerInspectorAndPreviewUpdate() + void TriggerInspectorUpdate() { - m_previewUpdateDelegate(); Update(); } diff --git a/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/GraphDataPropertyDrawer.cs b/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/GraphDataPropertyDrawer.cs index f4cd6524888..9d14bbb7784 100644 --- a/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/GraphDataPropertyDrawer.cs +++ b/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/GraphDataPropertyDrawer.cs @@ -1,8 +1,9 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using Data.Interfaces; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing; +using UnityEditor.Graphing.Util; using UnityEditor.ShaderGraph.Internal; using UnityEngine; using UnityEngine.UIElements; @@ -18,6 +19,8 @@ public class GraphDataPropertyDrawer : IPropertyDrawer PostTargetSettingsChangedCallback m_postChangeTargetSettingsCallback; ChangeConcretePrecisionCallback m_postChangeConcretePrecisionCallback; + Dictionary m_TargetFoldouts = new Dictionary(); + public void GetPropertyData( PostTargetSettingsChangedCallback postChangeValueCallback, ChangeConcretePrecisionCallback changeConcretePrecisionCallback) @@ -26,6 +29,75 @@ public void GetPropertyData( m_postChangeConcretePrecisionCallback = changeConcretePrecisionCallback; } + 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)); + + element.Add(new PropertyRow(new Label("Targets")), (row) => + { + row.Add(new IMGUIContainer(() => { + EditorGUI.BeginChangeCheck(); + var activeTargetBitmask = EditorGUILayout.MaskField(graphData.activeTargetBitmask, graphData.validTargets.Select(x => x.displayName).ToArray(), GUILayout.Width(100f)); + if (EditorGUI.EndChangeCheck()) + { + RegisterActionToUndo("Change active Targets"); + graphData.activeTargetBitmask = activeTargetBitmask; + graphData.UpdateActiveTargets(); + m_postChangeTargetSettingsCallback(); + } + })); + }); + + // Iterate active TargetImplementations + foreach(var target in graphData.activeTargets) + { + // Ensure enabled state is being tracked and get value + bool foldoutActive = true; + if(!m_TargetFoldouts.TryGetValue(target.displayName, out foldoutActive)) + { + m_TargetFoldouts.Add(target.displayName, foldoutActive); + } + + // Create foldout + var foldout = new Foldout() { text = target.displayName, value = foldoutActive }; + element.Add(foldout); + foldout.RegisterValueChangedCallback(evt => + { + // Update foldout value and rebuild + m_TargetFoldouts[target.displayName] = evt.newValue; + foldout.value = evt.newValue; + onChange(); + }); + + if(foldout.value) + { + // Get settings for Target + var context = new TargetPropertyGUIContext(); + target.GetPropertiesGUI(ref context, onChange, RegisterActionToUndo); + + foreach(var property in context.properties) + { + element.Add(property); + } + } + } + + return element; + } + internal VisualElement CreateGUI(GraphData graphData) { var propertySheet = new VisualElement() {name = "graphSettings"}; @@ -44,6 +116,8 @@ internal VisualElement CreateGUI(GraphData graphData) ConcretePrecision.Float, out var propertyVisualElement)); + propertySheet.Add(GetSettings(graphData, () => this.m_postChangeTargetSettingsCallback())); + return propertySheet; } diff --git a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs index c039ec43eaf..921f71481cb 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs @@ -233,7 +233,8 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage var content = new VisualElement { name = "content" }; { - m_GraphView = new MaterialGraphView(graph) { name = "GraphView", viewDataKey = "MaterialGraphView" }; + m_GraphView = new MaterialGraphView(graph, () => { }) + { name = "GraphView", viewDataKey = "MaterialGraphView" }; m_GraphView.SetupZoom(0.05f, 8); m_GraphView.AddManipulator(new ContentDragger()); m_GraphView.AddManipulator(new SelectionDragger()); @@ -248,7 +249,7 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage CreateMasterPreview(); // When Matt integrates his stacks work, the inspector will need to trigger preview updates - CreateInspector(() => { }); + CreateInspector(); UpdateSubWindowsVisibility(); @@ -359,9 +360,9 @@ void CreateMasterPreview() m_MasterPreviewView.previewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout; } - void CreateInspector(Action previewUpdateDelegate) + void CreateInspector() { - m_InspectorView = new InspectorView(graphView, previewUpdateDelegate); + m_InspectorView = new InspectorView(graphView); m_GraphView.Add(m_InspectorView); m_GraphView.OnSelectionChange += selectedObjects => m_InspectorView.Update(); } diff --git a/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs b/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs index effa733b024..caf5d29f6ea 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs @@ -36,15 +36,17 @@ protected override bool canCopySelection get { return selection.OfType().Any(x => x.node.canCopyNode) || selection.OfType().Any() || selection.OfType().Any(); } } - public MaterialGraphView(GraphData graph) : this() + public MaterialGraphView(GraphData graph, Action previewUpdateDelegate) : this() { this.graph = graph; + this.m_PreviewManagerUpdateDelegate = previewUpdateDelegate; } [Inspectable("GraphData", null)] public GraphData graph { get; private set; } Action m_InspectorUpdateDelegate; + Action m_PreviewManagerUpdateDelegate; public string inspectorTitle => this.graph.path; @@ -69,8 +71,17 @@ public void SupplyDataToPropertyDrawer(IPropertyDrawer propertyDrawer, Action in void ChangeTargetSettings() { + var activeBlocks = graph.GetActiveBlocksForAllActiveTargets(); + if (ShaderGraphPreferences.autoAddRemoveBlocks) + { + graph.AddRemoveBlocksFromActiveList(activeBlocks); + } + + graph.UpdateActiveBlocks(activeBlocks); + this.m_PreviewManagerUpdateDelegate(); this.m_InspectorUpdateDelegate(); } + void ChangeConcretePrecision(ConcretePrecision newValue) { var graphEditorView = this.GetFirstAncestorOfType(); From 8648bdf159f494546dfdfbd5e74a0d4be16f6038 Mon Sep 17 00:00:00 2001 From: nightmask3 Date: Fri, 15 May 2020 13:34:50 -0700 Subject: [PATCH 03/10] [skip ci] fixing window handling issues with preview and BB, code cleanup [skip ci] # Conflicts: # com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/ShaderGUIOverridePropertyDrawer.cs # com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs # com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs --- .../Drawing/Blackboard/BlackboardProvider.cs | 4 + .../Editor/Drawing/Inspector/InspectorView.cs | 1 - .../Drawing/Inspector/MasterPreviewView.cs | 11 ++- .../ShaderGUIOverridePropertyDrawer.cs.meta | 3 - .../Editor/Drawing/Views/GraphEditorView.cs | 95 +++++++++++-------- .../Editor/Drawing/Views/GraphSubWindow.cs | 39 +++++--- .../Editor/Drawing/Views/MaterialNodeView.cs | 4 - .../Editor/Resources/Styles/Blackboard.uss | 2 + .../Resources/Styles/GraphSubWindow.uss | 4 +- .../Editor/Resources/Styles/InspectorView.uss | 2 +- .../Resources/Styles/MasterPreviewView.uss | 8 +- 11 files changed, 101 insertions(+), 72 deletions(-) delete mode 100644 com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/ShaderGUIOverridePropertyDrawer.cs.meta diff --git a/com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs b/com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs index ac8fcaba640..819566b47a1 100644 --- a/com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs +++ b/com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs @@ -19,6 +19,7 @@ class BlackboardProvider public const int k_PropertySectionIndex = 0; public const int k_KeywordSectionIndex = 1; + const string k_styleName = "Blackboard"; public Blackboard blackboard { get; private set; } Label m_PathLabel; @@ -49,6 +50,9 @@ public BlackboardProvider(GraphData graph) moveItemRequested = MoveItemRequested }; + var styleSheet = Resources.Load($"Styles/{k_styleName}"); + blackboard.styleSheets.Add(styleSheet); + m_PathLabel = blackboard.hierarchy.ElementAt(0).Q