308 lines
12 KiB
C#
308 lines
12 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Calibrate : MonoBehaviour {
|
|
|
|
public Camera cam;
|
|
|
|
private int touchCount = 0;
|
|
|
|
private float targetTime = 1.0f;
|
|
|
|
public Text Fingercount;
|
|
|
|
private string game="blinking";
|
|
|
|
public GameObject finger1;
|
|
public GameObject finger2;
|
|
public GameObject finger3;
|
|
public GameObject finger4;
|
|
public GameObject finger5;
|
|
public GameObject finger6;
|
|
public GameObject finger7;
|
|
public GameObject finger8;
|
|
public GameObject finger9;
|
|
public GameObject finger10;
|
|
|
|
private bool logged = false;
|
|
|
|
//private Color color1 = Color.green;
|
|
//private Color color2 = Color.cyan;
|
|
private int counter=1;
|
|
|
|
private Touch[] sortedTouches = new Touch[10];// Input.touches;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
|
|
//Camera.main.aspect = 1536f / 2048f;
|
|
|
|
finger1.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger2.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger3.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger4.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger5.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger6.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger7.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger8.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger9.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger10.GetComponent<SpriteRenderer>().enabled = false;
|
|
|
|
Vector3 pos = cam.ScreenToWorldPoint(finger1.transform.position);
|
|
pos.z = 0.0f;
|
|
finger1.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger2.transform.position);
|
|
pos.z = 0.0f;
|
|
finger2.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger3.transform.position);
|
|
pos.z = 0.0f;
|
|
finger3.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger4.transform.position);
|
|
pos.z = 0.0f;
|
|
finger4.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger5.transform.position);
|
|
pos.z = 0.0f;
|
|
finger5.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger6.transform.position);
|
|
pos.z = 0.0f;
|
|
finger6.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger7.transform.position);
|
|
pos.z = 0.0f;
|
|
finger7.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger8.transform.position);
|
|
pos.z = 0.0f;
|
|
finger8.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger9.transform.position);
|
|
pos.z = 0.0f;
|
|
finger9.transform.position = pos;
|
|
pos = cam.ScreenToWorldPoint(finger10.transform.position);
|
|
pos.z = 0.0f;
|
|
finger10.transform.position = pos;
|
|
|
|
//game = "blinking";
|
|
|
|
}
|
|
|
|
|
|
void timerEnded()
|
|
{
|
|
//do your stuff here.
|
|
sortTouches();
|
|
/*Gamestate.Instance.setTouchPoints(sortedTouches);
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[0].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[1].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[2].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[3].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[4].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[5].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[6].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[7].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[8].position.ToString());
|
|
Debug.Log("cal: " + Gamestate.Instance.getTouchPoints()[9].position.ToString());
|
|
*/
|
|
DontDestroyOnLoad(Gamestate.Instance);
|
|
Gamestate.Instance.startIntro();
|
|
}
|
|
|
|
private void sortTouches()
|
|
{
|
|
List<Touch> touches = new List<Touch>();// Input.touches;
|
|
|
|
touches = Input.touches.OrderBy(t => t.position.y).ToList();
|
|
|
|
Touch t1 = touches[0];
|
|
Touch t2 = touches[1];
|
|
|
|
//Thumbs
|
|
if (t1.position.x < t2.position.x)
|
|
{
|
|
sortedTouches[0] = t2;
|
|
sortedTouches[5] = t1;
|
|
} else
|
|
{
|
|
sortedTouches[0] = t1;
|
|
sortedTouches[5] = t2;
|
|
}
|
|
|
|
touches.RemoveRange(0, 2);
|
|
touches = touches.OrderBy(t => t.position.x).ToList();
|
|
|
|
sortedTouches[9] = touches.First<Touch>();
|
|
touches.RemoveAt(0);
|
|
sortedTouches[8] = touches.First<Touch>();
|
|
touches.RemoveAt(0);
|
|
sortedTouches[7] = touches.First<Touch>();
|
|
touches.RemoveAt(0);
|
|
sortedTouches[6] = touches.First<Touch>();
|
|
touches.RemoveAt(0);
|
|
sortedTouches[4] = touches.First<Touch>();
|
|
touches.RemoveAt(0);
|
|
sortedTouches[3] = touches.First<Touch>();
|
|
touches.RemoveAt(0);
|
|
sortedTouches[2] = touches.First<Touch>();
|
|
touches.RemoveAt(0);
|
|
sortedTouches[1] = touches.First<Touch>();
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
|
|
switch (game)
|
|
{
|
|
case "running":
|
|
if (!logged)
|
|
{
|
|
Debug.Log("running");
|
|
logged = true;
|
|
}
|
|
foreach (Touch touch in Input.touches)
|
|
{
|
|
switch (touch.phase)
|
|
{
|
|
case TouchPhase.Began:
|
|
touchCount += 1;
|
|
Fingercount.text = touchCount.ToString();
|
|
break;
|
|
case TouchPhase.Ended:
|
|
touchCount -= 1;
|
|
Fingercount.text = touchCount.ToString();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (touchCount == 10)
|
|
{
|
|
targetTime -= Time.deltaTime;
|
|
|
|
if (targetTime <= 0.0f)
|
|
{
|
|
timerEnded();
|
|
}
|
|
|
|
}
|
|
break;
|
|
|
|
case "blinking":
|
|
|
|
targetTime -= Time.deltaTime;
|
|
|
|
//float t = Mathf.PingPong(Time.time, duration) / duration;
|
|
//cam.backgroundColor = Color.Lerp(color1, color2, t);
|
|
|
|
if (targetTime <= 0.0f)
|
|
{
|
|
Debug.Log("targetTime: " + targetTime.ToString());
|
|
Debug.Log("Time.deltaTime: " + Time.deltaTime.ToString());
|
|
Debug.Log("counter: "+counter.ToString());
|
|
|
|
switch (counter)
|
|
{
|
|
case 1:
|
|
finger1.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 2;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 2:
|
|
finger2.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 3;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 3:
|
|
finger3.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 4;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 4:
|
|
finger4.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 5;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 5:
|
|
finger5.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 6;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 6:
|
|
finger6.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 7;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 7:
|
|
finger7.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 8;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 8:
|
|
finger8.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 9;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 9:
|
|
finger9.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 10;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 10:
|
|
finger10.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 11;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 11:
|
|
finger1.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger2.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger3.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger4.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger5.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger6.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger7.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger8.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger9.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger10.GetComponent<SpriteRenderer>().enabled = false;
|
|
counter = 12;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 12:
|
|
finger1.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger2.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger3.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger4.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger5.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger6.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger7.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger8.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger9.GetComponent<SpriteRenderer>().enabled = true;
|
|
finger10.GetComponent<SpriteRenderer>().enabled = true;
|
|
counter = 13;
|
|
targetTime = 0.5f;
|
|
break;
|
|
case 13:
|
|
finger1.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger2.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger3.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger4.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger5.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger6.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger7.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger8.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger9.GetComponent<SpriteRenderer>().enabled = false;
|
|
finger10.GetComponent<SpriteRenderer>().enabled = false;
|
|
targetTime = 2.0f;
|
|
game = "running";
|
|
break;
|
|
|
|
}
|
|
}
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|