Exemplo n.º 1
0
    void CheckAvailableCreation()
    {
        Vector2    createPosition;
        Collider2D col;

        if (col = Physics2D.OverlapPoint(gizmoTile.transform.position, roomLayer))
        {
            Vector2    center         = col.gameObject.transform.position;
            RoomGrid   rg             = col.gameObject.GetComponent <RoomGrid>();
            GameObject candidate      = currentTabList[tileSelectedID];
            Transform  editorHitTrans = candidate.transform.Find("EditorHitbox");
            if (editorHitTrans != null)
            {
                GameObject    candidateHitbox = editorHitTrans.gameObject;
                BoxCollider2D c2d             = candidateHitbox.GetComponent <BoxCollider2D>();
                Rect          candidateRect;
                if (horizontal)
                {
                    candidateRect = new Rect(gizmoTile.transform.position.x - (c2d.size.x / 2),
                                             gizmoTile.transform.position.y + (c2d.size.y / 2),
                                             c2d.size.x,
                                             c2d.size.y);
                }
                else
                {
                    candidateRect = new Rect(gizmoTile.transform.position.x - (c2d.size.y / 2),
                                             gizmoTile.transform.position.y + (c2d.size.x / 2),
                                             c2d.size.y,
                                             c2d.size.x);
                }

                if (rg.CheckAvailableBlocks(candidateRect, selectedItemTab, center, out createPosition))
                {
                    AddTileToScene(createPosition, rg);
                }
            }
        }
    }