CinemachineFixtureBase.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Cinemachine;
  4. using NUnit.Framework;
  5. using UnityEngine;
  6. namespace Tests.Runtime
  7. {
  8. public class CinemachineFixtureBase
  9. {
  10. readonly List<GameObject> m_GameObjectsToDestroy = new List<GameObject>();
  11. internal GameObject CreateGameObject(string name, params System.Type[] components)
  12. {
  13. var go = new GameObject();
  14. m_GameObjectsToDestroy.Add(go);
  15. go.name = name;
  16. foreach(var c in components)
  17. if (c.IsSubclassOf(typeof(Component)))
  18. go.AddComponent(c);
  19. return go;
  20. }
  21. internal GameObject CreatePrimitive(PrimitiveType type)
  22. {
  23. var go = GameObject.CreatePrimitive(type);
  24. m_GameObjectsToDestroy.Add(go);
  25. return go;
  26. }
  27. [SetUp]
  28. public virtual void SetUp()
  29. {
  30. // force a uniform deltaTime, otherwise tests will be unstable
  31. CinemachineCore.UniformDeltaTimeOverride = 0.1f;
  32. // disable delta time compensation for deterministic test results
  33. CinemachineCore.FrameDeltaCompensationEnabled = false;
  34. }
  35. [TearDown]
  36. public virtual void TearDown()
  37. {
  38. foreach (var go in m_GameObjectsToDestroy)
  39. Object.Destroy(go);
  40. m_GameObjectsToDestroy.Clear();
  41. CinemachineCore.UniformDeltaTimeOverride = -1f;
  42. }
  43. protected static IEnumerator WaitForOnePhysicsFrame()
  44. {
  45. yield return new WaitForFixedUpdate(); // this is needed to ensure physics system is up-to-date
  46. yield return null;
  47. }
  48. }
  49. }