public void SetUpForApplication(BoundBoxItem boundBoxItem) { if (appType == APPLICATION_TYPE.Control) { boundBoxItem.panelDes.alpha = 0; boundBoxItem.boundBoxBorder.sprite = boundBoxItem.spRect; boundBoxItem.decor0.SetActive(false); boundBoxItem.decor1.SetActive(false); } else { boundBoxItem.boundBoxBorder.sprite = boundBoxItem.spCircle; boundBoxItem.decor0.SetActive(true); boundBoxItem.decor1.SetActive(true); } }
public void UpdateBoundBox() { RecognizeInputStruct data = fileController.LoadRecorgnizeInput(); CheckTatgetDelay(); if (timeCheckDelay <= 0) { DisableAllChild(boundBoxContainer); timeCheckDelay = timeDelay; if (data == null || data.recognizeObjects.Length == 0) { if (OnNotFoundObject != null) { OnNotFoundObject(); } } } if (data == null) { imgBoundBox.rectTransform.sizeDelta = Vector2.zero; return; } //Select Main Object if (data.recognizeObjects.Length > 0 && isSelectMainObj) { if (isControlling) { data.recognizeObjects = new RecognizeObject[0]; } else { RecognizeObject bestObj = data.recognizeObjects[0]; for (int i = 1; i < data.recognizeObjects.Length; i++) { if (bestObj.score < data.recognizeObjects[i].score) { bestObj = data.recognizeObjects[i]; } } data.recognizeObjects = new RecognizeObject[1]; data.recognizeObjects[0] = bestObj; if (OnMainObjectDetected != null) { OnMainObjectDetected(data.recognizeObjects[0]); } //Debug.Log(data.recognizeObjects[0].x + ":" + (data.recognizeObjects[0].y)); } } for (int i = 0; i < Mathf.Min(data.recognizeObjects.Length, boundBoxContainer.childCount); i++) { Image itemObj = boundBoxContainer.GetChild(i).GetComponent <Image>(); itemObj.rectTransform.localPosition = new Vector3(data.recognizeObjects[i].x + data.recognizeObjects[i].width / 2, -(data.recognizeObjects[i].y + data.recognizeObjects[i].height / 2), itemObj.rectTransform.localPosition.z); itemObj.rectTransform.sizeDelta = new Vector2(data.recognizeObjects[i].width, data.recognizeObjects[i].height); //boundBoxItem.GetComponent<BoundBoxItem>().lbContent.rectTransform.sizeDelta= new Vector2(data.recognizeObjects[i].width, data.recognizeObjects[i].height); //add list string objectName = data.recognizeObjects[i].name.ToUpper(); if (!listTargets.ContainsKey(objectName)) { listTargets[objectName] = typeTargetCount; typeTargetCount++; } BoundBoxItem boundBoxItem = itemObj.GetComponent <BoundBoxItem>(); boundBoxItem.lbContent.text = string.Format("{0} {1}%", objectName, (int)(data.recognizeObjects[i].score * 100)); //boundBoxItem.GetComponent<BoundBoxItem>().lbContent.color= colors[listTargets[objectName] % colors.Count]; boundBoxItem.lbDesc.text = data.recognizeObjects[i].description; boundBoxItem.UpdateBoundBoxByAnim(boundBoxAnim, data.recognizeObjects[i].width, data.recognizeObjects[i].height); boundBoxItem.OptimizeDes(data.recognizeObjects[i].x + data.recognizeObjects[i].width / 2, -(data.recognizeObjects[i].y + data.recognizeObjects[i].height / 2), screenWidth, screenHeight); boundBoxItem.panelDes.alpha = (data.recognizeObjects[i].description != "") ? 1 : 0; itemObj.color = colors[listTargets[objectName] % colors.Count]; itemObj.gameObject.SetActive(true); //show anim des if (prevObj != objectName) { boundBoxItem.GetComponent <Animator>().Play(boundBoxAnim.ToString(), -1, 0f); boundBoxItem.panelDesAnim.Play((boundBoxItem.panelBGDes.localPosition.x <= 0) ? AppConstant.ACTIVE_LEFT_ANIM : AppConstant.ACTIVE_RIGHT_ANIM, -1, 0f); prevObj = objectName; } //Set up for every application SetUpForApplication(boundBoxItem); } for (int i = boundBoxContainer.childCount; i < data.recognizeObjects.Length; i++) { Image itemObj = Instantiate(imgBoundBox, boundBoxContainer); itemObj.rectTransform.localPosition = new Vector3(data.recognizeObjects[i].x + data.recognizeObjects[i].width / 2, -(data.recognizeObjects[i].y + data.recognizeObjects[i].height / 2), itemObj.rectTransform.localPosition.z); itemObj.rectTransform.sizeDelta = new Vector2(data.recognizeObjects[i].width, data.recognizeObjects[i].height); //boundBoxItem.GetComponent<BoundBoxItem>().lbContent.rectTransform.sizeDelta = new Vector2(data.recognizeObjects[i].width, data.recognizeObjects[i].height); //add list string objectName = data.recognizeObjects[i].name.ToUpper(); if (!listTargets.ContainsKey(objectName)) { listTargets[objectName] = typeTargetCount; typeTargetCount++; } BoundBoxItem boundBoxItem = itemObj.GetComponent <BoundBoxItem>(); boundBoxItem.lbContent.text = string.Format("{0} {1}%", objectName, (int)(data.recognizeObjects[i].score * 100)); //boundBoxItem.GetComponent<BoundBoxItem>().lbContent.color = colors[listTargets[objectName] % colors.Count]; boundBoxItem.lbDesc.text = data.recognizeObjects[i].description; boundBoxItem.UpdateBoundBoxByAnim(boundBoxAnim, data.recognizeObjects[i].width, data.recognizeObjects[i].height); boundBoxItem.OptimizeDes(data.recognizeObjects[i].x + data.recognizeObjects[i].width / 2, -(data.recognizeObjects[i].y + data.recognizeObjects[i].height / 2), screenWidth, screenHeight); boundBoxItem.panelDes.alpha = (data.recognizeObjects[i].description != "") ? 1 : 0; itemObj.color = colors[listTargets[objectName] % colors.Count]; itemObj.gameObject.SetActive(true); //show anim des if (prevObj != objectName) { boundBoxItem.GetComponent <Animator>().Play(boundBoxAnim.ToString(), -1, 0f); boundBoxItem.panelDesAnim.Play((boundBoxItem.panelBGDes.localPosition.x <= 0) ? AppConstant.ACTIVE_LEFT_ANIM : AppConstant.ACTIVE_RIGHT_ANIM, -1, 0f); prevObj = objectName; } //Set up for every application SetUpForApplication(boundBoxItem); } UpdateNumBoundBoxActive(); isDelay = (data.recognizeObjects.Length > 0 && data.recognizeObjects.Length == numBoundBoxActive); //Debug.Log("Update Success"); }