Home > other >  O solve, realize stroboscopic in Unity
O solve, realize stroboscopic in Unity

Time:09-26

Wants to use Unity to complete SSVEP experiment, precisely through Unity create a Panel, the Panel on the five pictures, want to make each picture flicker, which changed from white to black, then changed from black to white, but is not the same as the picture each blink time, 0.075 ms and 0.066 ms and 0.058 ms... , using multithreading + thread to sleep later found flashing time and the default, could you tell me how to solve this? Language ability is bad, post code, hope the great god directions

Public class TestSSVEP: MonoBehaviour
{
Private List StimulateLists=new List (a);
///& lt; Summary>
///the position of each square, in fact, the four picture
///& lt;/summary>
Public List ImageLists;
///& lt; Summary>
///stroboscopic frequency, flickering stipulated time
///& lt;/summary>
Public List StimulateFrenquencyLists;
Private List ThreadList=new List (a);
Private void the Start ()
{
Initial ();
}

///& lt; Summary>
///initializes the squares, determine the stroboscopic frequency and the position of the corresponding
///& lt;/summary>
Private void Initial ()
{
For (int I=0; I & lt; ImageLists. Count; I++)
{
StimulateInfo stimulate=new StimulateInfo (imageLists [I], stimulateFrenquencyLists [I]);
StimulateLists. Add (stimulate);
}
Foreach (StimulateInfo item in stimulateLists)
{
Thread newThread=new Thread (ChangeColor);
NewThread. Start (item);
ThreadList. Add (newThread);
}
}

///& lt; Summary>
///stroboscopic
///& lt;/summary>
///& lt; Param name="o" & gt;
Private void ChangeColor (object o)
{
# region thread to sleep
As StimulateInfo StimulateInfo stimulate="o.
While (true)
{
//ThreadCrossingHelper is a thread cross access assistant, for use in the main thread UnityAPI
ThreadCrossingHelper. Instance. ExecuteOnMainThread (()=& gt;
{
Stimulate. Img. Color=color. Black;
});
Thread.sleep ((int) (Math. Round (1.0 f/stimulate FlickerFrequency/2, 3) * 1000));
ThreadCrossingHelper. Instance. ExecuteOnMainThread (()=& gt;
{
Stimulate. Img. Color=color. White;
});
Thread.sleep ((int) (Math. Round (1.0 f/stimulate FlickerFrequency/2, 3) * 1000));
}
# endregion
# region coroutines
# endregion
}


Private void OnApplicationQuit ()
{
For (int I=0; I & lt; ThreadList. Count; I++)
{
ThreadList [I]. Abort ();
ImageLists [I]. Color=color. Black;
}
}
}

CodePudding user response:

Code thread. Sleep parameters of the unit is milliseconds yo, even if your code is no problem, the screen refresh rate also failed to keep pace with,
How much is 0.075 ms converted to screen refresh rate?
  • Related