Example #1
0
    public void OnSpawnBoxInitially(Box box, BoxPlacement placement)
    {
        box.PlacedOnShelf(this);
        boxesInShelf.Add(box, placement);

        SetBoxInSlots(box, placement, true);
    }
Example #2
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Pickupable")
        {
            var box = other.gameObject.GetComponent <Box>();

            // if (!boxesInShelf.Contains(box)) {
            if (!boxesInShelf.ContainsKey(box))
            {
                box.PlacedOnShelf(this);
                var placement = new BoxPlacement();
                GuessSlotFromGameObject(box, placement);
                boxesInShelf.Add(box, placement);

                SetBoxInSlots(box, placement, true);

                /*	if (box.InShelf) {
                 *              SetBoxInSlots(box, true);
                 *      } else {
                 *              Debug.LogError("This box is currently not in a shelf");
                 *              var slot = GuessSlotFromGameObject(box);
                 *              SetBoxInSlots(box, true);
                 *      }*/
                // }
            }
        }
    }
Example #3
0
    private void spawnQuadBox(int x, int y, int referenceCount)
    {
        var box = GameObject.Instantiate(QuadBoxPrefab, transform.position + transform.rotation * new Vector3(x + QuadBoxOffsetX, y, 0), transform.rotation).GetComponent <Box>();

        /*box.InShelf = true;
        *  box.ShelfSlotX = 4 * x;
        *  box.ShelfSlotY = y;*/
        box.Type     = Box.BoxType.Quad;
        box.Variable = CreateVariable(10, referenceCount);
        var placement = new BoxPlacement();

        placement.SlotX = x;
        placement.SlotY = y;
        boxesInShelfManager.OnSpawnBoxInitially(box, placement);
    }
Example #4
0
    private void SetBoxInSlots(Box box, BoxPlacement placement, bool content)
    {
        switch (box.Type)
        {
        case Box.BoxType.Single:
            SetSlot(placement.SlotX, placement.SlotY, box, content);
            break;

        case Box.BoxType.Double:
            SetSlot(placement.SlotX, placement.SlotY, box, content);
            SetSlot(placement.SlotX + 1, placement.SlotY, box, content);
            break;

        case Box.BoxType.Quad:
            SetSlot(placement.SlotX, placement.SlotY, box, content);
            SetSlot(placement.SlotX + 1, placement.SlotY, box, content);
            SetSlot(placement.SlotX + 2, placement.SlotY, box, content);
            SetSlot(placement.SlotX + 3, placement.SlotY, box, content);
            break;
        }
    }
Example #5
0
    private int GuessSlotFromGameObject(Box box, BoxPlacement placement)
    {
        // TODO: handle rotation
        var localPosition = gameObject.transform.rotation * (box.transform.position - gameObject.transform.position);

        var x        = 0;
        var boxWidth = 0;

        switch (box.Type)
        {
        case Box.BoxType.Single:
            x        = (int)(localPosition.x - SingleBoxOffsetX + 0.5f);
            boxWidth = 1;
            break;

        case Box.BoxType.Double:
            x        = (int)(localPosition.x - DoubleBoxOffsetX + 0.5f);
            boxWidth = 2;
            break;

        case Box.BoxType.Quad:
            x        = (int)(localPosition.x - QuadBoxOffsetX + 0.5f);
            boxWidth = 4;
            break;
        }



        var y = (int)(localPosition.y + 0.5);

        x = Mathf.Clamp(x, 0, Width - boxWidth);
        y = Mathf.Clamp(y, 0, Height - 1);

        placement.SlotX = x;
        placement.SlotY = y;

        // Debug.Log("Guessed: " + x + ", "+ y + "  | " + localPosition);
        return(x + y * Width);
    }
Example #6
0
    void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Pickupable")
        {
            var box = other.gameObject.GetComponent <Box>();
            box.RemovedFromShelf(this);
            BoxPlacement placement = boxesInShelf[box];
            boxesInShelf.Remove(box);
            SetBoxInSlots(box, placement, false);

            /*if (box.InShelf) {
             *      SetBoxInSlots(box, false);
             * } else {
             *      // Should never happen (?)
             *      Debug.LogError("This box is currently not in a shelf");
             *      // var slot = GuessSlotFromGameObject(other.gameObject);
             *      // areSlotsFull[slot] = false;
             * }
             *
             * box.InShelf = false;*/
        }
    }