Skip to content

Fixed various Look Dev issues after exiting Playmode #2956

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 3 commits into from
Jan 11, 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
22 changes: 16 additions & 6 deletions com.unity.render-pipelines.core/Editor/LookDev/CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,17 @@ virtual protected bool isDragging
}
}

public CameraController(CameraState cameraState, DisplayWindow window, Action focused)
public CameraController(DisplayWindow window, Action focused)
{
m_CameraState = cameraState;
m_Window = window;
m_Focused = focused;
}

public void UpdateCameraState(Context context, ViewIndex index)
{
m_CameraState = context.GetViewContent(index).camera;
}

private void ResetCameraControl()
{
isDragging = false;
Expand Down Expand Up @@ -458,16 +462,22 @@ class SwitchableCameraController : CameraController
bool switchedDrag = false;
bool switchedWheel = false;

public SwitchableCameraController(CameraState cameraStateFirstView, CameraState cameraStateSecondView, DisplayWindow window, Action<ViewIndex> focused)
: base(cameraStateFirstView, window, null)
public SwitchableCameraController(DisplayWindow window, Action<ViewIndex> focused)
: base(window, null)
{
m_FirstView = cameraStateFirstView;
m_SecondView = cameraStateSecondView;
m_CurrentViewIndex = ViewIndex.First;

m_Focused = () => focused?.Invoke(m_CurrentViewIndex);
}

public void UpdateCameraState(Context context)
{
m_FirstView = context.GetViewContent(ViewIndex.First).camera;
m_SecondView = context.GetViewContent(ViewIndex.Second).camera;

m_CameraState = m_CurrentViewIndex == ViewIndex.First ? m_FirstView : m_SecondView;
}

void SwitchTo(ViewIndex index)
{
CameraState stateToSwitch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ bool isDragging
}
}

public ComparisonGizmoController(ComparisonGizmoState state, SwitchableCameraController switcher)
public ComparisonGizmoController(SwitchableCameraController switcher)
{
m_State = state;
m_Switcher = switcher;
}

public void UpdateGizmoState(ComparisonGizmoState state)
{
m_State = state;
}

protected override void RegisterCallbacksOnTarget()
{
target.RegisterCallback<MouseDownEvent>(OnMouseDown);
Expand Down
16 changes: 11 additions & 5 deletions com.unity.render-pipelines.core/Editor/LookDev/Compositor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,15 @@ public bool pixelPerfect

public Compositer(
IViewDisplayer displayer,
Context contexts,
IDataProvider dataProvider,
StageCache stages)
{
m_Displayer = displayer;
m_Contexts = contexts;

m_RenderDataCache = new RenderingData[2]
{
new RenderingData() { stage = stages[ViewIndex.First], updater = contexts.GetViewContent(ViewIndex.First).camera },
new RenderingData() { stage = stages[ViewIndex.Second], updater = contexts.GetViewContent(ViewIndex.Second).camera }
new RenderingData() { stage = stages[ViewIndex.First] },
new RenderingData() { stage = stages[ViewIndex.Second] }
};

m_Displayer.OnRenderDocAcquisitionTriggered += RenderDocAcquisitionRequested;
Expand Down Expand Up @@ -197,6 +195,12 @@ public void Dispose()

public void Render()
{
// This can happen when entering/leaving playmode.
if (LookDev.dataProvider == null)
return;

m_Contexts = LookDev.currentContext;

//TODO: make integration EditorWindow agnostic!
if (UnityEditorInternal.RenderDoc.IsLoaded() && UnityEditorInternal.RenderDoc.IsSupported() && m_RenderDocAcquisitionRequested)
UnityEditorInternal.RenderDoc.BeginCaptureRenderDoc(m_Displayer as EditorWindow);
Expand Down Expand Up @@ -236,11 +240,13 @@ void AcquireDataForView(ViewIndex index, Rect viewport)

m_RenderTextures.UpdateSize(renderingData.viewPort, index, m_Renderer.pixelPerfect, renderingData.stage.camera);

int debugMode = m_Contexts.GetViewContent(index).debug.viewMode;
int debugMode = view.debug.viewMode;
if (debugMode != -1)
LookDev.dataProvider.UpdateDebugMode(debugMode);

renderingData.output = m_RenderTextures[index, ShadowCompositionPass.MainView];
renderingData.updater = view.camera;

m_Renderer.BeginRendering(renderingData, LookDev.dataProvider);
m_Renderer.Acquire(renderingData);

Expand Down
24 changes: 15 additions & 9 deletions com.unity.render-pipelines.core/Editor/LookDev/DisplayWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ event Action IViewDisplayer.OnUpdateRequested
StyleSheet styleSheet = null;
StyleSheet styleSheetLight = null;

SwitchableCameraController m_FirstOrCompositeManipulator;
CameraController m_SecondManipulator;
ComparisonGizmoController m_GizmoManipulator;

void ReloadStyleSheets()
{
if (styleSheet == null || styleSheet.Equals(null))
Expand Down Expand Up @@ -395,9 +399,7 @@ void CreateViews()
m_Views[(int)ViewIndex.Second] = new Image() { name = Style.k_SecondViewName, image = Texture2D.blackTexture };
m_ViewContainer.Add(m_Views[(int)ViewIndex.Second]);

var firstOrCompositeManipulator = new SwitchableCameraController(
LookDev.currentContext.GetViewContent(ViewIndex.First).camera,
LookDev.currentContext.GetViewContent(ViewIndex.Second).camera,
m_FirstOrCompositeManipulator = new SwitchableCameraController(
this,
index =>
{
Expand All @@ -406,8 +408,7 @@ void CreateViews()
if (sidePanel == SidePanel.Environment && environment != null && LookDev.currentContext.environmentLibrary != null)
m_EnvironmentList.selectedIndex = LookDev.currentContext.environmentLibrary.IndexOf(environment);
});
var secondManipulator = new CameraController(
LookDev.currentContext.GetViewContent(ViewIndex.Second).camera,
m_SecondManipulator = new CameraController(
this,
() =>
{
Expand All @@ -416,10 +417,10 @@ void CreateViews()
if (sidePanel == SidePanel.Environment && environment != null && LookDev.currentContext.environmentLibrary != null)
m_EnvironmentList.selectedIndex = LookDev.currentContext.environmentLibrary.IndexOf(environment);
});
var gizmoManipulator = new ComparisonGizmoController(LookDev.currentContext.layout.gizmoState, firstOrCompositeManipulator);
m_Views[(int)ViewIndex.First].AddManipulator(gizmoManipulator); //must take event first to switch the firstOrCompositeManipulator
m_Views[(int)ViewIndex.First].AddManipulator(firstOrCompositeManipulator);
m_Views[(int)ViewIndex.Second].AddManipulator(secondManipulator);
m_GizmoManipulator = new ComparisonGizmoController(m_FirstOrCompositeManipulator);
m_Views[(int)ViewIndex.First].AddManipulator(m_GizmoManipulator); //must take event first to switch the firstOrCompositeManipulator
m_Views[(int)ViewIndex.First].AddManipulator(m_FirstOrCompositeManipulator);
m_Views[(int)ViewIndex.Second].AddManipulator(m_SecondManipulator);

m_NoObject1 = new Label(Style.k_DragAndDropObject);
m_NoObject1.style.flexGrow = 1;
Expand Down Expand Up @@ -667,6 +668,11 @@ void Update()
Debug.LogError("LookDev is not supported: No SRP detected.");
LookDev.Close();
}

// All those states coming from the Contexts can become invalid after a domain reload so we need to update them.
m_FirstOrCompositeManipulator.UpdateCameraState(LookDev.currentContext);
m_SecondManipulator.UpdateCameraState(LookDev.currentContext, ViewIndex.Second);
m_GizmoManipulator.UpdateGizmoState(LookDev.currentContext.layout.gizmoState);
}

void OnGUI()
Expand Down
17 changes: 14 additions & 3 deletions com.unity.render-pipelines.core/Editor/LookDev/LookDev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ internal static IDataProvider dataProvider
internal static Context currentContext
{
//Lazy init: load it when needed instead in static even if you do not support lookdev
get => s_CurrentContext ?? (s_CurrentContext = LoadConfigInternal() ?? defaultContext);
get
{
if (s_CurrentContext == null || s_CurrentContext.Equals(null))
{
s_CurrentContext = LoadConfigInternal();
if (s_CurrentContext == null)
s_CurrentContext = defaultContext;

ReloadStage(false);
}
return s_CurrentContext;
}
private set => s_CurrentContext = value;
}

Expand Down Expand Up @@ -161,9 +172,9 @@ static void WaitingSRPReloadForConfiguringRenderer(int maxAttempt, bool reloadWi
static void ConfigureRenderer(bool reloadWithTemporaryID)
{
s_Stages?.Dispose(); //clean previous occurrence on reloading
s_Stages = new StageCache(dataProvider, currentContext);
s_Stages = new StageCache(dataProvider);
s_Compositor?.Dispose(); //clean previous occurrence on reloading
s_Compositor = new Compositer(s_ViewDisplayer, currentContext, dataProvider, s_Stages);
s_Compositor = new Compositer(s_ViewDisplayer, dataProvider, s_Stages);
}

static void LinkViewDisplayer()
Expand Down
8 changes: 3 additions & 5 deletions com.unity.render-pipelines.core/Editor/LookDev/Stage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,15 @@ class StageCache : IDisposable
const string secondStageName = "LookDevSecondView";

Stage[] m_Stages;
Context m_Contexts;
IDataProvider m_CurrentDataProvider;

public Stage this[ViewIndex index]
=> m_Stages[(int)index];

public bool initialized { get; private set; }

public StageCache(IDataProvider dataProvider, Context contexts)
public StageCache(IDataProvider dataProvider)
{
m_Contexts = contexts;
m_Stages = new Stage[2]
{
InitStage(ViewIndex.First, dataProvider),
Expand Down Expand Up @@ -333,7 +331,7 @@ public void UpdateSceneObjects(ViewIndex index)
Stage stage = this[index];
stage.Clear();

var viewContent = m_Contexts.GetViewContent(index);
var viewContent = LookDev.currentContext.GetViewContent(index);
if (viewContent == null)
{
viewContent.viewedInstanceInPreview = null;
Expand All @@ -347,7 +345,7 @@ public void UpdateSceneObjects(ViewIndex index)
public void UpdateSceneLighting(ViewIndex index, IDataProvider provider)
{
Stage stage = this[index];
Environment environment = m_Contexts.GetViewContent(index).environment;
Environment environment = LookDev.currentContext.GetViewContent(index).environment;
provider.UpdateSky(stage.camera,
environment == null ? default : environment.sky,
stage.runtimeInterface);
Expand Down