Esempio n. 1
0
    // Token: 0x060041AA RID: 16810 RVA: 0x0014CDD4 File Offset: 0x0014B1D4
    private void CreateButton(int id, Vector3 position)
    {
        PlaneObject planeObject = PlaneObject.Create(0.67f, 0.67f, 2, 2);

        planeObject.gameObject.GetComponent <MeshRenderer>().sharedMaterial.color = new Color(1f, 1f, 1f, 1f);
        BoxCollider boxCollider = planeObject.gameObject.AddComponent <BoxCollider>();

        boxCollider.isTrigger = true;
        planeObject.gameObject.transform.position = position;
        ButtonTrigger buttonTrigger = planeObject.gameObject.AddComponent <ButtonTrigger>();

        buttonTrigger.ID = id;
        this.buttons.Add(planeObject.gameObject);
        switch (id)
        {
        case 0:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/triangle") as Texture2D);
            break;

        case 1:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/plane") as Texture2D);
            break;

        case 2:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/circle") as Texture2D);
            break;

        case 3:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/ellipse") as Texture2D);
            break;

        case 4:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/ring") as Texture2D);
            break;

        case 5:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/box") as Texture2D);
            break;

        case 6:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/cylinder") as Texture2D);
            break;

        case 7:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/cone") as Texture2D);
            break;

        case 8:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/sphere") as Texture2D);
            break;

        case 9:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/ellipsoid") as Texture2D);
            break;

        case 10:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/pyramid") as Texture2D);
            break;

        case 11:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/geosphere") as Texture2D);
            break;

        case 12:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/tube") as Texture2D);
            break;

        case 13:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/capsule") as Texture2D);
            break;

        case 14:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/roundedBox") as Texture2D);
            break;

        case 15:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/torus") as Texture2D);
            break;

        case 16:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/torusKnot") as Texture2D);
            break;

        case 17:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/arc") as Texture2D);
            break;

        case 18:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/sphericalcone") as Texture2D);
            break;

        case 19:
            planeObject.gameObject.GetComponent <Renderer>().material             = new Material(Shader.Find("Unlit/Transparent"));
            planeObject.gameObject.GetComponent <Renderer>().material.mainTexture = this.GetTexture(Resources.Load("icons/superellipsoid") as Texture2D);
            break;
        }
        if (planeObject)
        {
            planeObject.gameObject.transform.position = position + new Vector3(0f, 0.1f, 0f);
        }
    }
Esempio n. 2
0
    // Token: 0x060041A6 RID: 16806 RVA: 0x0014C3B4 File Offset: 0x0014A7B4
    public void OnButtonHit(int id)
    {
        this.animTimeout = this.animTimeMax;
        BaseObject baseObject = null;

        switch (id)
        {
        case 0:
        {
            baseObject = Triangle.Create(1f, 0);
            float[] array = new float[6];
            array[0]            = 4f;
            array[1]            = 4f;
            this.shapeParamsMax = array;
            float[] array2 = new float[6];
            array2[0]             = 1f;
            array2[1]             = 1f;
            this.shapeParamsStart = array2;
            break;
        }

        case 1:
            baseObject          = PlaneObject.Create(1f, 1f, 1, 1);
            this.shapeParamsMax = new float[]
            {
                4f,
                4f,
                1f,
                1f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                1f,
                1f,
                1f,
                0f,
                0f
            };
            break;

        case 2:
        {
            baseObject = Circle.Create(1f, 3);
            float[] array3 = new float[6];
            array3[0]           = 2.5f;
            array3[1]           = 40f;
            this.shapeParamsMax = array3;
            float[] array4 = new float[6];
            array4[0]             = 1f;
            array4[1]             = 3f;
            this.shapeParamsStart = array4;
            break;
        }

        case 3:
            baseObject          = Ellipse.Create(1f, 0.5f, 3);
            this.shapeParamsMax = new float[]
            {
                2.5f,
                1.2f,
                40f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                0.5f,
                3f,
                0f,
                0f,
                0f
            };
            break;

        case 4:
            baseObject          = Ring.Create(0.5f, 1f, 3);
            this.shapeParamsMax = new float[]
            {
                1f,
                2.5f,
                40f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                0.5f,
                1f,
                3f,
                0f,
                0f,
                0f
            };
            break;

        case 5:
            baseObject          = Box.Create(1f, 1f, 1f, 1, 1, 1, false, null, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                2.5f,
                2.5f,
                2.5f,
                1f,
                1f,
                1f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                1f,
                1f,
                1f,
                1f,
                1f
            };
            break;

        case 6:
            baseObject          = Cylinder.Create(1f, 3f, 3, 1, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                1.25f,
                4f,
                40f,
                1f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                3f,
                3f,
                1f,
                0f,
                0f,
                0f
            };
            break;

        case 7:
            baseObject          = Cone.Create(1f, 0f, 0f, 2f, 3, 10, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                1.25f,
                0f,
                4f,
                40f,
                10f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                1f,
                2f,
                3f,
                10f,
                0f,
                0f
            };
            break;

        case 8:
        {
            baseObject = Sphere.Create(1f, 4, 0f, 0f, 0f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            float[] array5 = new float[6];
            array5[0]           = 2.25f;
            array5[1]           = 40f;
            this.shapeParamsMax = array5;
            float[] array6 = new float[6];
            array6[0]             = 1f;
            array6[1]             = 4f;
            this.shapeParamsStart = array6;
            break;
        }

        case 9:
            baseObject          = Ellipsoid.Create(1f, 1f, 1f, 4, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                1.25f,
                2.45f,
                2.5f,
                40f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                1f,
                1f,
                4f,
                0f,
                0f,
                0f
            };
            break;

        case 10:
            baseObject          = Pyramid.Create(1f, 1f, 1f, 1, 1, 1, false, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                2.7f,
                2.7f,
                1.7f,
                1f,
                1f,
                1f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                1f,
                1f,
                1f,
                1f,
                1f,
                0f,
                0f,
                0f
            };
            break;

        case 11:
        {
            baseObject = GeoSphere.Create(1f, 0, GeoSpherePrimitive.BaseType.Icosahedron, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            float[] array7 = new float[6];
            array7[0]           = 2.45f;
            array7[1]           = 4f;
            this.shapeParamsMax = array7;
            float[] array8 = new float[6];
            array8[0]             = 1f;
            this.shapeParamsStart = array8;
            break;
        }

        case 12:
            baseObject          = Tube.Create(0.8f, 1f, 1f, 3, 1, 0f, false, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                0.8f,
                1.5f,
                4f,
                40f,
                0f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                0.8f,
                1f,
                1f,
                3f,
                0f,
                0f,
                0f,
                0f
            };
            break;

        case 13:
            baseObject          = Capsule.Create(1f, 1f, 4, 1, false, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                1.2f,
                4f,
                40f,
                1f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                1f,
                4f,
                1f,
                0f,
                0f,
                0f
            };
            break;

        case 14:
            baseObject          = RoundedCube.Create(1f, 1f, 1f, 1, 0.2f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                1.6f,
                1.6f,
                1.6f,
                20f,
                0.6f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                1f,
                1f,
                1f,
                0.2f,
                0f,
                0f,
                0f
            };
            break;

        case 15:
            baseObject          = Torus.Create(1f, 0.5f, 4, 4, 0f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                1.6f,
                0.8f,
                40f,
                40f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                0.5f,
                4f,
                4f,
                0f,
                0f,
                0f
            };
            break;

        case 16:
            baseObject          = TorusKnot.Create(0.5f, 0.3f, 10, 4, 2, 3, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                1f,
                0.5f,
                120f,
                40f,
                2f,
                3f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                0.5f,
                0.3f,
                10f,
                4f,
                2f,
                3f,
                0f,
                0f,
                0f
            };
            break;

        case 17:
            baseObject = Arc.Create(1f, 1f, 1f, 1f, 10, PivotPosition.Botttom);
            ((Arc)baseObject).gizmo.gameObject.transform.localPosition = new Vector3(-1f, -1f, 0f);
            this.shapeParamsMax = new float[]
            {
                4f,
                3f,
                2f,
                1f,
                20f,
                -1f
            };
            this.shapeParamsStart = new float[]
            {
                0.5f,
                0.5f,
                0.1f,
                0.5f,
                0f,
                0f
            };
            break;

        case 18:
            baseObject          = SphericalCone.Create(1f, 20, 180f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                2f,
                40f,
                20f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                1f,
                20f,
                360f,
                0f,
                0f,
                0f
            };
            break;

        case 19:
            baseObject          = SuperEllipsoid.Create(1f, 1f, 1f, 20, 0.5f, 1f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom);
            this.shapeParamsMax = new float[]
            {
                2f,
                2f,
                2f,
                20f,
                0.5f,
                1f,
                0f,
                0f,
                0f
            };
            this.shapeParamsStart = new float[]
            {
                0.5f,
                0.5f,
                0.5f,
                1f,
                0f,
                0f,
                0f,
                0f,
                0f
            };
            break;

        case 20:
            this.textureToggle = !this.textureToggle;
            break;

        case 21:
            this.flatNormals = !this.flatNormals;
            break;
        }
        if (baseObject)
        {
            if (this.shapeOld)
            {
                UnityEngine.Object.Destroy(this.shapeOld.gameObject);
            }
            this.shapeOld  = this.shapeMain;
            this.shapeMain = baseObject;
            this.shapeMain.gameObject.GetComponent <Renderer>().material = new Material(this.GetSpecularShader());
            this.shapeMain.gameObject.GetComponent <Renderer>().material.SetColor("_Color", new Color(1f, 0.7058824f, 0.7058824f));
            this.shapeMain.gameObject.GetComponent <Renderer>().material.SetColor("_SpecColor", Color.white);
            this.shapeMain.gameObject.transform.position = this.prevPosition.position;
            this.nextShowTimeout = this.nextShowTimeoutMax;
            this.shapeID         = id;
        }
        if (this.textureToggle)
        {
            this.shapeMain.GetComponent <MeshRenderer>().sharedMaterial = (Resources.Load("Checker") as Material);
        }
        else
        {
            this.shapeMain.GetComponent <MeshRenderer>().sharedMaterial = new Material(this.GetSpecularShader());
            this.shapeMain.gameObject.GetComponent <Renderer>().material.SetColor("_Color", new Color(1f, 0.7058824f, 0.7058824f));
            this.shapeMain.gameObject.GetComponent <Renderer>().material.SetColor("_SpecColor", Color.white);
        }
    }
Esempio n. 3
0
    void AddCursors(int[] ports, string parentName, CursorType cursorType, float xMod, float yMod, float[,] target_positions, GameObject grandParent)
    {
        GameObject parent = new GameObject(name: parentName);

        parent.transform.parent = grandParent.transform;

        // get trajectories

        List <float[, ]> trajectory = new List <float[, ]>();

        foreach (var port in ports)
        {
            //print(port);
            trajectory.Add(GetBufferData(port));
            //printArrayDimensions(trajectory[trajectory.Count - 1]);
        }

        // build cursors

        for (int TRIAL = 0; TRIAL < Number.trials; TRIAL++)
        {
            List <Vector2> cursorTrajectory = reshapeTrajectory(trajectory, TRIAL, xMod, yMod);

            Color colorToUse = colors[(int)target_positions[TRIAL, 0] - 1];

            float randomValue = UnityEngine.Random.Range(.25f, 1);
            colorToUse.r = colorToUse.r * randomValue;
            colorToUse.g = colorToUse.g * randomValue;
            colorToUse.b = colorToUse.b * randomValue;

            GameObject SpawnCursorObject()
            {
                switch (cursorType)
                {
                case CursorType.cursor:
                    GameObject cursorObject1 = PlaneObject.Create(width: Sizes.cursor,
                                                                  length: Sizes.cursor,
                                                                  widthSegments: 1,
                                                                  lengthSegments: 1).gameObject;

                    cursorObject1.GetComponent <Renderer>().material       = cursorMaterial;
                    cursorObject1.GetComponent <Renderer>().material.color = colorToUse;
                    return(cursorObject1);

                case CursorType.gaze:
                    GameObject cursorObject2 = Create.Polygon(position: Vector3.zero,
                                                              rotation: new Vector3(-90, 0, 0),
                                                              radius: Sizes.gaze,
                                                              edgeThickness: .1f,
                                                              nSegments: Defaults.nSegementsCircle,
                                                              color: colorToUse,
                                                              sortingOrder: 1);
                    return(cursorObject2);

                default:
                    return(new GameObject());
                }
            }

            GameObject cursorObject = SpawnCursorObject();
            cursorObject.name             = "cursor." + TRIAL.ToString();
            cursorObject.transform.parent = parent.transform;

            cursors.Add(new Cursor(gameObject: cursorObject, trajectory: cursorTrajectory));
        }
    }
Esempio n. 4
0
    void Start()
    {
        FPS_text = GameObject.Find("Canvas/FPS").GetComponent <TextMeshProUGUI>();

        Stopwatch sw = new Stopwatch();

        sw.Start();

        cursorMaterial = Resources.Load("UnlitColor") as Material;

        float[,] GetBufferData(int port)
        {
            UnityBuffer unityBuffer = new UnityBuffer();

            if (unityBuffer.connect(host: "127.0.0.1", port: port))
            {
                print("connected");
                unityBuffer.header = unityBuffer.getHeader();

                float[,] data = unityBuffer.getFloatData(0, unityBuffer.header.nSamples - 1);

                //print(data.GetLength(0));
                //print(data.GetLength(1));

                return(data);
            }
            else
            {
                print("connection failed...");
                return(new float[0, 0]);
            }
        }

        void printArrayDimensions(float[,] array)
        {
            print(array.GetLength(0));
            print(array.GetLength(1));
        }

        // get trajectories

        List <float[, ]> trajectory = new List <float[, ]>();

        foreach (var port in ports)
        {
            print(port);
            trajectory.Add(GetBufferData(port));
            printArrayDimensions(trajectory[trajectory.Count - 1]);
        }

        // get colors

        float[,] target_positions = GetBufferData(1002);
        printArrayDimensions(target_positions);


        // build cursors

        for (int TRIAL = 0; TRIAL < Number.trials; TRIAL++)
        {
            // reshape

            float[,] trajectory_to_use = new float[Number.frames, Number.axes];

            for (int FRAME = 0; FRAME < Number.frames; FRAME++)
            {
                for (int AXIS = 0; AXIS < Number.axes; AXIS++)
                {
                    //print(TRIAL.ToString() + ":" + FRAME.ToString() + ":" + AXIS.ToString());
                    trajectory_to_use[FRAME, AXIS] = trajectory[AXIS][TRIAL, FRAME];
                }
            }


            Color colorToUse  = colors[(int)target_positions[TRIAL, 0] - 1];
            float randomValue = Random.Range(.25f, 1);
            colorToUse.r = colorToUse.r * randomValue;
            colorToUse.g = colorToUse.g * randomValue;
            colorToUse.b = colorToUse.b * randomValue;


            PlaneObject cursorPlane = PlaneObject.Create(width: Sizes.cursor,
                                                         length: Sizes.cursor,
                                                         widthSegments: 1,
                                                         lengthSegments: 1);

            cursorPlane.gameObject.GetComponent <Renderer>().material       = cursorMaterial;
            cursorPlane.gameObject.GetComponent <Renderer>().material.color = colorToUse;

            cursors.Add(new Cursor(gameObject: cursorPlane.gameObject, trajectory: trajectory_to_use));

            //cursors[cursors.Count - 1].gameObject.transform.localScale = new Vector3(.1f, .1f, .1f) * 15;
            //cursors[cursors.Count - 1].gameObject.GetComponent<Renderer>().material = cursorMaterial;
            //cursors[cursors.Count - 1].gameObject.GetComponent<Renderer>().material.color = colorToUse;
        }



        // add target positions

        for (int TARGET = 0; TARGET < Number.targetPositions; TARGET++)
        {
            GameObject target = Create.Polygon(position: new Vector3(targetPositions[TARGET].x, 0, targetPositions[TARGET].y),
                                               rotation: new Vector3(-90, 0, 0),
                                               radius: Sizes.target,
                                               edgeThickness: .1f,
                                               nSegments: Defaults.nSegementsCircle,
                                               color: Color.white, //colors[TARGET],
                                               sortingOrder: 2);

            //GameObject target = GameObject.CreatePrimitive(PrimitiveType.Plane);
            //target.transform.localScale = new Vector3(.1f, .1f, .1f) * 15;
            //target.transform.position = new Vector3(targetPositions[TARGET].x, 0, targetPositions[TARGET].y);
            //target.GetComponent<Renderer>().material = cursorMaterial;
            //target.GetComponent<Renderer>().material.color = colors[TARGET];

            target.name = TARGET.ToString();
        }

        print(sw.Elapsed.Seconds);
    }
Esempio n. 5
0
    void Start()
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();

        // timeVector setup

        for (int FRAME = 0; FRAME < Number.frames; FRAME++)
        {
            timeVector[FRAME] = (float)FRAME / 144;
        }

        // scene setup

        FPS_text       = GameObject.Find("Canvas/FPS_text").GetComponent <TextMeshProUGUI>();
        cursorMaterial = Resources.Load("UnlitColor") as Material;

        // add target positions

        void DrawTargets(float xMod, string parentName)
        {
            GameObject targets = new GameObject(name: parentName);

            for (int TARGET = 0; TARGET < Number.targetPositions; TARGET++)
            {
                GameObject target = Create.Polygon(position: new Vector3(targetPositions[TARGET].x + xMod, 0, targetPositions[TARGET].y),
                                                   rotation: new Vector3(-90, 0, 0),
                                                   radius: Sizes.target,
                                                   edgeThickness: .1f,
                                                   nSegments: Defaults.nSegementsCircle,
                                                   color: Color.white, //colors[TARGET],
                                                   sortingOrder: 2);

                target.name             = "target." + TARGET.ToString();
                target.transform.parent = targets.transform;
            }
        }

        for (int CONTROL = 0; CONTROL < Number.control; CONTROL++)
        {
            DrawTargets(xMod[CONTROL], "targets." + Labels.control[CONTROL]);
        }

        // session setup

        float[,] GetBufferData(int port)
        {
            UnityBuffer unityBuffer = new UnityBuffer();

            if (unityBuffer.connect(host: "127.0.0.1", port: port))
            {
                print("connected");
                unityBuffer.header = unityBuffer.getHeader();
                float[,] data      = unityBuffer.getFloatData(0, unityBuffer.header.nSamples - 1);
                return(data);
            }
            else
            {
                print("connection failed...");
                return(new float[0, 0]);
            }
        }

        void printArrayDimensions(float[,] array)
        {
            print(array.GetLength(0));
            print(array.GetLength(1));
        }

        // reshape method
        List <Vector2> reshapeTrajectory(List <float[, ]> trajectoryData, int TRIAL, float xMod)
        {
            List <Vector2> trajectoryToUse = new List <Vector2>();

            for (int FRAME = 0; FRAME < Number.frames; FRAME++)
            {
                Vector2 position = new Vector2();

                for (int AXIS = 0; AXIS < Number.axes; AXIS++)
                {
                    //print(TRIAL.ToString() + ":" + FRAME.ToString() + ":" + AXIS.ToString());
                    if (AXIS == 0)
                    {
                        position[AXIS] = trajectoryData[AXIS][TRIAL, FRAME] + xMod;
                    }
                    else
                    {
                        position[AXIS] = trajectoryData[AXIS][TRIAL, FRAME];
                    }
                }
                trajectoryToUse.Add(position);
            }

            return(trajectoryToUse);
        }

        void AddCursors(int[] ports, string parentName, CursorType cursorType, float xMod, float[,] target_positions)
        {
            GameObject parent = new GameObject(name: parentName);

            // get trajectories

            List <float[, ]> trajectory = new List <float[, ]>();

            foreach (var port in ports)
            {
                print(port);
                trajectory.Add(GetBufferData(port));
                printArrayDimensions(trajectory[trajectory.Count - 1]);
            }

            // build cursors

            for (int TRIAL = 0; TRIAL < Number.trials; TRIAL++)
            {
                List <Vector2> cursorTrajectory = reshapeTrajectory(trajectory, TRIAL, xMod);

                Color colorToUse = colors[(int)target_positions[TRIAL, 0] - 1];

                float randomValue = UnityEngine.Random.Range(.25f, 1);
                colorToUse.r = colorToUse.r * randomValue;
                colorToUse.g = colorToUse.g * randomValue;
                colorToUse.b = colorToUse.b * randomValue;

                GameObject SpawnCursorObject()
                {
                    switch (cursorType)
                    {
                    case CursorType.cursor:
                        GameObject cursorObject1 = PlaneObject.Create(width: Sizes.cursor,
                                                                      length: Sizes.cursor,
                                                                      widthSegments: 1,
                                                                      lengthSegments: 1).gameObject;

                        cursorObject1.GetComponent <Renderer>().material       = cursorMaterial;
                        cursorObject1.GetComponent <Renderer>().material.color = colorToUse;
                        return(cursorObject1);

                    case CursorType.gaze:
                        GameObject cursorObject2 = Create.Polygon(position: Vector3.zero,
                                                                  rotation: new Vector3(-90, 0, 0),
                                                                  radius: Sizes.gaze,
                                                                  edgeThickness: .1f,
                                                                  nSegments: Defaults.nSegementsCircle,
                                                                  color: colorToUse,
                                                                  sortingOrder: 1);
                        return(cursorObject2);

                    default:
                        return(new GameObject());
                    }
                }

                GameObject cursorObject = SpawnCursorObject();
                cursorObject.name             = "cursor." + TRIAL.ToString();
                cursorObject.transform.parent = parent.transform;

                cursors.Add(new Cursor(gameObject: cursorObject, trajectory: cursorTrajectory));
            }
        }

        float[,] target_positions_solo = GetBufferData(Ports.target_positions_solo);

        AddCursors(Ports.P1, "P1", CursorType.cursor, xMod[0], target_positions_solo);
        AddCursors(Ports.P2, "P2", CursorType.cursor, xMod[0], target_positions_solo);

        AddCursors(Ports.P1_gaze_solo, "P1_gaze_solo", CursorType.gaze, xMod[0], target_positions_solo);
        AddCursors(Ports.P2_gaze_solo, "P2_gaze_solo", CursorType.gaze, xMod[0], target_positions_solo);

        float[,] target_positions_joint = GetBufferData(Ports.target_positions_joint);

        AddCursors(Ports.joint, "joint", CursorType.cursor, xMod[1], target_positions_joint);

        AddCursors(Ports.P1_gaze_joint, "P1_gaze_joint", CursorType.gaze, xMod[1], target_positions_joint);
        AddCursors(Ports.P2_gaze_joint, "P2_gaze_joint", CursorType.gaze, xMod[1], target_positions_joint);

        print(sw.Elapsed.Seconds);
    }
Esempio n. 6
0
    void Start()
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();

        // timeVector setup

        for (int FRAME = 0; FRAME < Number.frames; FRAME++)
        {
            timeVector[FRAME] = (float)FRAME / 144;
        }

        // scene setup

        FPS_text       = GameObject.Find("Canvas/FPS").GetComponent <TextMeshProUGUI>();
        cursorMaterial = Resources.Load("UnlitColor") as Material;
        timeText       = GameObject.Find("Canvas/Time").GetComponent <TextMeshProUGUI>();
        sessionText    = GameObject.Find("Canvas/Session").GetComponent <TextMeshProUGUI>();

        // session setup

        float[,] GetBufferData(int port)
        {
            UnityBuffer unityBuffer = new UnityBuffer();

            if (unityBuffer.connect(host: "127.0.0.1", port: port))
            {
                print("connected: " + port.ToString());
                unityBuffer.header = unityBuffer.getHeader();
                float[,] data      = unityBuffer.getFloatData(0, unityBuffer.header.nSamples - 1);
                return(data);
            }
            else
            {
                print("connection failed...");
                return(new float[0, 0]);
            }
        }

        void printArrayDimensions(float[,] array)
        {
            print(array.GetLength(0));
            print(array.GetLength(1));
        }

        // reshape method
        List <Vector2> reshapeTrajectory(List <float[, ]> trajectoryData, int TRIAL, float xMod, float yMod)
        {
            List <Vector2> trajectoryToUse = new List <Vector2>();

            for (int FRAME = 0; FRAME < Number.frames; FRAME++)
            {
                Vector2 position = new Vector2();

                for (int AXIS = 0; AXIS < Number.axes; AXIS++)
                {
                    //print(TRIAL.ToString() + ":" + FRAME.ToString() + ":" + AXIS.ToString());
                    if (AXIS == 0)
                    {
                        position[AXIS] = trajectoryData[AXIS][TRIAL, FRAME] + xMod;
                    }
                    else
                    {
                        position[AXIS] = trajectoryData[AXIS][TRIAL, FRAME] + yMod;
                    }
                }
                trajectoryToUse.Add(position);
            }

            return(trajectoryToUse);
        }

        void AddCursors(int[] ports, string parentName, CursorType cursorType, float xMod, float yMod, float[,] target_positions, GameObject grandParent)
        {
            GameObject parent = new GameObject(name: parentName);

            parent.transform.parent = grandParent.transform;

            // get trajectories

            List <float[, ]> trajectory = new List <float[, ]>();

            foreach (var port in ports)
            {
                //print(port);
                trajectory.Add(GetBufferData(port));
                //printArrayDimensions(trajectory[trajectory.Count - 1]);
            }

            // build cursors

            for (int TRIAL = 0; TRIAL < Number.trials; TRIAL++)
            {
                List <Vector2> cursorTrajectory = reshapeTrajectory(trajectory, TRIAL, xMod, yMod);

                Color colorToUse = colors[(int)target_positions[TRIAL, 0] - 1];

                float randomValue = UnityEngine.Random.Range(.25f, 1);
                colorToUse.r = colorToUse.r * randomValue;
                colorToUse.g = colorToUse.g * randomValue;
                colorToUse.b = colorToUse.b * randomValue;

                GameObject SpawnCursorObject()
                {
                    switch (cursorType)
                    {
                    case CursorType.cursor:
                        GameObject cursorObject1 = PlaneObject.Create(width: Sizes.cursor,
                                                                      length: Sizes.cursor,
                                                                      widthSegments: 1,
                                                                      lengthSegments: 1).gameObject;

                        cursorObject1.GetComponent <Renderer>().material       = cursorMaterial;
                        cursorObject1.GetComponent <Renderer>().material.color = colorToUse;
                        return(cursorObject1);

                    case CursorType.gaze:
                        GameObject cursorObject2 = Create.Polygon(position: Vector3.zero,
                                                                  rotation: new Vector3(-90, 0, 0),
                                                                  radius: Sizes.gaze,
                                                                  edgeThickness: .1f,
                                                                  nSegments: Defaults.nSegementsCircle,
                                                                  color: colorToUse,
                                                                  sortingOrder: 1);
                        return(cursorObject2);

                    default:
                        return(new GameObject());
                    }
                }

                GameObject cursorObject = SpawnCursorObject();
                cursorObject.name             = "cursor." + TRIAL.ToString();
                cursorObject.transform.parent = parent.transform;

                cursors.Add(new Cursor(gameObject: cursorObject, trajectory: cursorTrajectory));
            }
        }

        // add target positions

        void DrawTargets(float xMod, float yMod, string parentName, GameObject grandParent)
        {
            GameObject targets = new GameObject(name: parentName);

            targets.transform.parent = grandParent.transform;

            for (int TARGET = 0; TARGET < Number.targetPositions; TARGET++)
            {
                GameObject target = Create.Polygon(position: new Vector3(targetPositions[TARGET].x + xMod, 0, targetPositions[TARGET].y + yMod),
                                                   rotation: new Vector3(-90, 0, 0),
                                                   radius: Sizes.target,
                                                   edgeThickness: .1f,
                                                   nSegments: Defaults.nSegementsCircle,
                                                   color: Color.white, //colors[TARGET],
                                                   sortingOrder: 2);

                target.name             = "target." + TARGET.ToString();
                target.transform.parent = targets.transform;
            }
        }

        //int[] sessionsToUse = new int[] { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
        int[] sessionsToUse = new int[] { 12, 13, 14, 15, 16, 17 };
        int   sessionCount  = 0;


        void prepareSession(int SESSION)
        {
            print("***************************************************************");
            print("SESSION: " + SESSION.ToString());

            sessionText.text = "S" + Labels.session[SESSION];

            GameObject grandParentObject = new GameObject(name: Labels.session[SESSION]);

            float yModToUse = 0;

            for (int CONTROL = 0; CONTROL < Number.control; CONTROL++)
            {
                DrawTargets(xMod[CONTROL], yModToUse, "targets." + Labels.control[CONTROL], grandParentObject);
            }

            float[,] target_positions_solo = GetBufferData(Ports.target_positions_solo);

            AddCursors(Ports.P1, "P1", CursorType.cursor, xMod[0], yModToUse, target_positions_solo, grandParentObject);
            AddCursors(Ports.P2, "P2", CursorType.cursor, xMod[0], yModToUse, target_positions_solo, grandParentObject);

            AddCursors(Ports.P1_gaze_solo, "P1_gaze_solo", CursorType.gaze, xMod[0], yModToUse, target_positions_solo, grandParentObject);
            AddCursors(Ports.P2_gaze_solo, "P2_gaze_solo", CursorType.gaze, xMod[0], yModToUse, target_positions_solo, grandParentObject);

            float[,] target_positions_joint = GetBufferData(Ports.target_positions_joint);

            AddCursors(Ports.joint, "joint", CursorType.cursor, xMod[1], yModToUse, target_positions_joint, grandParentObject);

            AddCursors(Ports.P1_gaze_joint, "P1_gaze_joint", CursorType.gaze, xMod[1], yModToUse, target_positions_joint, grandParentObject);
            AddCursors(Ports.P2_gaze_joint, "P2_gaze_joint", CursorType.gaze, xMod[1], yModToUse, target_positions_joint, grandParentObject);
        }

        prepareSession(1);

        void StartOBSrecording()
        {
            var proc = new System.Diagnostics.Process
            {
                StartInfo = new System.Diagnostics.ProcessStartInfo // get process by window name - super dodge - also cannot run Pathly from unity
                {
                    FileName               = @"C:\Program Files (x86)\obs-studio\OBSCommand_v1.5.4\OBSCommand\OBSCommand.exe",
                    Arguments              = "/startrecording",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            proc.Start();
        }

        StartOBSrecording();

        print(sw.Elapsed.Seconds);
    }