-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptomotor_task1.cs
More file actions
116 lines (90 loc) · 3.38 KB
/
Copy pathoptomotor_task1.cs
File metadata and controls
116 lines (90 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class optomotor_task1 : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 0f;
// float duration = 60f;
public Material SphereMaterial;
public bool cylinder_material;
float time;
public float time_1 = 0f;
public float time_task;
public float nextActionTime = 0.0f;
public float nextActionTime_1 = 0.0f;
public float period_grat = 2.0f;//how long grating go
public float period_gray = 4.0f;//how long grating go
public int repeats_num = 0; //from 0 to 9 and reset
public int grating_num = 0;//from 0 to 7 no rest
public int trial_num = 0;//from 0 to 69 no reset
private int[] turn_order = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
public EventLogger eventLogger;
private string[] materials = { "1_deg", "2_deg", "4_deg", "6_deg", "8_deg", "12_deg", "24_deg" };
private float[] freq_speed = { 1.0f, 2.0f, 4.0f, 6.0f, 8.0f, 12.0f, 24.0f };
private int[] material_order = { 0, 1, 2, 3, 4, 5, 6, 7 };
int[,] order_array = new int[7, 10];
void Start()
{
SphereMaterial = Resources.Load<Material>("Materials/gray");
MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
meshRenderer.material = SphereMaterial;
for (int i = 0; i < 7; i++)
{
turn_order.Shuffle();
for (int j = 0; j< 10; j++)
{
order_array[i,j] = turn_order[j];
}
}
material_order.Shuffle();//sudorandom
}
// Update is called once per frame
void Update()
{
time_1 += Time.deltaTime;
time_task = Time.time;
if (time_1 > nextActionTime)
{
nextActionTime += period_grat+period_gray;
if (time_1 > nextActionTime_1)
{
nextActionTime_1 = nextActionTime + period_grat;
// execute block of code here
speed = 1.50f*freq_speed[material_order[grating_num]]* order_array[grating_num, repeats_num];
SphereMaterial = Resources.Load<Material>("Materials/"+materials[material_order[grating_num]]);
MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
meshRenderer.material = SphereMaterial;
if (grating_num < 7)
{
grating_num++;
}
else
{
grating_num= 0;
repeats_num++;
material_order.Shuffle();
}
}
else
{
SphereMaterial = Resources.Load<Material>("Materials/gray");
MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
meshRenderer.material = SphereMaterial;
speed =0f;
trial_num++;
}
}
if (trial_num>69)
{
Application.Quit();
}
else if (time_task > 900f)
{
Application.Quit();
}
transform.Rotate(0f, 0f, Time.deltaTime * speed);
eventLogger.Add(new Event("grating_wavelength", material_order[grating_num]));
eventLogger.Add(new Event("grating_direction", speed));
}
}