Beispiel #1
0
 public virtual void startTask()
 {
     task_start = Experiment.Now();
     //currentInterrupt = 0;        Not here since after an interuupt we will restart
     Start();    //added by jared
     log.log("TASK_START\t" + name + "\t" + this.GetType().Name, 1);
 }
Beispiel #2
0
    public void stop()
    {
        //someday make these be real speed values
        Vector3 vec = new Vector3(0.0F, 0.0F, 0.0F);

        AVATAR_STOP(vec);
        log.log("AVATAR_STOP	"+ vec.ToString("f0"), 1);
    }
Beispiel #3
0
 // Update is called once per frame
 void FixedUpdate()
 {
     // Log the name of the tracked object, it's body position, body rotation, and camera (head) rotation
     if (navLog)
     {
         //print("AVATAR_POS	" + "\t" +  avatar.position.ToString("f3") + "\t" + "AVATAR_Body " + "\t" +  cameraCon.localEulerAngles.ToString("f3") +"\t"+ "AVATAR_Head " + cameraRig.localEulerAngles.ToString("f3"));
         log.log("Avatar: \t" + avatar.name + "\t" +
                 "Position (xyz): \t" + cameraCon.position.x + "\t" + cameraCon.position.y + "\t" + cameraCon.position.z + "\t" +
                 "Rotation (xyz): \t" + cameraCon.eulerAngles.x + "\t" + cameraCon.eulerAngles.y + "\t" + cameraCon.eulerAngles.z + "\t" +
                 "Camera   (xyz): \t" + cameraRig.eulerAngles.x + "\t" + cameraRig.eulerAngles.y + "\t" + cameraRig.eulerAngles.z + "\t"
                 , 1);
     }
 }
Beispiel #4
0
    void Update()
    {
        if (!done)
        {
            if (config.runMode != ConfigRunMode.PLAYBACK)
            {
                if (Input.GetKeyDown(KeyCode.T))
                {
                    dblog.log("BOOKMARK	t-trigger", 1);
                }

                done = tasks.updateTask();
                if (done)
                {
                    Cursor.visible = true;
                    Application.Quit();
                }
            }
            else
            {
                UpadtePlayback();
            }
        }
    }
Beispiel #5
0
 public void setScore(int newScore)
 {
     score = newScore;
     log.log("SET_SCORE	"+ score, 2);
 }
Beispiel #6
0
    void Awake()
    {
        // check if we have any old Landmarks instances from LoadScene.cs and handle them
        GameObject oldInstance = GameObject.Find("OldInstance");

        if (oldInstance != null)
        {
            foreach (var item in oldInstance.transform)
            {
                //Destroy(item); // this tends to break the steamvr skeleton buttons and hand rendermodels
                oldInstance.SetActive(false);
            }
        }

        Debug.Log("Starting Experiment.cs");

        //since config is a singleton it will be the one created in scene 0 or this scene
        config = Config.instance;

        // ------------------------------------------
        // Grab the Landmarks items that are not controller dependent
        // ------------------------------------------
        tasks          = GameObject.Find("LM_Timeline").GetComponent <TaskList>();
        overheadCamera = GameObject.Find("OverheadCamera").GetComponent <Camera>();
        // Assign the scaled player if it's in the scene, otherwise instantiate to avoid errors
        scaledPlayer = GameObject.Find("SmallScalePlayerController");
        // find Environment
        environment = GameObject.FindGameObjectWithTag("Environment");
        // find scaled environment
        if (GameObject.FindGameObjectsWithTag("ScaledEnvironment") != null)
        {
            scaledEnvironment = GameObject.FindGameObjectWithTag("ScaledEnvironment");
            scaledEnvironment.SetActive(false);
        }


        if (PlayerPrefs.GetString("UserInterface") != "default")
        {
            Debug.Log("Getting user interface from config file.");

            switch (config.ui)
            {
            case "Desktop":
                userInterface = UserInterface.DesktopDefault;
                break;

            case "Vive Virt.":
                userInterface = UserInterface.ViveAndVirtualizer;
                break;

            case "Vive Std.":
                userInterface = UserInterface.ViveRoomspace;
                break;

            default:
                break;
            }
        }

        // ------------------------------------------
        // Assign Player and Camera based on UI enum
        // ------------------------------------------


        switch (userInterface)
        {
        case UserInterface.DesktopDefault:
            // Standard Desktop with Keyboard/mouse controller
            player       = GameObject.Find("DesktopDefaultController");
            playerCamera = GameObject.Find("DesktopDefaultCamera").GetComponent <Camera>();

            // Render the overhead camera on the main display (none)
            overheadCamera.stereoTargetEye = StereoTargetEyeMask.None;

            // create variable to indicate if using VR
            usingVR = false;

            break;

        case UserInterface.ViveRoomspace:

            // HTC Vive and Cyberith Virtualizer
            player       = GameObject.Find("ViveRoomspaceController");
            playerCamera = GameObject.Find("VRCamera").GetComponent <Camera>();

            // Render the overhead camera to each lense of the HMD
            overheadCamera.stereoTargetEye = StereoTargetEyeMask.Both;

            // create variable to indicate if using VR
            usingVR = true;

            break;

        case UserInterface.ViveAndVirtualizer:

            // This is a proprietary asset that must be added to the _Landmarks_ prefab to work
            // If it is not added (either for lack of need or lack of the proprietary SDK), use the default
            if (GameObject.Find("ViveVirtualizerController") == null)
            {
                Debug.Log("UserInterface player controller not found. Falling back to Default");
                goto default;
            }

            // HTC Vive and Cyberith Virtualizer
            player       = GameObject.Find("ViveVirtualizerController");
            playerCamera = GameObject.Find("ViveVirtualizerCamera").GetComponent <Camera>();

            // Render the overhead camera to each lense of the HMD
            overheadCamera.stereoTargetEye = StereoTargetEyeMask.Both;

            // create variable to indicate if using VR
            usingVR = true;

            break;

        default:
            // Standard Desktop with Keyboard/mouse controller
            player       = GameObject.Find("DesktopDefaultController");
            playerCamera = GameObject.Find("DesktopDefaultCamera").GetComponent <Camera>();

            // Render the overhead camera on the main display (none)
            overheadCamera.stereoTargetEye = StereoTargetEyeMask.None;

            // create variable to indicate if using VR
            usingVR = false;

            break;
        }

        Debug.Log(player.name);
        // Tag the selected playerController
        player.tag = "Player";
        // Deactivate all other controllers
        foreach (Transform child in GameObject.Find("PlayerControllers").transform)
        {
            if (child.name != player.name)
            {
                child.gameObject.SetActive(false);
            }
        }

        // Add audiolistener to camera (default one should be removed on on all LM_playerControllers)
        // This ensures there will only be one in the scene, attached to the active camera
        playerCamera.gameObject.AddComponent <AudioListener>();

        // Set up Overhead Camera (for map task or any other top-down viewed tasks)
        overheadCamera = GameObject.Find("OverheadCamera").GetComponent <Camera> ();

        // ------------------------------------------
        // Configure Player properties
        // ------------------------------------------

        playerCamera.enabled   = true;
        overheadCamera.enabled = false;
        Cursor.visible         = false;


        // Set the avatar and hud
        avatar = player;
        hud    = avatar.GetComponent("HUD") as HUD;
        hud.showOnlyHUD();


        // ------------------------------------------
        // Handle the config file
        // ------------------------------------------
        logfile    = config.subjectPath + "/" + PlayerPrefs.GetString("expID") + "_" + config.subject + "_" + config.level + ".log";
        configfile = config.expPath + "/" + config.filename;

        //when in editor
        if (!config.bootstrapped)
        {
            if (!Directory.Exists(Directory.GetCurrentDirectory() + "/data/tmp/"))
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/data/tmp/");
            }
            logfile    = Directory.GetCurrentDirectory() + "/data/tmp/" + "test.log";
            configfile = Directory.GetCurrentDirectory() + "/data/tmp/" + config.filename;

            PlayerPrefs.SetString("expID", "TEST");
        }

        if (config.runMode == ConfigRunMode.NEW)
        {
            dblog = new dbLog(logfile);
        }
        else if (config.runMode == ConfigRunMode.RESUME)
        {
            dblog = new dbPlaybackLog(logfile);
        }
        else if (config.runMode == ConfigRunMode.PLAYBACK)
        {
            CharacterController c = avatar.GetComponent <CharacterController>();
            c.detectCollisions = false;
            dblog = new dbPlaybackLog(logfile);
        }

        //start session

        dblog.log("EXPERIMENT:\t" + PlayerPrefs.GetString("expID") + "\tSUBJECT:\t" + config.subject +
                  "\tSTART_SCENE\t" + config.level + "\tSTART_CONDITION:\t" + config.condition + "\tUI:\t" + userInterface.ToString(), 1);

        Debug.Log(XRSettings.loadedDeviceName);
    }
Beispiel #7
0
    public static void set_keyvalue(string line, string lineNum, dbLog log)
    {
        string go         = "";
        string code       = "";
        string key        = "";
        string val        = "";
        string typestring = "";

        string[] keyvalue = new string[1];
        string[] parts    = new string[1];

        try {
            keyvalue = line.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
            if (keyvalue.Length != 2)
            {
                throw new ConfigFormatException();
            }

            val = keyvalue[1].Trim();

            parts = keyvalue[0].Trim().Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Length != 3)
            {
                throw new ConfigKeyFormatException();
            }



            go   = parts[0];
            code = parts[1];
            key  = parts[2];

            GameObject taskObject = GameObject.Find(go);
            if (!taskObject)
            {
                throw new GameObjectNullException();
            }

            Component script = taskObject.GetComponent(code) as Component;
            if (!script)
            {
                throw new ScriptNullException();
            }

            Type         valType;
            BindingFlags flags;
            FieldInfo    fi = script.GetType().GetField(key, BindingFlags.Instance | BindingFlags.Public);

            // don't care if key is a field or property
            if (fi == null)
            {
                PropertyInfo pi = script.GetType().GetProperty(key, BindingFlags.Instance | BindingFlags.Public);
                if (pi == null)
                {
                    throw new MissingKeyException();
                }
                else
                {
                    typestring = pi.PropertyType.ToString();
                    valType    = pi.PropertyType;
                    flags      = BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty;
                }
            }
            else
            {
                valType    = fi.FieldType;
                typestring = fi.FieldType.ToString();
                flags      = BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetField;
            }

            // try to convert value to correct type
            object converted = null;
            if (valType.IsEnum)
            {
                converted = Enum.Parse(valType, val, true);
            }
            else
            {
                converted = Convert.ChangeType(val, valType);
            }
            if (converted == null)
            {
                throw new InvalidCastException();
            }

            //set via reflection
            script.GetType().InvokeMember(key, flags, null, script, new object[] { converted });
            log.log("CONFIG_SET	" + keyvalue[0].Trim() + "\t" + keyvalue[1].Trim(), 1);
        } catch (ConfigFormatException) {
            Debug.Log(lineNum + "  Configuration '" + line + "' has invalid format.\nValid config format is 'Session.Game Object name.Script Type.Variable = value'");
        } catch (ConfigKeyFormatException) {
            Debug.Log(lineNum + "  Configuration key '" + key.Trim() + "' has invalid format.\nValid config format is 'Session.Game Object name.Script Type.Variable'");
        } catch (GameObjectNullException) {
            Debug.Log(lineNum + "  Unable to find game object: " + go);
        } catch (ScriptNullException) {
            Debug.Log(lineNum + "  Unable to find script: " + code);
        } catch (MissingKeyException) {
            Debug.Log(lineNum + "  Key: " + key + " Not found in " + go + "." + code);
        } catch (FormatException) {
            Debug.Log(lineNum + "  Unable to set " + go + "." + code + "." + key + " to " + val + ". Was expecting to be formated for " + typestring);
        } catch (InvalidCastException) {
            Debug.Log(lineNum + "  Unable to convert " + val + " to " + typestring);
        } catch (ArgumentException e) {
            Debug.Log("Line: " + lineNum + "  " + e.ToString());
        }
    }