示例#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);
    }
示例#2
0
    private void Build(string name) // only to be invoked by BuildObject()
    {
        if (!placingObject && objMap[name] != null)
        {
            currPlacingObject      = Instantiate(objMap[name]);
            currPlacingObject.name = name;
            CommonProperties common = currPlacingObject.GetComponent <CommonProperties>();
            common.SetTransparency(0.2f, BlendMode.Transparent);
            common.SetColliderEnabled(false);
            common.InitMats();

            if (debugCubeEnabled)
            {
                int diff = debugCubeCount - common.GetFootprint().Count;
                if (diff > 0)
                {
                    for (int i = 0; i < diff; i++)
                    {
                        GameObject g = debugCubeContainer.transform.GetChild(0).gameObject;
                        g.SetActive(false);
                        Destroy(g);
                        debugCubeCount--;
                    }
                }
                else if (diff < 0)
                {
                    for (int i = 0; i < -diff; i++)
                    {
                        GameObject g = Instantiate(debugCube, Vector3.zero, Quaternion.identity, debugCubeContainer.transform);
                        debugCubeCount++;
                    }
                }
            }


            placingObject = true;
        }
    }
示例#3
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);
            }
        }
    }