Skip to content

[Backport][ShaderGraph][2021.2][1357648] Fix bug that prevents switching to Graph Settings tab in Inspector when multiple nodes and edge are selected #5701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.shadergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Changed "Create Node" action in ShaderGraph stack separator context menu to "Add Block Node" and added it to main stack context menu

### Fixed
- Fixed bug where it was not possible to switch to Graph Settings tab in Inspector if multiple nodes and an edge was selected [1357648] (https://fogbugz.unity3d.com/f/cases/1357648/)
- Fixed an issue where fog node density was incorrectly calculated.
- Fixed inspector property header styling
- Added padding to the blackboard window to prevent overlapping of resize region and scrollbars interfering with user interaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,15 +690,8 @@ public void AddToSelection(ISelectable selectable)
return;
}

if (selectable != this)
Inspector.InspectorView.forceNodeView = true;

var materialGraphView = m_ViewModel.parentView.GetFirstAncestorOfType<MaterialGraphView>();
materialGraphView?.AddToSelection(selectable);

if (materialGraphView.selection.OfType<SGBlackboardCategory>().Any())
// Turns off the inspector being forced to trigger so user can still use Graph Settings tab if they want, on category selection
Inspector.InspectorView.forceNodeView = false;
}

public void RemoveFromSelection(ISelectable selectable)
Expand Down
50 changes: 39 additions & 11 deletions com.unity.shadergraph/Editor/Drawing/Inspector/InspectorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ class InspectorView : GraphSubWindow
const float k_InspectorUpdateInterval = 0.25f;
const int k_InspectorElementLimit = 20;

bool m_GraphSettingsTabFocused = false;

int m_CurrentlyInspectedElementsCount = 0;

readonly List<Type> m_PropertyDrawerList = new List<Type>();

HashSet<IInspectable> cachedInspectables = new();

// 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();
public override string windowTitle => "Graph Inspector";
Expand All @@ -34,8 +38,6 @@ class InspectorView : GraphSubWindow

Label m_MaxItemsMessageLabel;

internal static bool forceNodeView = true;

void RegisterPropertyDrawer(Type newPropertyDrawerType)
{
if (typeof(IPropertyDrawer).IsAssignableFrom(newPropertyDrawerType) == false)
Expand Down Expand Up @@ -83,8 +85,8 @@ public InspectorView(InspectorViewModel viewModel) : base(viewModel)
m_MaxItemsMessageLabel = m_GraphInspectorView.Q<Label>("maxItemsMessageLabel");
m_ContentContainer.Add(m_GraphInspectorView);
m_ScrollView = this.Q<ScrollView>();
m_GraphInspectorView.Q<TabButton>("GraphSettingsButton").OnSelect += SetScrollModeHorizontal;
m_GraphInspectorView.Q<TabButton>("NodeSettingsButton").OnSelect += SetScrollModeHorizontalVertical;
m_GraphInspectorView.Q<TabButton>("GraphSettingsButton").OnSelect += GraphSettingsTabClicked;
m_GraphInspectorView.Q<TabButton>("NodeSettingsButton").OnSelect += NodeSettingsTabClicked;

isWindowScrollable = true;
isWindowResizable = true;
Expand All @@ -100,13 +102,15 @@ public InspectorView(InspectorViewModel viewModel) : base(viewModel)
m_GraphInspectorView.Activate(m_GraphInspectorView.Q<TabButton>("GraphSettingsButton"));
}

void SetScrollModeHorizontal(TabButton button)
void GraphSettingsTabClicked(TabButton button)
{
m_GraphSettingsTabFocused = true;
m_ScrollView.mode = ScrollViewMode.Vertical;
}

void SetScrollModeHorizontalVertical(TabButton button)
void NodeSettingsTabClicked(TabButton button)
{
m_GraphSettingsTabFocused = false;
m_ScrollView.mode = ScrollViewMode.VerticalAndHorizontal;
}

Expand All @@ -130,28 +134,41 @@ public void Update()
ShowGraphSettings_Internal(m_GraphSettingsContainer);

m_NodeSettingsContainer.Clear();
m_CurrentlyInspectedElementsCount = 0;

try
{
bool anySelectables = false;
int currentInspectablesCount = 0;
var currentInspectables = new HashSet<IInspectable>();
foreach (var selectable in selection)
{
if (selectable is IInspectable inspectable)
{
DrawInspectable(m_NodeSettingsContainer, inspectable);
m_CurrentlyInspectedElementsCount++;
currentInspectablesCount++;
anySelectables = true;
currentInspectables.Add(inspectable);
}

if (m_CurrentlyInspectedElementsCount == k_InspectorElementLimit)
if (currentInspectablesCount == k_InspectorElementLimit)
{
m_NodeSettingsContainer.Add(m_MaxItemsMessageLabel);
m_MaxItemsMessageLabel.style.visibility = Visibility.Visible;
break;
}
}
if (anySelectables && forceNodeView)

// If we have changed our inspector selection while the graph settings tab was focused, we want to switch back to the node settings tab, so invalidate the flag
foreach (var currentInspectable in currentInspectables)
{
if (cachedInspectables.Contains(currentInspectable) == false)
m_GraphSettingsTabFocused = false;
}

cachedInspectables = currentInspectables;
m_CurrentlyInspectedElementsCount = currentInspectablesCount;

if (anySelectables && !m_GraphSettingsTabFocused)
{
// Anything selectable in the graph (GraphSettings not included) is only ever interacted with through the
// Node Settings tab so we can make the assumption they want to see that tab
Expand Down Expand Up @@ -180,9 +197,20 @@ void DrawInspectable(
internal void HandleGraphChanges()
{
float timePassed = (float)(EditorApplication.timeSinceStartup % k_InspectorUpdateInterval);

int currentInspectablesCount = 0;
foreach (var selectable in selection)
{
if (selectable is IInspectable)
currentInspectablesCount++;
}

// Don't update for selections beyond a certain amount as they are no longer visible in the inspector past a certain point and only cost performance as the user performs operations
if (timePassed < 0.01f && selection.Count < k_InspectorElementLimit && selection.Count != m_CurrentlyInspectedElementsCount)
if (timePassed < 0.01f && selection.Count < k_InspectorElementLimit && currentInspectablesCount != m_CurrentlyInspectedElementsCount)
{
m_GraphSettingsTabFocused = false;
Update();
}
}

void TriggerInspectorUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ void ChangeTargetSettings()

graph.UpdateActiveBlocks(activeBlocks);
this.m_PreviewManagerUpdateDelegate();
//Quick bugfix for 1327208. Can be fixed properly with GTF
Inspector.InspectorView.forceNodeView = false;
this.m_InspectorUpdateDelegate();
Inspector.InspectorView.forceNodeView = true;
}

void ChangePrecision(GraphPrecision newGraphDefaultPrecision)
Expand Down