Пример #1
0
    // Use this for initialization
    void Start()
    {
        if (EVENT_MARKER_TYPE == LSL_EVENT_MARKER)
        {
            info   = new liblsl.StreamInfo("Unity_Event_Marker", "Markers", 1, 0, liblsl.channel_format_t.cf_string, "msi");
            outlet = new liblsl.StreamOutlet(info);
        }

        var stimulusManagerObject = GameObject.Find("Stimulus Manager");

        stimulusManager = stimulusManagerObject.GetComponent <StimulusManager>();

        var textUpdaterObject = GameObject.Find("Text Updater");

        textUpdater = textUpdaterObject.GetComponent <TextUpdater>();
        textUpdater.setText("Welcome");

        //Shuffle(conditions);

        orders = new int[TARGET_NUM];
        for (int i = 0; i < TARGET_NUM; ++i)
        {
            orders[i] = i;
        }
        Shuffle(orders);

        state = 5;
    }
Пример #2
0
    private void Socket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender,
                                        Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
    {
        //Debug.Log("GOT MESSAGE FROM: " + args.RemoteAddress.DisplayName);
        //Read the message that was received from the UDP  client.
        Stream       streamIn = args.GetDataStream().AsStreamForRead();
        MemoryStream ms       = ToMemoryStream(streamIn);

        byte[] msgData = ms.ToArray();

        /*
         *  if (ExecuteOnMainThread.Count == 0)
         *  {
         *      ExecuteOnMainThread.Enqueue(() =>
         *      {
         *          Debug.Log("ENQEUED ");
         *          if (udpEvent != null){
         *         Debug.Log("Call udp event.");
         *             udpEvent.Invoke(args.RemoteAddress.DisplayName, internalPort, msgData);
         *      }
         *      });
         *  }
         */

        //string dataString = System.Text.Encoding.UTF8.GetString (msgData);
        string dataString = string.Join(" ", msgData);

        //Debug.Log(dataString);
        if (textUpdater != null)
        {
            //Debug.Log("Set text");
            //textUpdater.setText(dataString);
            textUpdater.setText(msgData[0]);
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        targetTime -= Time.deltaTime;

        if (targetTime <= 0.0f)
        {
            if (waitKeyState == 1)
            {
                if (setTextFlag == true)
                {
                    textUpdater.setText(s);
                    setTextFlag = false;
                }
                if (Input.anyKeyDown)
                {
                    waitKeyState = 0;
                    textUpdater.setText(" ");
                }
            }

            else if (state == 0)
            {
                ++state;
                if (EVENT_MARKER_TYPE == LPT_EVENT_MARKER)
                {
                    ParallelPortManager.Out32_x64(ParallelPortManager.address, 0);
                }

                if (trialCount == TRIAL_PER_BLOCK)
                {
                    if (conditionCount == CONDITION_NUM)
                    {
                        blockCount    += 1;
                        conditionCount = 0;
                        //Shuffle(conditions);
                        Shuffle(orders);

                        if (blockCount == BLOCK_NUM)
                        {
                            Debug.Log(practiceFlag.ToString());
                            if (practiceFlag == true)
                            {
                                CONDITION_NUM   = EXP_CONDITION_NUM;
                                TRIAL_PER_BLOCK = EXP_TRIAL_PER_BLOCK;
                                BLOCK_NUM       = EXP_BLOCK_NUM;
                                trialCount      = TRIAL_PER_BLOCK;

                                practiceFlag = false;
                                waitKeyState = 1;
                                s            = "Experiment Session";
                                setTextFlag  = true;
                                state        = 0;
                            }
                            else
                            {
                                if (parallelFlag == false)
                                {
                                    parallelFlag = true;
                                    state        = 5;
                                }
                                else
                                {
                                    state = 8;
                                }
                            }

                            conditionCount = 0;
                            blockCount     = 0;
                            stimulusManager.StopStimulating();

                            return;
                        }
                    }

                    if (parallelFlag == true)
                    {
                        setStimulus(conditions[conditionCount]);
                    }


                    conditionCount += 1;
                    stimulusManager.StopStimulating();
                    trialCount   = 0;
                    waitKeyState = 1;
                }

                trialCount++;

                trainingTarget = 0;
                targetTime     = 0f;
            }

            else if (state == 1)
            {
                int trainingTargets = orders[trainingTarget];
                if (parallelFlag == false)
                {
                    setSerialStimulus(orders[trainingTarget], conditions[conditionCount - 1]);
                    stimulusManager.GazeShift(0);
                }
                else
                {
                    stimulusManager.GazeShift(trainingTargets);
                }

                if (EVENT_MARKER_TYPE == TCP_EVENT_MARKER)
                {
#if !UNITY_EDITOR
                    Connect();
#endif
                }
                else if (EVENT_MARKER_TYPE == LPT_EVENT_MARKER)
                {
                    ParallelPortManager.Out32_x64(ParallelPortManager.address, 0);
                }

                targetTime = GAZE_SHIFT_LENGTH;
                state      = 2;
            }
            else if (state == 2)
            {
                targetTime = STIM_LENGTH;
                state      = 1;

                if (++trainingTarget == TARGET_NUM)
                {
                    state = 0;
                }

                stimulusManager.StartStimulating();

                if (practiceFlag == false)
                {
                    int eventValue = conditions[conditionCount - 1] * 10 + (orders[trainingTarget - 1] + 1);
                    //Debug.Log(eventValue.ToString());
                    if (EVENT_MARKER_TYPE == TCP_EVENT_MARKER)
                    {
                        byte[] msg = new byte[2];
                        msg[0] = (byte)(orders[trainingTarget - 1] + 1);
                        msg[1] = (byte)(conditions[conditionCount - 1] * 10);
#if !UNITY_EDITOR
                        SendMessage(msg);
#endif
                    }
                    else if (EVENT_MARKER_TYPE == LPT_EVENT_MARKER)
                    {
                        //Debug.Log((conditionCount - 1).ToString());
                        //Debug.Log((trainingTarget - 1).ToString());
                        //Debug.Log("Block: " + (blockCount + 1) + ". Condition: " + conditions[conditionCount - 1] + ". Trial: " + trialCount + ". Target: " + (orders[trainingTarget - 1] + 1));
                        //int eventValue = (blockCount + 1) * 1000 + conditions[conditionCount - 1] * 100 + trialCount * 10 + (orders[trainingTarget - 1] + 1);
                        ParallelPortManager.Out32_x64(ParallelPortManager.address, eventValue);
                    }
                    else if (EVENT_MARKER_TYPE == LSL_EVENT_MARKER)
                    {
                        string[] sample = new string[1];
                        sample[0] = eventValue.ToString();
                        outlet.push_sample(sample);
                    }
                }
            }
            else if (state == 5)
            {
                waitKeyState = 1;
                s            = "Practice Session";
                setTextFlag  = true;
                state        = 6;
            }
            else if (state == 6)
            {
                practiceFlag    = true;
                CONDITION_NUM   = PRAC_CONDITION_NUM;
                TRIAL_PER_BLOCK = PRAC_TRIAL_PER_BLOCK;
                BLOCK_NUM       = PRAC_BLOCK_NUM;

                trialCount = TRIAL_PER_BLOCK;
                state      = 0;
            }
            else if (state == 8)
            {
                waitKeyState = 1;
                s            = "The experiment is over. Thank you!";
                setTextFlag  = true;
                state        = -100;
            }
        }
    }