void RemoveObserversFromList(NSObject observer, string aName, NSObject anObject) { lock (__mt_ObserverList_var) { for (int i = __mt_ObserverList_var.Count - 1; i >= 0; i--) { ObservedData od = __mt_ObserverList_var [i]; if (observer != od.Observer) { continue; } if (aName != null && aName != od.Name) { continue; } if (anObject != null && anObject != od.Object) { continue; } __mt_ObserverList_var.RemoveAt(i); } } }
/***********************/ //int frame = 0; // initialize with zero void OnFrame() { //recording the data angle = mainCamera.transform.localRotation.eulerAngles.y; playerPositions[frameIndex] = SpineMid.transform.position; playerHeadRotations[frameIndex] = angle; traffic_towards_flow[frameIndex] = current_traffic_towards_flow; current_time_span[frameIndex] = Mathf.Abs(Mathf.Round((Time.time - timeSinceReachTheFirstYellowPoint) * 1000) / 1000); isLookingAtCar[frameIndex] = CarMove.numberOfRenderedCars > 0; is_hit_by_car[frameIndex] = checkPointsController.isHitByCar; distance_nearest_car_in_lane[frameIndex] = finalDistanceResult; frameIndex++; if (frameIndex == 2) // you can use this as the index of the lists { // Debug.Log("ON FRAME "); observedData = new ObservedData(playerPositions, playerHeadRotations, isLookingAtCar, traffic_towards_flow, current_time_span, is_hit_by_car, distance_nearest_car_in_lane); //connection to database in a thread // Debug.Log("OnFRAME"); //StartCoroutine(ConnectToDB()); Thread connectionDBThread = new Thread(() => ConnectionToDB()); connectionDBThread.Start(); if (!connectionDBThread.IsAlive) { // Debug.Log("ABORT THREAD"); connectionDBThread.Abort(); } // Debug.Log("thread status =" + connectionDBThread.IsAlive); //connectionDBThread.Join(); frameIndex = 0; // back to zero after each send } }
//create a crossingroaddata row in the db public void CreateRoadCrossingData(ObservedData observedData) { StreetCrossingData streetCrossingData; for (int i = 0; i < 2; i++) { streetCrossingData = new StreetCrossingData { gameplay_id = ExperimentParameters.gameplay_id, //storing from the static variable in the class traffic_flow_towards = observedData.traffic_towards_flow[i], current_time_span = double.Parse(observedData.current_time_span[i].ToString("F3")), current_distance_nearest_car = (double)observedData.nearest_distance_for_lane[i], //for now gazing_car = observedData.isLookingAtCar[i], gazing_nearest_car = false, //for now after_collision_frame = observedData.is_hit_by_car[i], person_x = (double)observedData.playerPositions[i].x, person_y = (double)observedData.playerPositions[i].y, person_z = (double)observedData.playerPositions[i].z, head_rotation_y = (double)observedData.playerHeadRotations[i] }; _connection.Insert(streetCrossingData); } }