FittsLaw/Assets/Scripts/ExperimentController.cs

118 lines
3.9 KiB
C#
Raw Normal View History

2018-10-14 19:55:46 -04:00
using System;
2018-10-14 23:33:23 -04:00
using System.Collections.Generic;
2018-10-30 19:07:29 -04:00
using System.Diagnostics;
2018-10-14 19:55:46 -04:00
using System.Text;
using UnityEngine;
2018-10-30 19:07:29 -04:00
using UnityEngine.EventSystems;
2018-10-14 19:55:46 -04:00
public class ExperimentController : MonoBehaviour {
GameObject startDot;
GameObject nextDot;
int trialIndex;
int trialDotIndex;
Participant participant;
2018-10-14 23:33:23 -04:00
List<GameObject> dots = new List<GameObject>();
2018-10-30 19:07:29 -04:00
Stopwatch stopwatch = new Stopwatch();
GameObject playerCamera;
2018-10-14 19:55:46 -04:00
// Use this for initialization
void Start () {
//FOR THE LOVE OF GOD FUCKING DELETE THIS, SERIOUSLY CHRIS DON'T YOU DARE FORGET
string fuck = "ewoidHJpYWxzIiA6IFsKICBbIkxlZnRMb25nIiwiUmlnaHRNZWRpdW0iLCJMZWZ0U2hvcnQiLCJVcE1lZGl1bSIsIlVwTG9uZyIsIlJpZ2h0U2hvcnQiXSwKICBbIlVwU2hvcnQiLCJSaWdodExvbmciLCJMZWZ0TWVkaXVtIiwiUmlnaHRNZWRpdW0iLCJMZWZ0TG9uZyIsIlVwTG9uZyJdLAogIFsiUmlnaHRTaG9ydCIsIlVwTWVkaXVtIiwiTGVmdE1lZGl1bSIsIkxlZnRTaG9ydCIsIlJpZ2h0TG9uZyIsIlVwU2hvcnQiXSwKICBbIkxlZnRMb25nIiwiUmlnaHRNZWRpdW0iLCJMZWZ0U2hvcnQiLCJVcE1lZGl1bSIsIlVwTG9uZyIsIlJpZ2h0U2hvcnQiXSwKICBbIlVwU2hvcnQiLCJSaWdodExvbmciLCJMZWZ0TWVkaXVtIiwiUmlnaHRNZWRpdW0iLCJMZWZ0TG9uZyIsIlVwTG9uZyJdLAogIFsiUmlnaHRTaG9ydCIsIlVwTWVkaXVtIiwiTGVmdE1lZGl1bSIsIkxlZnRTaG9ydCIsIlJpZ2h0TG9uZyIsIlVwU2hvcnQiXSwKICBbIkxlZnRMb25nIiwiUmlnaHRNZWRpdW0iLCJMZWZ0U2hvcnQiLCJVcE1lZGl1bSIsIlVwTG9uZyIsIlJpZ2h0U2hvcnQiXSwKICBbIlVwU2hvcnQiLCJSaWdodExvbmciLCJMZWZ0TWVkaXVtIiwiUmlnaHRNZWRpdW0iLCJMZWZ0TG9uZyIsIlVwTG9uZyJdLAogIFsiUmlnaHRTaG9ydCIsIlVwTWVkaXVtIiwiTGVmdE1lZGl1bSIsIkxlZnRTaG9ydCIsIlJpZ2h0TG9uZyIsIlVwU2hvcnQiXQpdLAoicGFydGljaXBhbnRJZCIgOiAxLAoiaW5wdXRNZXRob2QiIDogImNhcmRib2FyZCIKfQo=";
byte[] decodedBytes = Convert.FromBase64String(fuck);
string decodedText = Encoding.UTF8.GetString(decodedBytes);
UnityEngine.Debug.Log(decodedText);
participant = new Participant(decodedText);
startDot = GameObject.Find("StartButton");
2018-10-30 19:07:29 -04:00
playerCamera = GameObject.FindGameObjectsWithTag("MainCamera")[0];
2018-10-14 19:55:46 -04:00
trialIndex = 0;
trialDotIndex = 0;
foreach (GameObject go in GameObject.FindGameObjectsWithTag("Dot"))
{
2018-10-14 23:33:23 -04:00
dots.Add(go);
2018-10-14 19:55:46 -04:00
Hide(go);
};
}
void Hide(GameObject dot)
{
2018-10-14 23:33:23 -04:00
dot.SetActive(false);
2018-10-14 19:55:46 -04:00
}
void Show(GameObject dot)
{
2018-10-14 23:33:23 -04:00
dot.SetActive(true);
2018-10-14 19:55:46 -04:00
}
public void NextDot()
{
2018-10-30 19:07:29 -04:00
if (stopwatch.IsRunning)
{
stopwatch.Stop();
double time = stopwatch.Elapsed.TotalSeconds;
stopwatch.Reset();
}
else
{
stopwatch.Start();
}
2018-10-14 23:33:23 -04:00
nextDot = FindDot(participant.trials[trialIndex][trialDotIndex]);
2018-10-14 19:55:46 -04:00
trialDotIndex++;
Show(nextDot);
Hide(startDot);
}
public void BackToStart()
{
2018-10-30 19:07:29 -04:00
stopwatch.Stop();
double time = stopwatch.Elapsed.TotalSeconds;
stopwatch.Reset();
2018-10-30 19:07:52 -04:00
2018-10-30 19:07:29 -04:00
double angle = Vector3.Angle(nextDot.transform.position, playerCamera.transform.position);
double arcDistance = angle * (float)(Math.PI / 180) * 10;
2018-10-14 19:55:46 -04:00
Hide(nextDot);
Show(startDot);
2018-10-30 19:07:29 -04:00
2018-10-14 19:55:46 -04:00
2018-10-30 19:07:29 -04:00
}
public void CardboardWrapper(GameObject go, PointerEventData eventData)
{
UnityEngine.Debug.Log(eventData.pointerPressRaycast.worldPosition);
if (go != null)
{
UnityEngine.Debug.Log(go.name);
if (go.name == "StartButton")
{
NextDot();
}
else
{
BackToStart();
}
}
else
{
UnityEngine.Debug.Log("Missed");
}
2018-10-14 19:55:46 -04:00
}
// Update is called once per frame
void Update () {
}
2018-10-14 23:33:23 -04:00
GameObject FindDot(string name)
{
foreach(GameObject dot in dots)
{
if (dot.name == name) return dot;
}
return null;
}
2018-10-14 19:55:46 -04:00
}