Esempio n. 1
0
    /**
     * Given a json blob representing the a BBList,
     * load and instantiate bounding boxes to match the contents.
     */
    public void LoadJson(string json)
    {
        BBList bbList = JsonUtility.FromJson <BBList>(json);

        foreach (BBInfo bbInfo in bbList.boundingBoxes)
        {
            GameObject boundingBox = Instantiate(boundingBoxPrefab, bbInfo.position, Quaternion.Euler(bbInfo.rotation));
            boundingBox.transform.localScale = bbInfo.scale;
            boundingBox.transform.SetParent(boundingBoxParent);
            boundingBox.GetComponent <BBState>().label = bbInfo.label;

            // 2D
            GameObject boundingBox2D = Instantiate(boundingBox2DPrefab);
            boundingBox2D.transform.SetParent(boundingBox2DParent);
            boundingBox2D.GetComponent <BB2D>().linkedObj = boundingBox;
        }
    }
Esempio n. 2
0
    private string BBToJson()
    {
        GameObject bbParent = GameObject.Find(PARENT_NAME);

        BBInfo[] boundingBoxes = new BBInfo[bbParent.transform.childCount];
        for (int i = 0; i < boundingBoxes.Length; i++)
        {
            Transform childTransform = bbParent.transform.GetChild(i);
            BBInfo    bbInfo         = new BBInfo();
            bbInfo.position  = childTransform.position;
            bbInfo.rotation  = childTransform.eulerAngles;
            bbInfo.scale     = childTransform.localScale;
            bbInfo.label     = childTransform.GetComponent <BBState>().label;
            boundingBoxes[i] = bbInfo;
        }

        BBList bbList = new BBList();

        bbList.boundingBoxes = boundingBoxes;
        return(JsonUtility.ToJson(bbList));
    }