Commit 4a2fb1ab authored by Ru Cindrea's avatar Ru Cindrea

Merge branch '175-joystick-controls' into 'master'

Resolve "Joystick controls"

Closes #175

See merge request altom/altunitytester!102
parents 70ba19c7 6e95f86e
fileFormatVersion: 2
guid: 875f18258bda64f788e2a3e64f4d84bb
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android
second:
enabled: 1
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bec1d057034494faf895751748c3b26f
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android
second:
enabled: 1
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 219f3730c9359437d9409c91141778e7
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android
second:
enabled: 1
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d73d7313e8a2e4b0e8e29701095743f9
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android
second:
enabled: 1
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:
......@@ -263,7 +263,7 @@ public class AltUnityDriver {
sleepFor(durationInSecs );
String data;
do {
send(CreateCommand("swipeFinished"));
send(CreateCommand("actionFinished"));
data = recvall();
} while (data.equals("No"));
......@@ -300,16 +300,16 @@ public class AltUnityDriver {
}
handleErrors(data);
}
public void pressKey(String keyName, float duration){
send(CreateCommand("pressKeyboardKey", keyName,String.valueOf(duration)));
public void pressKey(String keyName,float power, float duration){
send(CreateCommand("pressKeyboardKey", keyName,String.valueOf(power),String.valueOf(duration)));
String data = recvall();
if (!data.contains("error:")) {
return;
}
handleErrors(data);
}
public void pressKeyAndWait(String keyName, float duration) {
pressKey(keyName, duration);
public void pressKeyAndWait(String keyName,float power, float duration) {
pressKey(keyName,power, duration);
sleepFor(duration );
String data;
do {
......
package ro.altom.altunitytester;
import com.sun.javafx.geom.Vec3f;
import javafx.scene.input.KeyCode;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
......@@ -24,6 +27,7 @@ public class TestSampleScene5 {
@AfterClass
public static void tearDown() throws Exception {
altUnityDriver.stop();
Thread.sleep(1000);
}
@Before
......@@ -45,10 +49,10 @@ public class TestSampleScene5 {
AltUnityObject cube = altUnityDriver.findElement("Player1");
Vec3f cubeInitialPostion = new Vec3f(cube.worldX, cube.worldY, cube.worldY);
altUnityDriver.scrollMouse(30, 20);
altUnityDriver.pressKey("K", 2);
altUnityDriver.pressKey("K",1, 2);
Thread.sleep(2000);
cube = altUnityDriver.findElement("Player1");
altUnityDriver.pressKeyAndWait("O", 1);
altUnityDriver.pressKeyAndWait("O",1, 1);
Vec3f cubeFinalPosition = new Vec3f(cube.worldX, cube.worldY, cube.worldY);
......@@ -66,7 +70,7 @@ public class TestSampleScene5 {
AltUnityObject cube = altUnityDriver.findElement("Player1");
Vec3f cubeInitialPostion = new Vec3f(cube.worldX, cube.worldY, cube.worldY);
altUnityDriver.pressKey("W", 2);
altUnityDriver.pressKey("W",1, 2);
Thread.sleep(2000);
cube = altUnityDriver.findElement("Player1");
Vec3f cubeFinalPosition = new Vec3f(cube.worldX, cube.worldY, cube.worldY);
......@@ -86,14 +90,36 @@ public class TestSampleScene5 {
altUnityDriver.moveMouse(800, 400, 1);
Thread.sleep(1500);
altUnityDriver.pressKey("Mouse0", 1);
altUnityDriver.pressKey("Mouse0",1, 1);
altUnityDriver.moveMouseAndWait(800, 200, 1);
altUnityDriver.pressKeyAndWait("Mouse0", 1);
altUnityDriver.pressKeyAndWait("Mouse0",1, 1);
stars = altUnityDriver.findElementsWhereNameContains("Star");
assertEquals(4, stars.length);
assertEquals(3, stars.length);
}
@Test
public void TestPowerJoystick()
{
ArrayList<String> ButtonNames = new ArrayList<String>();
ButtonNames.add("Horizontal");
ButtonNames.add("Vertical");
ArrayList<String> KeyToPressForButtons = new ArrayList<>();
KeyToPressForButtons.add("D");
KeyToPressForButtons.add("W");
altUnityDriver.loadScene("Scene 5 Keyboard Input");
AltUnityObject axisName = altUnityDriver.findElement("AxisName");
AltUnityObject axisValue = altUnityDriver.findElement("AxisValue");
int i = 0;
for (String key : KeyToPressForButtons)
{
altUnityDriver.pressKeyAndWait(key,0.5f,0.1f);
assertEquals("0.5", axisValue.getText());
assertEquals(ButtonNames.get(i), axisName.getText());
i++;
}
}
}
......@@ -23,6 +23,7 @@ public class TestsSampleScene1 {
@AfterClass
public static void tearDown() throws Exception {
altUnityDriver.stop();
Thread.sleep(1000);
}
@Before
......@@ -476,7 +477,8 @@ public void TestCallStaticMethod() throws Exception {
public void TestGetSetTimeScale(){
altUnityDriver.setTimeScale(0.1f);
float timeScale = altUnityDriver.getTimeScale();
assertEquals(0.1f, timeScale);
assertEquals(0.1f, timeScale,0f);
altUnityDriver.setTimeScale(1f);
}
}
......@@ -23,6 +23,7 @@ public class TestsSampleScene2 {
@AfterClass
public static void tearDown() throws Exception {
altUnityDriver.stop();
Thread.sleep(1000);
}
@Before
......
......@@ -21,6 +21,7 @@ public class TestsSampleScene3 {
@AfterClass
public static void tearDown() throws Exception {
altUnityDriver.stop();
Thread.sleep(1000);
}
@Before
......
......@@ -354,13 +354,13 @@ class AltrunUnityDriver(object):
data = self.send_data(self.create_command('tilt', acceleration ))
return self.handle_errors(data)
def press_key(self, keyName,duration):
def press_key(self, keyName,power=1,duration=1):
print ('Press key: ' + keyName)
data = self.send_data(self.create_command('pressKeyboardKey', keyName, duration ))
data = self.send_data(self.create_command('pressKeyboardKey',keyName,power, duration ))
return self.handle_errors(data)
def press_key_and_wait(self,keyName,duration):
data = self.press_key(keyName,duration)
def press_key_and_wait(self,keyName,power=1,duration=1):
data = self.press_key(keyName,power,duration)
self.handle_errors(data)
print('Wait for press key to finish')
time.sleep(duration)
......
......@@ -254,10 +254,10 @@ class PythonTests(unittest.TestCase):
cube = self.altdriver.find_element("Player1")
cubeInitialPostion = (cube.worldX, cube.worldY, cube.worldY)
self.altdriver.scroll_mouse(30, 1)
self.altdriver.press_key('K', 2)
self.altdriver.press_key('K',1, 2)
time.sleep(2)
cube = self.altdriver.find_element("Player1")
self.altdriver.press_key_and_wait('O', 1)
self.altdriver.press_key_and_wait('O',1, 1)
cubeFinalPosition = (cube.worldX, cube.worldY, cube.worldY)
self.assertNotEqual(cubeInitialPostion, cubeFinalPosition)
......@@ -269,7 +269,7 @@ class PythonTests(unittest.TestCase):
cube = self.altdriver.find_element("Player1")
cubeInitialPostion =(cube.worldX, cube.worldY, cube.worldY)
self.altdriver.press_key('W', 2)
self.altdriver.press_key('W',1, 2)
time.sleep(2)
cube = self.altdriver.find_element("Player1")
cubeFinalPosition =(cube.worldX, cube.worldY, cube.worldY)
......@@ -281,17 +281,31 @@ class PythonTests(unittest.TestCase):
stars = self.altdriver.find_elements_where_name_contains("Star","Player2")
self.assertEqual(1, len(stars))
player = self.altdriver.find_elements_where_name_contains("Player","Player2")
self.altdriver.move_mouse(int(stars[0].x),int(stars[0].y)+100, 1)
self.altdriver.move_mouse(int(stars[0].x),int(player[0].y)+500, 1)
time.sleep(1.5)
self.altdriver.press_key('Mouse0', 0)
self.altdriver.move_mouse_and_wait(int(stars[0].x),int(stars[0].y)-100, 1)
self.altdriver.press_key('Mouse0', 0)
self.altdriver.press_key('Mouse0', 1,0)
self.altdriver.move_mouse_and_wait(int(stars[0].x),int(player[0].y)-500, 1)
self.altdriver.press_key('Mouse0', 1,0)
stars = self.altdriver.find_elements_where_name_contains("Star")
self.assertEqual(3, len(stars))
def test_power_joystick(self):
button_names=['Horizontal','Vertical']
keys_to_press=['D','W']
self.altdriver.load_scene("Scene 5 Keyboard Input")
axisName = self.altdriver.find_element("AxisName")
axisValue = self.altdriver.find_element("AxisValue")
i = 0
for key in keys_to_press:
self.altdriver.press_key_and_wait(key,0.5, 0.1)
self.assertEqual('0.5', axisValue.get_text())
self.assertEqual(button_names[i], axisName.get_text())
i=i+1
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(PythonTests)
result = unittest.TextTestRunner(verbosity=2).run(suite)
......
......@@ -9,46 +9,45 @@ Prefab:
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1108575978661420}
m_RootGameObject: {fileID: 1768235295843564}
m_IsPrefabParent: 1
--- !u!1 &1108575978661420
--- !u!1 &1768235295843564
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4846072577023442}
- component: {fileID: 33689772339675380}
- component: {fileID: 23307282478673166}
- component: {fileID: 114547691594838158}
- component: {fileID: 64420025417565984}
- component: {fileID: 4209538840206634}
- component: {fileID: 33226856824416228}
- component: {fileID: 23501760235078744}
- component: {fileID: 114927286709782638}
m_Layer: 0
m_Name: Star 1
m_Name: Star
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4846072577023442
--- !u!4 &4209538840206634
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1108575978661420}
m_LocalRotation: {x: 0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1.04, y: -0.85, z: -2.4527688}
m_GameObject: {fileID: 1768235295843564}
m_LocalRotation: {x: 0.000000021855694, y: 0, z: -0, w: 1}
m_LocalPosition: {x: -2.39, y: -0.18, z: -0}
m_LocalScale: {x: 50, y: 50, z: 50}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &23307282478673166
--- !u!23 &23501760235078744
MeshRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1108575978661420}
m_GameObject: {fileID: 1768235295843564}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
......@@ -78,35 +77,22 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &33689772339675380
--- !u!33 &33226856824416228
MeshFilter:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1108575978661420}
m_GameObject: {fileID: 1768235295843564}
m_Mesh: {fileID: 4300000, guid: cfecc298235aa6e44b7fc60d0ad69593, type: 3}
--- !u!64 &64420025417565984
MeshCollider:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1108575978661420}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 3
m_Convex: 0
m_CookingOptions: 14
m_SkinWidth: 0.01
m_Mesh: {fileID: 4300000, guid: cfecc298235aa6e44b7fc60d0ad69593, type: 3}
--- !u!114 &114547691594838158
--- !u!114 &114927286709782638
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1108575978661420}
m_GameObject: {fileID: 1768235295843564}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a5993bee904a8d544919c74378e40e17, type: 3}
m_Name:
m_EditorClassIdentifier:
starCounter: {fileID: 0}
fileFormatVersion: 2
guid: 93fc2ca8e4355e44e88baaec8f062e4b
guid: 498075f2b42d9bd4f8b5887858ff68ef
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
......
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DebugController : MonoBehaviour
{
public Text lastKeyDown;
public Text lastKeyUp;
public Text lastKeyPressed;
public Text lastButtonDown;
public Text lastButtonUp;
public Text lastButtonPressed;
public Text mousePosition;
public Text scroll;
public Text lastAxis;
public Text lastAxisValue;
private void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.anyKeyDown)
{
foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKeyDown(kcode))
lastKeyDown.text=kcode.ToString();
}
}
if (Input.anyKey)
{
foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKey(kcode))
lastKeyPressed.text = kcode.ToString();
}
}
foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKeyUp(kcode))
lastKeyUp.text = kcode.ToString();
}
#if ALTUNITYTESTER
lastButtonDown.text = Input.LastButtonDown;
lastButtonPressed.text = Input.LastButtonPressed;
lastButtonUp.text = Input.LastButtonUp;
lastAxis.text = Input.LastAxisName;
lastAxisValue.text = Input.LastAxisValue.ToString();
#endif
mousePosition.text = Input.mousePosition.ToString();
scroll.text = Input.mouseScrollDelta.ToString();
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 971539f6b29d5874f85765f6b0203a79
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,6 +5,7 @@ using UnityEngine;
public class GameLogicController : MonoBehaviour {
public GameObject starPrefab;
public Camera camera;
public StarCounter starCounter;
// Use this for initialization
void Start () {
......@@ -22,9 +23,11 @@ public class GameLogicController : MonoBehaviour {
{
if (hit.transform.gameObject.name == "Floor")
{
starCounter.UpdateStarCounter(true);
var position = hit.point;
position.y += 1;
Instantiate(starPrefab, position, Quaternion.identity);
var star=Instantiate(starPrefab, position, Quaternion.identity);
star.GetComponent<StarController>().starCounter = starCounter;
}
}
......
......@@ -22,5 +22,15 @@ public class Player2Controller : MonoBehaviour {
movement.z = -1 * speed * Time.deltaTime + Input.mouseScrollDelta.y;
transform.position += movement;
if (Input.GetButton("Horizontal"))
{
Debug.Log("HorizontalPressed");
}
if (Input.GetButtonDown("Vertical"))
{
Debug.Log("VerticalPressed");
}
}
}
......@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
public class StarController : MonoBehaviour {
public StarCounter starCounter;
// Use this for initialization
void Start () {
......@@ -18,7 +18,7 @@ public class StarController : MonoBehaviour {
{
if (collision.gameObject.name == "Player1")
{
starCounter.UpdateStarCounter(false);
Destroy(gameObject);
}
}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StarCounter : MonoBehaviour
{
public UnityEngine.UI.Text text;
int stars = 1;
int starsCollected = 0;
private void Start()
{
stars = GameObject.FindGameObjectsWithTag("Star").Length;
text.text = starsCollected + "/" + stars;
}
public void UpdateStarCounter(bool created)
{
if (created)
{
stars++;
}
else
{
starsCollected++;
}
text.text = starsCollected + "/" + stars;
}