void BeginTrial(TrialDataModel trialModel) { passTimer = 0f; trialRunning = true; // Load Asteroid asteroidPrefab.GetComponent <Asteroid>().rotation = true; asteroidPrefab.GetComponent <Asteroid>().rotationSpeed = trialModel.AsteroidRotation; asteroidPrefab.GetComponent <Asteroid>().movementSpeedX = trialModel.AsteroidMovementX; asteroidPrefab.GetComponent <Asteroid>().movementSpeedY = trialModel.AsteroidMovementY; asteroidPrefab.GetComponent <Asteroid>().spawnPoint = new Vector3(trialModel.AsteroidSpawnX, trialModel.AsteroidSpawnY, 0); // Load Ship shipPrefab.GetComponent <Ship>().canMove = trialModel.ShipMove; shipPrefab.GetComponent <Ship>().canRotate = trialModel.ShipRotate; shipPrefab.GetComponent <Ship>().maxSpeed = trialModel.ShipMoveSpeed; shipPrefab.GetComponent <Ship>().rotSpeed = trialModel.ShipRotateSpeed; //Instantiate GameObjects AsteroidSpawnVector = new Vector3(trialModel.AsteroidSpawnX, trialModel.AsteroidSpawnY, 0); Vector3 shipSpawnVector = new Vector3(trialModel.ShipSpawnX, trialModel.ShipSpawnY, 0); var createShip = Instantiate(shipPrefab, shipSpawnVector, transform.rotation); createShip.transform.parent = gameObject.transform; BeginPass(); //Instructions.cs starts countdown, when countdown is over, run StartPass() }
void onNextTrial() { try { if (trialQueue.Count == 1) { onLastTrial = true; } trialRunning = false; trialModel = trialQueue.Dequeue(); trialName = trialModel.TrialName; trialText.GetComponent <Text>().text = trialName; } catch (Exception e) { Debug.Log(e); } }
private void parseXML(string xml, string partID) { try { Debug.Log(partID); if (xml != "-1") { invalidAccessCode = false; int trialCount = 1; var doc = new XmlDocument(); doc.LoadXml(xml); XmlNodeList xmlTrials = doc.SelectNodes("/experiment/trial"); foreach (XmlNode xmlTrial in xmlTrials) { string trialName = xmlTrial.Attributes["name"].InnerText; // LOAD XML DOCUMENT XmlNode ship = xmlTrial.SelectSingleNode("ship"); XmlNode asteroid = xmlTrial.SelectSingleNode("asteroid"); // Ship float shipSpawnX = float.Parse(ship.SelectSingleNode("spawn").Attributes["x"].InnerText); float shipSpawnY = float.Parse(ship.SelectSingleNode("spawn").Attributes["y"].InnerText); float shipSpawnZ = float.Parse(ship.SelectSingleNode("spawn").Attributes["z"].InnerText); bool shipCanMove = bool.Parse(ship.Attributes["canMove"].Value); bool shipCanRotate = bool.Parse(ship.Attributes["canRotate"].Value); float shipMoveSpeed = float.Parse(ship.Attributes["moveSpeed"].Value); float shipRotSpeed = float.Parse(ship.Attributes["rotationSpeed"].Value); // Asteroid XmlNode spawnPoint = asteroid.SelectSingleNode("spawn"); float asteroidSpawnX = float.Parse(spawnPoint.Attributes["x"].InnerText); float asteroidSpawnY = float.Parse(spawnPoint.Attributes["y"].InnerText); float asteroidSpawnZ = float.Parse(spawnPoint.Attributes["z"].InnerText); float asteroidMoveX = float.Parse(asteroid.Attributes["movementX"].Value); float asteroidMoveY = float.Parse(asteroid.Attributes["movementY"].Value); float asteroidRotSpeed = float.Parse(asteroid.Attributes["rotationSpeed"].Value); // LOAD DATAMODELS WITH INFORMATION FROM XML // Trial TrialDataModel tempTrial = new TrialDataModel(); tempTrial.TrialName = trialName; // Trial Ship tempTrial.ShipSpawnX = shipSpawnX; tempTrial.ShipSpawnY = shipSpawnY; tempTrial.ShipMove = shipCanMove; tempTrial.ShipRotate = shipCanRotate; tempTrial.ShipMoveSpeed = shipMoveSpeed; tempTrial.ShipRotateSpeed = shipRotSpeed; // Trial Asteroid tempTrial.AsteroidSpawnX = asteroidSpawnX; tempTrial.AsteroidSpawnY = asteroidSpawnY; tempTrial.AsteroidMovementX = asteroidMoveX; tempTrial.AsteroidMovementY = asteroidMoveY; tempTrial.AsteroidRotation = asteroidRotSpeed; tempTrial.ParticipantID = partID; trialCount++; // Add TrialDataModel To List //trialQueue.Enqueue(tempTrial); InputDataHolder.TrialQueue.Enqueue(tempTrial); } } else { invalidAccessCode = true; Debug.Log("Invalid Access Code"); } } catch (XmlException e) { Debug.Log(e.GetType().ToString() + e.Message); } }