Exemplo n.º 1
0
    public void PreviewBox(BoxJSON box)
    {
        if (go != null)
        {
            GameObject.Destroy(go);
        }

        go = new GameObject();

        float shelf_size = box == null ? 1 : box.width;
        //if (shelf_size < 1) { shelf_size = 1; }

        ShelfJSON shelf_json = new ShelfJSON();

        //shelf_json.front_index = new int[] { 3, 0, 1, 2, 3 };
        shelf_json.front_index = new int[] { 3, 0 };
        shelf_json.x_points    = new float[] { -shelf_size, -shelf_size, shelf_size, shelf_size };
        shelf_json.y_points    = new float[] { -shelf_size, shelf_size, shelf_size, -shelf_size };
        shelf_json.boxes       = box == null ? new BoxJSON[0] : new BoxJSON[] { box };


        shelf_json.thickness = shelf_size / 5.0f;


        ShelfJSON[] shj_array = new ShelfJSON[] { shelf_json };
        StandJSON   sj        = new StandJSON();

        sj.shelves = shj_array;
        sj.y_start = -1.0f;
        sj.wall_x  = new float[0];
        sj.wall_y  = new float[0];
        StandJSON[] sj_array = new StandJSON[] { sj };
        SceneData   sd       = new SceneData(sj_array);

        SG = go.AddComponent <SceneGenerator>() as SceneGenerator;
        SG.transform.parent = this.transform;


        SG.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
        SG.GenerateScene(sd);

        shelf_json.boxes[0].cpr = 0.25f;
        shelf_json.boxes[0].cir = 0;
        //shelf_json.boxes[0].cil = 0;

        ShelfGenerator shg = SG.stands[0].shelves[0];

        shg.cubes[0].SetStartingPosition(0, 0.25f);

        /* Camera needs to focus the new object, the position of the new object is not defined till the next
         *  update cycle. Do the camera position update in the next lateupdate */
        camera_pos_needs_update = true;
    }
    private SceneData FromSceneToJSON(List <StandGenerator> s)
    {
        StandJSON[] outData = new StandJSON[s.Count];

        for (int st = 0; st < s.Count; st++)
        {
            outData[st] = s[st].this_stand;

            for (int sh = 0; sh < s[st].shelves.Count; sh++)
            {
                // Each shelf has 1 array with the product data that was extracted from the JSON
                // it also has 1 array list which is the one used and updated
                // TODO this is so confusing, it should be reworked
                outData[st].shelves[sh].boxes = s[st].shelves[sh].cubesJSON.ToArray();
            }
        }
        return(new SceneData(outData));
    }
    public void Initialize(StandJSON s)
    {
        initialized = true;
        this_stand  = s;


        transform.localPosition = Vector3.zero;

        transform.localRotation = Quaternion.identity;
        transform.RotateAround(FindStandCenter().to3DwY(0), Vector3.up, s.y_rotation);

        transform.localPosition += new Vector3(s.x_start, s.y_start, s.z_start);

        shelves = new List <ShelfGenerator>();

        float current_height = 0;

        id2shelf = new Dictionary <int, GameObject>();

        for (int i = 0; i < s.shelves.Length; i++)
        {
            GameObject g = new GameObject("shelf " + i);

            ShelfGenerator SHG = g.AddComponent(typeof(ShelfGenerator)) as ShelfGenerator;

            id2shelf.Add(g.GetInstanceID(), g);

            SHG.transform.SetParent(transform);

            current_height += s.shelves[i].relative_height;
            s.shelves[i].absolute_height = current_height;
            SHG.Initialize(s.shelves[i]);

            shelves.Add(SHG);
        }
        wall = new Vector2[s.wall_x.Length];
        for (int i = 0; i < s.wall_x.Length; i++)
        {
            wall[i] = new Vector2(s.wall_x[i], s.wall_y[i]);
        }

        AddWalls();
        //UpdateColor();
    }