Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
glabute committed Nov 21, 2024
1 parent fd12c89 commit e4246bc
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 124 deletions.
80 changes: 73 additions & 7 deletions com.unity.cinemachine/Tests/Editor/BlendManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public FakeMixer(string name) : base(name) {}
FakeMixer m_Mixer = new ("Mixer");
FakeCamera m_Cam1 = new ("Cam1");
FakeCamera m_Cam2 = new ("Cam2");
FakeCamera m_Cam3 = new ("Cam3");

int m_ActivatedEventCount;
int m_DeactivatedEventCount;
Expand Down Expand Up @@ -57,21 +58,26 @@ [TearDown] public void TearDown()

void ResetCounters() => m_ActivatedEventCount = m_DeactivatedEventCount = m_BlendCreatedCount = m_BlendFinishedCount = 0;

void ProcessFrame(ICinemachineCamera cam, float deltaTime)
void Reset(float blendTime)
{
m_BlendManager.UpdateRootFrame(m_Mixer, cam, Vector3.up, deltaTime);
m_BlendManager.LookupBlendDelegate = (outgoing, incoming)
=> new (CinemachineBlendDefinition.Styles.EaseInOut, blendTime); // constant blend time
m_BlendManager.ResetRootFrame();
ProcessFrame(null, 0.1f);
ResetCounters();
}

void ProcessFrame(ICinemachineCamera activeCam, float deltaTime)
{
m_BlendManager.UpdateRootFrame(m_Mixer, activeCam, Vector3.up, deltaTime);
m_BlendManager.ComputeCurrentBlend();
m_BlendManager.ProcessActiveCamera(m_Mixer, Vector3.up, deltaTime);
}

[Test]
public void TestEvents()
{
m_BlendManager.LookupBlendDelegate = (outgoing, incoming)
=> new (CinemachineBlendDefinition.Styles.EaseInOut, 1); // constant blend time of 1

ResetCounters();
m_BlendManager.ResetRootFrame();
Reset(1); // constant blend time of 1

// We should get an initial activation event, no blend
ProcessFrame(m_Cam1, 0.1f);
Expand Down Expand Up @@ -110,5 +116,65 @@ public void TestEvents()
Assert.AreEqual(1, m_BlendFinishedCount);
Assert.That(m_BlendManager.IsBlending, Is.False);
}

[Test]
public void TestEventsNestedBlend()
{
Reset(1); // constant blend time of 1

// We should get an initial activation event, no blend
ProcessFrame(m_Cam1, 0.1f);
Assert.AreEqual(1, m_ActivatedEventCount);
Assert.AreEqual(0, m_DeactivatedEventCount);
Assert.AreEqual(0, m_BlendFinishedCount);
Assert.AreEqual(0, m_BlendCreatedCount);
Assert.That(m_BlendManager.IsBlending, Is.False);

ProcessFrame(m_Cam1, 0.1f);
Assert.AreEqual(1, m_ActivatedEventCount);
Assert.AreEqual(0, m_DeactivatedEventCount);
Assert.AreEqual(0, m_BlendCreatedCount);
Assert.AreEqual(0, m_BlendFinishedCount);
Assert.That(m_BlendManager.IsBlending, Is.False);

// Activate new camera, blend will take 1 sec
ProcessFrame(m_Cam2, 0.1f);
Assert.AreEqual(2, m_ActivatedEventCount);
Assert.AreEqual(0, m_DeactivatedEventCount);
Assert.AreEqual(1, m_BlendCreatedCount);
Assert.AreEqual(0, m_BlendFinishedCount);
Assert.That(m_BlendManager.IsBlending, Is.True);

ProcessFrame(m_Cam2, 0.5f);
Assert.AreEqual(2, m_ActivatedEventCount);
Assert.AreEqual(0, m_DeactivatedEventCount);
Assert.AreEqual(1, m_BlendCreatedCount);
Assert.AreEqual(0, m_BlendFinishedCount);
Assert.That(m_BlendManager.IsBlending, Is.True);

// Acivate new cam before old blend is finished
ProcessFrame(m_Cam3, 0.1f);
Assert.AreEqual(3, m_ActivatedEventCount);
Assert.AreEqual(0, m_DeactivatedEventCount);
Assert.AreEqual(2, m_BlendCreatedCount);
Assert.AreEqual(0, m_BlendFinishedCount);
Assert.That(m_BlendManager.IsBlending, Is.True);

// After first blend is finished, check the counters
ProcessFrame(m_Cam3, 0.5f);
Assert.AreEqual(3, m_ActivatedEventCount);
Assert.AreEqual(1, m_DeactivatedEventCount);
Assert.AreEqual(2, m_BlendCreatedCount);
Assert.AreEqual(0, m_BlendFinishedCount); // blend was interrupted, never finished
Assert.That(m_BlendManager.IsBlending, Is.True);

// After second blend is finished, check the counters
ProcessFrame(m_Cam3, 0.5f);
Assert.AreEqual(3, m_ActivatedEventCount);
Assert.AreEqual(2, m_DeactivatedEventCount);
Assert.AreEqual(2, m_BlendCreatedCount);
Assert.AreEqual(1, m_BlendFinishedCount);
Assert.That(m_BlendManager.IsBlending, Is.False);
}
}
}
106 changes: 0 additions & 106 deletions com.unity.cinemachine/Tests/Runtime/EventsTests.cs

This file was deleted.

11 changes: 0 additions & 11 deletions com.unity.cinemachine/Tests/Runtime/EventsTests.cs.meta

This file was deleted.

0 comments on commit e4246bc

Please sign in to comment.