Exemplo n.º 1
0
    private bool ValidatePlacement(Vector3 gridPosition)
    {
        CommonProperties common = currPlacingObject.GetComponent <CommonProperties>();

        if (common.GetFootprint().Count == 0)
        {
            return(false);
        }
        List <Vector3> adjustedFootprint = AdjustFootprint(common.GetFootprint(), common.GetFacing());

        for (int i = 0; i < adjustedFootprint.Count; i++)
        {
            Vector3 relativePosition = adjustedFootprint[i];

            Vector3 exactPosition = 10 * relativePosition + gridPosition;
            if (debugCubeEnabled)
            {
                debugCubeContainer.transform.GetChild(i).transform.position = exactPosition;
            }


            if (world.GridSpaceExists(exactPosition) || Utils.RoundToNearestTen(player.transform.position) == exactPosition)
            {
                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 2
0
    public void OnLMB(InputAction.CallbackContext context)
    {
        LMB = context.ReadValue <float>() == 1;
        if (snapped && LMB && context.started && placingObject && !(world.GridSpaceExists(placingObjPos)))
        {
            if (currPlacingObject.GetComponents <IActivatable>().Length != 0)
            {
                currPlacingObject.GetComponents <IActivatable>()[0].Activate();
            }

            placingObject                      = false;
            currPlacingObject.layer            = 7;
            currPlacingObject.transform.parent = blockContainer.transform;

            CommonProperties common = currPlacingObject.GetComponent <CommonProperties>();

            foreach (Vector3 relPos in AdjustFootprint(common.GetFootprint(), common.GetFacing())) //get adjusted footprint of placing object and add world positions to worldGrid
            {
                world.AddSpace(new GridSpace(placingObjPos + 10 * relPos, currPlacingObject));
            }

            common.SetTransparency(1f, BlendMode.Opaque);
            common.ResetTintColor();
            common.SetColliderEnabled(true);

            if (streakPlaceName == "")
            {
                currPlacingObject = null;
            }
            else
            {
                Direction dir = common.GetFacing();
                currPlacingObject = null;
                BuildObject(streakPlaceName, true, dir);
            }
        }
    }