private MockScreenInput MockInputA() { MockScreenInput mock = new MockScreenInput(); mock.Frames = new List <MockScreenInput.Frame>(); mock.Frames.Add(new MockScreenInput.Frame(0f, Vector3.zero, false)); mock.Frames.Add(new MockScreenInput.Frame(1f, Vector3.one, false)); return(mock); }
public void StartPlayBack() { if (_playing) { Debug.LogWarning("Already in playback"); return; } _playing = true; MockScreenInput data = new MockScreenInput(); data.Frames = _recorder.RecordedKeyFrames(); Debug.LogFormat("Start Playback with {0} frames", data.Frames.Count); _screenInputService.SetDriver(_playbackRunner, true); _playbackRunner.PlayInput(data, PlayBackComplete, Time.time); }
//NOTE: This test requires the "ExampleScene" is added to your 'Scenes In Build' //Loads the example scene, simulates clicking on each element, checks the click-counts match public IEnumerator TestExampleScene() { SceneManager.LoadScene("ExampleScene"); yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); ClickableExample[] clickables = GameObject.FindObjectsOfType <ClickableExample>(); Assert.AreNotEqual(0, clickables.Length); MockScreenInput mockInput = new MockScreenInput(); mockInput.Frames = new List <MockScreenInput.Frame>(); mockInput.Frames.Add(new MockScreenInput.Frame(0f, Vector3.zero, false)); foreach (ClickableExample clickable in clickables) { ClickCounter counter = clickable.GetComponent <ClickCounter>(); Assert.AreEqual(0, counter.ClickCount); Vector3 pos = Camera.main.WorldToScreenPoint(clickable.transform.position); float time = mockInput.Frames.Last().Time + 0.1f; mockInput.Frames.Add(new MockScreenInput.Frame(time, pos, false)); mockInput.Frames.Add(new MockScreenInput.Frame(time + 0.1f, pos, true)); mockInput.Frames.Add(new MockScreenInput.Frame(time + 0.2f, pos, false)); } Button button = GameObject.FindObjectOfType <Button>(); Assert.AreNotEqual(null, button); float timeB = mockInput.Frames.Last().Time + 0.1f; mockInput.Frames.Add(new MockScreenInput.Frame(timeB, button.transform.position, false)); mockInput.Frames.Add(new MockScreenInput.Frame(timeB + 0.1f, button.transform.position, true)); mockInput.Frames.Add(new MockScreenInput.Frame(timeB + 0.2f, button.transform.position, false)); TestHelper test = new TestHelper(mockInput); yield return(test.RunToEndInPlay()); foreach (ClickableExample clickable in clickables) { Assert.AreEqual(1, clickable.GetComponent <ClickCounter>().ClickCount); } Assert.AreEqual(1, button.GetComponent <ClickCounter>().ClickCount); }
public IEnumerator InputService_ClicksOnClickable_CountGoesUp() { Camera camera = new GameObject().AddComponent <Camera>(); camera.transform.position = new Vector3(0f, 1f, -10f); GameObject go = new GameObject(); go.AddComponent <BoxCollider>(); TestClickable clickable = go.AddComponent <TestClickable>(); clickable.transform.position = camera.ScreenToWorldPoint(Vector3.one); TestCounter counter = new TestCounter(); clickable.Clicked += counter.Increment; Assert.AreEqual(0, counter.Count); //wait for Unity to fully create and init the objects yield return(new WaitForEndOfFrame()); MockScreenInput mockInput = new MockScreenInput(); mockInput.Frames = new List <MockScreenInput.Frame>(); mockInput.Frames.Add(new MockScreenInput.Frame(0f, Vector3.zero, false)); mockInput.Frames.Add(new MockScreenInput.Frame(0.1f, Vector3.one, false)); mockInput.Frames.Add(new MockScreenInput.Frame(0.2f, Vector3.one, true)); mockInput.Frames.Add(new MockScreenInput.Frame(0.3f, Vector3.one, false)); TestHelper test = new TestHelper(mockInput); yield return(test.RunToEndInPlay()); Assert.AreEqual(1, counter.Count); //cleanup GameObject.Destroy(camera.gameObject); GameObject.Destroy(go); }
public TestHelper(MockScreenInput data) { Data = data; }