// Use this for initialization void Start() { //read file string data_raw; string[] data_lines; //string path = "txt\\" + this.gameObject.name + ".txt"; string path = "data\\" + this.gameObject.name + ".txt"; try { data_raw = File.ReadAllText(path); } catch { print(gameObject.name + " find no file, already disabled"); return; } data_lines = data_raw.Split('\n'); TotalDataNum = data_lines.Length; //change string data into int foreach (string i in data_lines) { string[] t = i.Split(','); float[] k = new float[] { float.Parse(t[0]), float.Parse(t[1]), float.Parse(t[2]), float.Parse(t[3]), float.Parse(t[4]), float.Parse(t[5]) }; data.Add(k); string[] j = new string[] { t[6], t[7] }; label.Add(j); } //initial position gameObject.transform.position = InitialPos; //initial Linrenderer try { box_Line = gameObject.GetComponent <Box_line>(); } catch { print(gameObject.name + " BoxMove get Line error"); box_Line = null; } //initial label try { panel_Label = GameObject.Find("Panel_label").GetComponent <Panel_label>(); } catch { print("BoxMove FindLabel error"); } print(SensorNum); }
// Update is called once per frame void Update() { if (retrying == true) { if (box_Line != null) { box_Line.OnRetryBtn(); Going = true; } } if (Going == true) { if (NowDataIte < TotalDataNum) { //label update if (NowSensor == 0) { if (panel_Label == null) { try { panel_Label = GameObject.Find("Panel_label").GetComponent <Panel_label>(); } catch { print("BoxMove FindLabel error"); } } panel_Label.LabelUpdate(label[NowDataIte][0], label[NowDataIte][1]); } //move (and add initial pos) transform.position = new Vector3(data[NowDataIte][0] + InitialPos.x, data[NowDataIte][2] + InitialPos.y, data[NowDataIte][1] + InitialPos.z); transform.rotation = Quaternion.Euler(data[NowDataIte][3], data[NowDataIte][5], data[NowDataIte][4]); NowSensor++; if (NowSensor == SensorNum) { NowDataIte++; NowSensor = 0; } //draw line if (box_Line != null) { box_Line.DrawLine(); } } else { print("End"); NowDataIte = 0; Going = false; } if (Retrying == true) { retryIte++; print(NowSensor + gameObject.name); if (retryIte == SensorNum) { retryIte = 0; Going = false; Retrying = false; } } } }