Esempio n. 1
0
    private void UpdateGhostPreview( )
    {
        if (gameobjectInstance == null)
        {
            return;
        }

        gameobjectInstance.SetActive(world.ObjectInsideWorld(GridPos));

        var canbuild     = true;
        var curBlueprint = state.CurrentBlueprint;

        //First check if its inside the world, porbably cheaper
        foreach (var posToCheck in curBlueprint.Positions)
        {
            if (!world.ObjectInsideWorld(curPos + posToCheck))
            {
                canbuild = false;
                break;
            }
        }

        foreach (var posToCheck in curBlueprint.Positions)
        {
            if (world.ObjectAtLocation(curPos + posToCheck))
            {
                canbuild = false;
                break;
            }
        }

        var renderers = gameobjectInstance.GetComponentsInChildren <MeshRenderer>( );

        foreach (var meshRenderer in renderers)
        {
            foreach (var mat in meshRenderer.materials)
            {
                mat.color = canbuild ? Ghostmat.color : ErrorColor;
            }
        }

        gameobjectInstance.transform.position = curPos.pos;
    }