public void ExecOnItemAttachedCallbacks(StandGenerator stand, ShelfGenerator shelf, Drag3D cube)
 {
     foreach (OnItemAttachedCallback f in onItemAttachedCallBacks)
     {
         f(stand, shelf, cube, childs_selected.ToArray());
     }
 }
 public void ExecOnChildProductClickedCallbacks(StandGenerator stg, ShelfGenerator shg, bool[] selected)
 {
     foreach (OnChildProductClickedCallback f in onChildProductClickedCallBacks)
     {
         f(stg, shg, selected);
     }
 }
    public void OnProductClickedInSimulation(StandGenerator stand, ShelfGenerator shelf, bool[] selected)
    {
        int stand_index = standList.IndexOf(stand);
        int shelf_index = standList[stand_index].shelves.IndexOf(shelf);

        _UIController.UpdateUIState(stand_index, shelf_index, selected, true);
    }
    public void OnProdcutRemovedFromShelf(StandGenerator stand, ShelfGenerator shelf, Drag3D cube, bool[] selected)
    {
        // When a product is added or removed from a shelf we should update the UI
        // To avoid any (out of bounds) errors and dislpaying incorrect information

        if (stand == _UIController.standList[_UIController.stand_dropdown_index] &&
            shelf == _UIController.standList[_UIController.stand_dropdown_index].shelves[_UIController.shelf_dropdown_index])
        {
            _UIController.UpdateUIState(_UIController.stand_dropdown_index, _UIController.shelf_dropdown_index, selected, true, true);
        }
    }
    public void ClearSelected()
    {
        selected = false;
        UpdateColor();

        if (child_selected != null)
        {
            child_selected.ClearSelected();
            child_selected = null;
        }
    }
    public void OnShelfClicked(ShelfGenerator shg, StandGenerator stg)
    {
        int standIndex = _UIController.standList.IndexOf(stg);
        int shelfIndex = _UIController.standList[standIndex].shelves.IndexOf(shg);

        int len = _UIController.standList[standIndex].shelves[shelfIndex].cubes.Count;

        bool[] sel = UIController.GetSelectedArray(new int[] {}, len);

        _UIController.UpdateUIState(standIndex, shelfIndex, sel, true, false);
    }
Ejemplo n.º 7
0
 public void OnCollisionEnter(Collision collision)
 {
     if (deattached && selected)
     {
         ShelfGenerator sg = collision.collider.gameObject.GetComponent <ShelfGenerator>();
         if (sg != null || sg != floatingObj.floatingProdOrigShelf)
         {
             ReAttach(sg);
         }
     }
 }
Ejemplo n.º 8
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;
    }
Ejemplo n.º 9
0
    public void OnPointerDown(PointerEventData pointerEventData)
    {
        ShelfGenerator shg = transform.GetComponentInParent <ShelfGenerator>();

        if (shg != null)
        {
            shg.OnMeshClicked();
        }
        else
        {
            Debug.LogError("Could not find shelf generator attached to this mesh");
        }
    }
Ejemplo n.º 10
0
    public void ReAttach(ShelfGenerator sg = null)
    {
        FloatingProducts fp = transform.GetComponentInParent <FloatingProducts>();

        if (fp != null)
        {
            this.deattached = false;
            fp.ReAttach(sg);
        }
        else
        {
            Debug.LogError("Attempting to re-attach without beeing in floating products");
        }
    }
    public void OnProductAddedToShelf(StandGenerator stand, ShelfGenerator shelf, Drag3D cube, bool[] selected)
    {
        //if (stand == _UIController.standList[_UIController.stand_dropdown_index] &&
        //shelf == _UIController.standList[_UIController.stand_dropdown_index].shelves[_UIController.shelf_dropdown_index])
        {
            int stand_idx = _UIController.standList.IndexOf(stand);
            int shelf_idx = _UIController.standList[stand_idx].shelves.IndexOf(shelf);

            //int len = _UIController.standList[stand_idx].shelves[shelf_idx].cubes.Count;
            //bool[] sel = UIController.GetSelectedArray( new int[]{len-1}, len);

            _UIController.UpdateUIState(stand_idx, shelf_idx, selected, true, true);
        }
    }
    // Selection handling //
    public void OnChildShelfSelected(ShelfGenerator shg)
    {
        if (!selected)
        {
            SetSelected();
        }

        // Clear previously selected child
        if (child_selected != null && child_selected != shg)
        {
            child_selected.ClearSelected();
        }
        child_selected = shg;
    }
Ejemplo n.º 13
0
    public CollisionMap2(Drag3D[] c, DragLines _draglines, ShelfGenerator parent)
    {
        cubes         = c;
        draglines     = _draglines;
        SG            = parent;
        collisionNote = new Dictionary <int, List <int> >();

        for (int i = 0; i < c.Length; i++)
        {
            collisionNote.Add(c[i].gameObject.GetInstanceID(), new List <int>());
        }

        for (int p = 0; p < cubes.Length; p++)
        {
            UpdateCollisionMap(cubes[p]);
        }
    }
    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();
    }
Ejemplo n.º 15
0
    public bool AddFloatingProduct(Drag3D fp, ShelfGenerator shg, StandGenerator sg)
    {
        // Only 1 product at a time
        if (floatingProduct != null)
        {
            return(false);
        }

        floatingProduct       = fp;
        floatingPordOrigStand = sg;
        floatingProdOrigShelf = shg;

        // Transfer the parenthood form the shg to this
        // Move to the same position as the shelf generator so the position of the product is not alterd
        transform.localPosition = shg.transform.localPosition;
        fp.transform.parent     = this.transform;

        return(true);
    }
Ejemplo n.º 16
0
    public void ReAttach(ShelfGenerator sg = null)
    {
        ShelfGenerator target_shelf = sg == null ? floatingProdOrigShelf : sg;

        floatingProduct.deattached = false;

        if (target_shelf == floatingProdOrigShelf)
        {
            target_shelf.AttachProduct(floatingProduct.box, floatingProduct.gameObject);
        }
        else
        {
            target_shelf.AttachProduct2(floatingProduct.box, floatingProduct.gameObject);
        }

        if (sg != null)
        {
            floatingProduct.ReturnToLastValidPosition();
        }

        floatingProduct = null;
    }
 //TODO Not the way it should work ... Initialize should asume a clean state
 public void Initialize(List <StandGenerator> standList)
 {
     this.standList = standList;
     if (standList != null)
     {
         foreach (StandGenerator sg in standList)
         {
             foreach (Transform sh in sg.transform)
             {
                 ShelfGenerator shg = sh.gameObject.GetComponent <ShelfGenerator>();
                 if (shg == null)
                 {
                     continue;
                 }
                 shg.RegisterOnItemAttachedCallback(OnProductAddedToShelf);
                 shg.RegisterOnItemDeattachedCallback(OnProdcutRemovedFromShelf);
                 shg.RegisterOnShelfClickedCallback(OnShelfClicked);
                 shg.RegisterOnChildProductClickedCallback(OnProductClickedInSimulation);
             }
         }
     }
 }
Ejemplo n.º 18
0
 public void BindToParent(ShelfGenerator _SG)
 {
     this.transform.parent = _SG.gameObject.transform;
     SG = _SG;
 }