private void Awake() { data = ScanningValue.getData(); if (data < 90f) { data = 90f; } else if (data > 180f) { data = 180; } }
void Start() { text.text = ScanningValue.getData().ToString(); }
IEnumerator ScanningUI() { scanningUI.SetActive(true); //Text scanningUIText = scanningUI.transform.Find("Number").GetComponent<Text>(); //RectTransform rectTransform = scanningUI.transform.Find("Bar").transform.Find("ColorBar").GetComponent<RectTransform>(); float d = 0.0f, rot = 0.0f; float ANGLE_MAX = 90.0f, ANGLE_MIN = -90.0f; float max = 0.0f, min = 0.0f; angle = 0.0f; while (scanningUI.activeSelf == true) { if (Camera.main == null) { yield return(new WaitForSeconds(0.1f)); } rot = Camera.main.transform.localRotation.eulerAngles.y; if (rot > 180.0f) { rot -= 360.0f; } if (rot < 92f && rot > -92f) { if (Convert.ToInt32(rot) % Convert.ToInt32(90f / (ChartData.Length / 4)) == 0) { Debug.Log("Data Checking!"); //RecortData(rot, Input.acceleration.z * 90f); StartCoroutine(RecordDataCoroutine(rot, Input.acceleration.z * 90f + CompensationAngle)); } } if (rot > 0.0f) { if (rot < ANGLE_MAX && rot > max) { max = rot; } } else { if (rot > ANGLE_MIN && rot < min) { min = rot; } } // rot is theta //if (rot < 0) //{ // d = rot * (5.0f / 9.0f) + 50; // left side // if (rot < 90 && rot > -90) // { // rectTransform.offsetMin = new Vector2(d, rectTransform.offsetMin.y); // rectTransform.offsetMax = new Vector2(-50, rectTransform.offsetMax.y); // } // } // right side //else //{ // d = (-1) * rot * (5.0f / 9.0f) + 50; // if (rot < 90 && rot > -90) // { // rectTransform.offsetMax = new Vector2(-d, rectTransform.offsetMax.y); // +일 때는 오른쪽만 수정 = right // rectTransform.offsetMin = new Vector2(50, rectTransform.offsetMin.y); // } //} angle = Mathf.Abs(max) + Mathf.Abs(min); angle = angle < 90.0f ? 90.0f : angle; //scanningUIText.text = "angle1 : " + rot.ToString() + "\nangle2 : " + angle.ToString() + "\npadding : " + d.ToString(); float sum = 0f; for (int i = 0; i < 4; i++) { float tmp = 0f; for (int j = 0; j < ChartData.Length / 4; j++) { tmp += ChartData[i * ChartData.Length / 4 + j]; } tmp = Mathf.Sqrt(tmp / (ChartData.Length / 4)); // 한 사분면의 평균의 변환값 if (tmp > 50f) { tmp = 50f; } sum += tmp; } ChartAvg = sum / 4f;// Mathf.Sqrt(sum / ChartData.Length); ChartAvgText.text = "ChartAvg. : " + ChartAvg.ToString() + "\ny'' :" + (Input.acceleration.z * 90f + CompensationAngle).ToString(); /*-----------------게이지 그리기-----------------------*/ // ChartAvg = [0, 50] float currentPercentage; if (ChartAvg > 50f) { currentPercentage = 100f; } else if (ChartAvg < 0f) { currentPercentage = 0f; } else { currentPercentage = ChartAvg * 2; } StartCoroutine(GaugeCoroutine(currentPercentage));// GaugeText.GetComponent <Text>().text = "avg : " + ((int)currentPercentage).ToString(); yield return(null); } /*-----------------값 변환 및 전달-----------------------*/ angle = 90f / 50f * ChartAvg + 90f; if (ChartAvg > 50f) // 현재 50이 최대라고 생각하고 있음 { angle = 180f; } if (angle > 180f) { angle = 180f; } else if (angle < 90f) { angle = 90f; } ScanningValue.setData(angle); UnityEngine.SceneManagement.SceneManager.LoadScene("04.MainGameScene"); }