Exemplo n.º 1
0
	// Use this for initialization
	void Awake () {
		
		skipTrial = false;
		
		base.Setup(GameManager.SessionType.Star);
		
		//Hide the arrow
		arrow = GameObject.Find("next");
		arrow.SetActive(false);
		
		for(int i=1; i< materials.Length;i++){
			materials[i].color = Color.black;
		}
		
		//Read in the event
		events =  csv.ReadInSession();
		
		//If read in failed, generate basic list of events
		if(events == null){
			
			events = new List<EventStats>();
			
			NeuroLog.Log("Generating Random events");
			
			numTrials = 2;
			
			for(int i =0;i<numTrials;i++){
				StarEvent eS = new StarEvent();
			
				eS.NumLittleStars = 34;
				eS.NumBigStars = 31;
				eS.NumTriangles= 7;
				eS.NumDots= 6;
			
				events.Add(eS);
			}
		}
		else{
			numTrials = events.Count;
		}
		
		//Find the max number of objects we'll need
		int maxTri = 2;
		int maxDot = 2;
		int maxLS = 3;
		int maxBS = 5;
		foreach(StarEvent sE in events){
			if(sE.NumBigStars>maxBS) maxBS = sE.NumBigStars;
			if(sE.NumLittleStars>maxLS) maxLS = sE.NumLittleStars;
			if(sE.NumDots>maxDot) maxDot = sE.NumDots;
			if(sE.NumTriangles>maxTri) maxTri = sE.NumTriangles;
		}
		
		//Have the game generate the maximum amount of objects needed for this session
		generateObjects(maxLS,maxBS,maxDot,maxTri);
		
		//Start the game
		StartCoroutine("runSession");

	}
Exemplo n.º 2
0
    //Generate a practice event
    protected override void generatePractice()
    {
        StarEvent prac = new StarEvent();

        prac.NumLittleStars = 5;
        prac.NumBigStars    = 3;
        prac.NumTriangles   = 2;
        prac.NumDots        = 2;

        practice.Add(prac);
    }
Exemplo n.º 3
0
    //Method used to read in all the trials of the game
    private List<EventStats> ReadStarEvents(XmlNode eventsNode)
    {
        List<EventStats> starEvents = new List<EventStats>();

        //For all the trials
        foreach(XmlNode trial in eventsNode.ChildNodes){

            StarEvent sE = new StarEvent();

            int lS=0;
            int bS=0;
            int d=0;
            int t=0;

            List<StarObject> objs = new List<StarObject>();

            for (int i=0; i<trial.ChildNodes.Count; i++){

                //Make sure were trying to deal with event
                if(trial.ChildNodes[i].Name =="event"){

                    int type = -1;
                    Vector2 pos = new Vector2(Mathf.Infinity,Mathf.Infinity);
                    float rotation = 0;

                    foreach(XmlAttribute attri in trial.ChildNodes[i].Attributes){
                        //Type
                        if(attri.Name.ToLower() == "type"){
                            if(int.TryParse(attri.Value.ToLower(),out type)){
                                if(type <0  && type>3){
                                    NeuroLog.Error("Invalid value for 'type' at event #" + (i+1).ToString() + ". Needs to be between 0 and 4.");
                                    type = -1;
                                }
                                else{
                                    if(type == 0)
                                        lS++;
                                    else if(type ==1)
                                        bS++;
                                    else if(type ==2)
                                        d++;
                                    else if(type ==3)
                                        t++;
                                }
                            }
                            else NeuroLog.Error("Invalid value for 'type' at event #" + (i+1).ToString() + ". Needs to be a int.");
                        }
                        //Position
                        else if(attri.Name.ToLower() =="position"){
                            string[] input = attri.Value.Split(',');

                            float x = Mathf.Infinity;
                            float y = Mathf.Infinity;

                            if(float.TryParse(input[0],out x)){
                                if(x!=Mathf.Infinity){
                                    if(x>170 || x<-170){
                                        x = Mathf.Infinity;
                                        NeuroLog.Error("Invalid value for 'position.x' at event #" + (i+1).ToString() + ". Needs to be between -170 and 170.");
                                    }
                                }
                            }
                            else NeuroLog.Error("Invalid value for 'position.x' at event #" + (i+1).ToString() + ". Needs to be a float.");

                            if(float.TryParse(input[1],out y)){
                                if(y!=Mathf.Infinity){
                                    if(y>90 || y<-75){
                                        y = Mathf.Infinity;
                                        NeuroLog.Error("Invalid value for 'position.y' at event #" + (i+1).ToString() + ". Needs to be between -75 and 90.");
                                    }
                                }
                            }
                            else NeuroLog.Error("Invalid value for 'position.y' at event #" + (i+1).ToString() + ". Needs to be a float.");

                            pos = new Vector2(x,y);
                        }
                        //Rotation
                        else if(attri.Name.ToLower() == "rotation"){
                            if(!float.TryParse(attri.Value.ToLower(),out rotation))
                                NeuroLog.Error("Invalid value for 'rotation' at event #" + (i+1).ToString() + ". Needs to be a float.");
                        }
                        //Other attributes that don't have cases
                        else NeuroLog.Error("Unknown attribute '" + attri.Name + "' at event #" + (i+1).ToString() + ".");
                    }

                    if(type!=-1 && pos.x != Mathf.Infinity && pos.y != Mathf.Infinity){
                        StarObject sO = new StarObject(type,pos,rotation);

                        objs.Add(sO);
                    }
                }
            }

            sE.Objects = objs;

            sE.NumBigStars = bS;
            sE.NumLittleStars=lS;
            sE.NumTriangles = t;
            sE.NumDots = d;

            starEvents.Add(sE);
        }
        return starEvents;
    }
Exemplo n.º 4
0
    // Use this for initialization
    void Awake()
    {
        skipTrial = false;

        base.Setup(GameManager.SessionType.Star);

        //Hide the arrow
        arrow = GameObject.Find("next");
        arrow.SetActive(false);

        for (int i = 1; i < materials.Length; i++)
        {
            materials[i].color = Color.black;
        }

        //Read in the event
        events = csv.ReadInSession();

        //If read in failed, generate basic list of events
        if (events == null)
        {
            events = new List <EventStats>();

            NeuroLog.Log("Generating Random events");

            numTrials = 2;

            for (int i = 0; i < numTrials; i++)
            {
                StarEvent eS = new StarEvent();

                eS.NumLittleStars = 34;
                eS.NumBigStars    = 31;
                eS.NumTriangles   = 7;
                eS.NumDots        = 6;

                events.Add(eS);
            }
        }
        else
        {
            numTrials = events.Count;
        }

        //Find the max number of objects we'll need
        int maxTri = 2;
        int maxDot = 2;
        int maxLS  = 3;
        int maxBS  = 5;

        foreach (StarEvent sE in events)
        {
            if (sE.NumBigStars > maxBS)
            {
                maxBS = sE.NumBigStars;
            }
            if (sE.NumLittleStars > maxLS)
            {
                maxLS = sE.NumLittleStars;
            }
            if (sE.NumDots > maxDot)
            {
                maxDot = sE.NumDots;
            }
            if (sE.NumTriangles > maxTri)
            {
                maxTri = sE.NumTriangles;
            }
        }

        //Have the game generate the maximum amount of objects needed for this session
        generateObjects(maxLS, maxBS, maxDot, maxTri);

        //Start the game
        StartCoroutine("runSession");
    }
Exemplo n.º 5
0
	//Generate a practice event
	protected override void generatePractice(){
		
		StarEvent prac = new StarEvent();
		
		prac.NumLittleStars = 5;
		prac.NumBigStars = 3;
		prac.NumTriangles= 2;
		prac.NumDots= 2;
		
		practice.Add(prac);
	}
Exemplo n.º 6
0
    //Method used to read in all the trials of the game
    private List<EventStats> ReadStarEvents(CsvReader csv)
    {
        List<EventStats> starEvents = new List<EventStats>();

        int fieldCount = csv.FieldCount;

        string[] headers = csv.GetFieldHeaders();

        int i =2;

        StarEvent sE = new StarEvent();

        int lS=0;
        int bS=0;
        int d=0;
        int t=0;

        int block =0;

        List<StarObject> objs = new List<StarObject>();

        while (csv.ReadNextRecord()){
            int type = -1;
            int b=-1;
            Vector2 pos = new Vector2(Mathf.Infinity,Mathf.Infinity);
            float rotation = 0;

            for(int j = 0;j<fieldCount;j++){
                //Type
                if(headers[j].ToLower() == "type"){
                    if(int.TryParse(csv[j].ToLower(),out type)){
                        if(type <0  && type>3){
                            NeuroLog.Log("Invalid value for 'type' at line #" + i.ToString() + ". Needs to be between 0 and 4.");
                            type = -1;
                        }
                        else{
                            if(type == 0)
                                lS++;
                            else if(type ==1)
                                bS++;
                            else if(type ==2)
                                d++;
                            else if(type ==3)
                                t++;
                        }
                    }
                    else NeuroLog.Log("Invalid value for 'type' at line #" + i.ToString() + ". Needs to be a int.");
                }
                //Position
                else if(headers[j].ToLower() =="position"){
                    string[] input = csv[j].Split(';');

                    float x = Mathf.Infinity;
                    float y = Mathf.Infinity;

                    if(float.TryParse(input[0],out x)){
                        if(x!=Mathf.Infinity){
                            if(x>170 || x<-170){
                                x = Mathf.Infinity;
                                NeuroLog.Log("Invalid value for 'position.x' at line #" + i.ToString() + ". Needs to be between -170 and 170.");
                            }
                        }
                    }
                    else NeuroLog.Log("Invalid value for 'position.x' at line #" + i.ToString() + ". Needs to be a float.");

                    if(float.TryParse(input[1],out y)){
                        if(y!=Mathf.Infinity){
                            if(y>90 || y<-75){
                                y = Mathf.Infinity;
                                NeuroLog.Log("Invalid value for 'position.y' at line #" + i.ToString() + ". Needs to be between -75 and 90.");
                            }
                        }
                    }
                    else NeuroLog.Log("Invalid value for 'position.y' at line #" + i.ToString() + ". Needs to be a float.");

                    pos = new Vector2(x,y);
                }
                //Rotation
                else if(headers[j].ToLower() == "rotation"){
                    if(!float.TryParse(csv[j].ToLower(),out rotation))
                        NeuroLog.Log("Invalid value for 'rotation' at line #" + i.ToString() + ". Needs to be a float.");
                }
                //Block Num
                else if (headers[j].ToLower() =="blocknum"){
                    if(int.TryParse(csv[j],out b)){
                        if(block ==0){
                            block = b;
                        }
                        else if(b <block){
                            NeuroLog.Log("Invalid value for 'dot' at line #" + i.ToString() + ". Needs to be greater than "+block +" at this point. Please keep block num's together");
                            b = -1;
                        }
                        else if(b> block+1){
                            NeuroLog.Log("Invalid value for 'dot' at line #" + i.ToString() + ". Needs to be less than "+(block+1).ToString()
                                +" at this point. Do not jump ahead.");
                            b = -1;
                        }
                    }
                    else NeuroLog.Log("Invalid value for 'BlockNum' at line #" + i.ToString() + ". Needs to be a int.");
                }
            }
            if(b != -1){
                if(b != block){

                    block = b;
                    sE.Objects = objs;

                    if(type == 0) lS--;
                    else if(type ==1) bS--;
                    else if(type ==2) d--;
                    else if(type ==3) t--;

                    sE.NumBigStars = bS;
                    sE.NumLittleStars=lS;
                    sE.NumTriangles = t;
                    sE.NumDots = d;

                    starEvents.Add(sE);

                    lS=0;
                    bS=0;
                    d=0;
                    t=0;
                    if(type == 0) lS++;
                    else if(type ==1) bS++;
                    else if(type ==2) d++;
                    else if(type ==3) t++;

                    objs = new List<StarObject>();

                    sE = new StarEvent();
                }

                if(type!=-1 && pos.x != Mathf.Infinity && pos.y != Mathf.Infinity){
                    StarObject sO = new StarObject(type,pos,rotation);

                    objs.Add(sO);
                }
            }

            i++;
        }

        if(objs.Count>0){
            sE.Objects = objs;

            sE.NumBigStars = bS;
            sE.NumLittleStars=lS;
            sE.NumTriangles = t;
            sE.NumDots = d;

            starEvents.Add(sE);
        }

        return starEvents;
    }