// Update is called once per frame void Update() { if (!mainSystem.finish_read_config) { return; } //キャリブが終わってからポジショントラッキングとバッテリー情報アクセスする if (calib_system.CheckFinishCalibration()) { PositionTracking(); UpdateBatteryInformation(); } }
// Update is called once per frame void Update() { if (!mainSystem.finish_read_config) { return; } //キャリブが終わってから if (calib_system.CheckFinishCalibration()) { if (!init_this_system) { InitThisSystem(); } WHS1DataUpdate(); } }
// Update is called once per frame void Update() { if (!mainSystem.finish_read_config) { return; } //CoordinatesAdapterの位置を調整してカメラとの距離を計算 coordinates_adapter.transform.localPosition = new Vector3(-0.23f, 0.0f, -0.3f); distance_old = distance; distance = CalcDistance(coordinates_adapter, ar_camera); //最初の1回Shaderを変更する if (!change_goods_shader) { foreach (GoodsData goods in goods_data_dictionary.Values) { ShaderChange shaderchange = goods.obj.GetComponent <ShaderChange>(); shaderchange.ChangeShader(Shader.Find("Custom/Transparent")); } change_goods_shader = true; } //距離が閾値以下でデータベースのstateが1だったら表示,違ったら非表示 if (calib_system.CheckFinishCalibration() && finish_coroutine) { //近づいたとき if (distance < mainSystem.GetConfig().refrigerator_distance&& distance_old >= mainSystem.GetConfig().refrigerator_distance) { refrigerator_shaderchange.ChangeShader(Shader.Find("Custom/Transparent")); refrigerator_shaderchange.alpha = 0.4f; refrigerator_shaderchange.ChangeColors(); IEnumerator coroutine = AppearSlowly(); StartCoroutine(coroutine); } //遠くにいるとき else if (distance >= mainSystem.GetConfig().refrigerator_distance) { foreach (GoodsData goods in goods_data_dictionary.Values) { ShaderChange goods_shaderchange = goods.obj.GetComponent <ShaderChange>(); goods_shaderchange.alpha = 0.0f; goods_shaderchange.ChangeColors(); goods.text3d.SetActive(false); } if (refrigerator_shaderchange.shader_now != Shader.Find("Custom/ARTransparent")) { refrigerator_shaderchange.ChangeShader(Shader.Find("Custom/ARTransparent")); refrigerator_shaderchange.alpha = rostms_shaderchange.alpha; refrigerator_shaderchange.ChangeColors(); } } //ずっと近くにいるとき else if (distance < mainSystem.GetConfig().refrigerator_distance&& distance_old < mainSystem.GetConfig().refrigerator_distance) { foreach (GoodsData goods in goods_data_dictionary.Values) { ShaderChange goods_shaderchange = goods.obj.GetComponent <ShaderChange>(); if (goods.state_bool) { goods_shaderchange.alpha = 0.4f; goods.text3d.SetActive(true); } else { goods_shaderchange.alpha = 0.0f; goods.text3d.SetActive(false); } goods_shaderchange.ChangeColors(); } } } //画像認識による自動キャリブレーションが終わった後に実行 if (calib_system.CheckFinishCalibration()) { //冷蔵庫に入っている物品のデータを取得 time_1 += Time.deltaTime; if (!DBAdapter.CheckWaitAnything() && time_1 > 1.0f) { time_1 = 0.0f; IEnumerator coroutine = DBAdapter.GetRefrigeratorItem(); StartCoroutine(coroutine); } if (DBAdapter.CheckGetRefrigeratorItem()) { if (DBAdapter.CheckAbort()) { DBAdapter.ConfirmAbort(); } if (DBAdapter.CheckSuccess()) { id_list = new List <int>(); ServiceResponseDB responce = DBAdapter.GetResponce(); DBAdapter.FinishReadData(); foreach (tmsdb data in responce.values.tmsdb) { //Debug.Log(data.name); //Debug.Log(data.x + ", " + data.y + ", " + data.z); if (data.sensor == 3018 && goods_data_dictionary.ContainsKey(data.id)) { GoodsData goods = goods_data_dictionary[data.id]; Vector3 place = new Vector3((float)data.x, (float)data.y, (float)data.z); place = Ros2UnityPosition(place); if (data.state == 1) { goods.state_bool = true; Debug.Log(data.name + " pos: " + place.ToString("f2")); mainSystem.MyConsole_Add(data.name + " pos: " + place.ToString("f2")); goods.obj.transform.localPosition = place; id_list.Add(data.id); } else { goods.state_bool = false; } if (goods.name == null) { goods.name = data.name; } if (goods.expiration == null) { goods.expiration = "don't know"; } goods.state = data.state; goods.pos = place; } } } } //冷蔵庫に入っている物品の消費期限を取得 time_2 += Time.deltaTime; if (!DBAdapter.CheckWaitAnything() && time_2 > 5.0f) { time_2 = 0.0f; DBAdapter.GiveItemIDList(id_list); IEnumerator coroutine = DBAdapter.ReadExpiration(); StartCoroutine(coroutine); } if (DBAdapter.CheckReadExpiration()) { if (DBAdapter.CheckAbort()) { DBAdapter.ConfirmAbort(); } if (DBAdapter.CheckSuccess()) { Dictionary <int, string> expiration_dictionary = DBAdapter.ReadExpirationData(); DBAdapter.FinishReadData(); foreach (KeyValuePair <int, string> goods in expiration_dictionary) { ExpirationData expiration_data = JsonUtility.FromJson <ExpirationData>(goods.Value); string expiration = expiration_data.expiration; Debug.Log("id: " + goods.Key + ", name: " + goods_data_dictionary[goods.Key].name + ", expiration: " + expiration); mainSystem.MyConsole_Add("id: " + goods.Key + ", name: " + goods_data_dictionary[goods.Key].name + ", expiration: " + expiration); goods_data_dictionary[goods.Key].text3d.GetComponent <TextMeshPro>().text = expiration; goods_data_dictionary[goods.Key].expiration = expiration; } } } //UIを更新する Dictionary <int, string> goods_info_string_dictionary = new Dictionary <int, string>(); foreach (KeyValuePair <int, GoodsData> goods in goods_data_dictionary) { string info = goods.Value.name + ", " + goods.Key.ToString() + ", " + goods.Value.state.ToString() + ", " + goods.Value.pos.ToString("f3") + ", " + goods.Value.expiration; goods_info_string_dictionary.Add(goods.Key, info); } mainSystem.UpdateDatabaseInfoRefrigerator(goods_info_string_dictionary); } }