示例#1
0
    public void Test()
    {
        var bounds = RecastBuilder.GetBoundsFromGameObject(gameObject);

        //bounds.Expand(2.0f);
        bounds = RecastBuilder.AlignBounds(bounds);
        bounds.Expand(new Vector3(0, 1.6f, 0));
        voxel = RecastBuilder.Creat(bounds, Size);
        RecastBuilder.AddGameObject(voxel, gameObject);
        Vector3 min = voxel.Bounds.min;

        heightfield = RecastBuilder.VoxelToHeightfield(voxel);
        var bitMask = RecastBuilder.VoxelizationWalkableFilter(voxel);

        if (ValidPoint)
        {
            var        pos       = Vector3Int.CeilToInt((ValidPoint.position - min) / voxel.CellSize);
            Vector2Int pt        = new Vector2Int(pos.x, pos.z);
            Vector2Int size      = new Vector2Int(voxel.Size.x, voxel.Size.z);
            var        validMask = RecastBuilder.CalcClosePoint(bitMask, size, pt);
            gridData = new RecastGridData
            {
                OriginPoint = new Vector3(min.x, min.z),
                Width       = voxel.Size.x,
                Length      = voxel.Size.z,
                Mask        = new SerializBitArray(validMask)
            };
        }
        else
        {
            gridData = RecastBuilder.VoxelizationToGrid(voxel);
        }
    }
示例#2
0
    private void Hit()
    {
        if (_target != null)
        {
            var moveTarget = Vector3.MoveTowards(transform.position, _target.transform.position, _speed * Time.deltaTime);

            var thisTransform = Vector3Int.CeilToInt(transform.position);
            var moveTrgetInt  = Vector3Int.CeilToInt(moveTarget);



            if (moveTrgetInt.x == thisTransform.x && moveTrgetInt.z == thisTransform.z)
            {
                _ai.SetDamage(_damage);
                Destroy(gameObject);
            }
            else
            {
                transform.position = new Vector3(moveTarget.x, transform.position.y, moveTarget.z);
            }
        }

        else
        {
            Destroy(gameObject);
        }
    }
示例#3
0
    private void InitServerState()
    {
        if (flyingDirection == Vector2.zero)
        {
            Debug.LogWarning($"{gameObject.name} move direction unclear");
            serverState.Direction = Vector2.up;
        }
        else
        {
            serverState.Direction = Vector2Int.RoundToInt(flyingDirection);
        }
        initialPosition = Vector3Int.RoundToInt(new Vector3(transform.position.x, transform.position.y, 0));
        var child         = transform.GetChild(0);
        var childPosition = Vector3Int.CeilToInt(new Vector3(child.transform.position.x, child.transform.position.y, 0));

        pivot = initialPosition - childPosition;
        Debug.Log($"Calculated pivot {pivot} for {gameObject.name}");

        serverState.Speed       = 1f;
        serverState.Position    = initialPosition;
        serverState.Orientation = Orientation.Up;
        serverTargetState       = serverState;

        clientState       = serverState;
        clientTargetState = serverState;
    }
示例#4
0
 public Voxelization(Bounds b, float size)
 {
     CellSize = size;
     Bounds   = b;
     Size     = Vector3Int.CeilToInt(b.size / size);
     Voxel    = new ThreeDimensionMask(Size.x, Size.y, Size.z);
 }
示例#5
0
        //[NativeSetThreadIndex]
        //int threadIndex;

        public void FillNoisySphere(World world, uint id, Vector3 o, float r, FastNoiseLite noise, float noiseScale, uint idVariant, float variantRate)
        {
            var rand = new System.Random();

            Vector3Int min = Vector3Int.FloorToInt(o) - Vector3Int.one * Mathf.CeilToInt(r + noiseScale);
            Vector3Int max = Vector3Int.CeilToInt(o) + Vector3Int.one * Mathf.CeilToInt(r + noiseScale);

            for (int x = min.x; x <= max.x; x++)
            {
                for (int y = min.y; y <= max.y; y++)
                {
                    for (int z = min.z; z <= max.z; z++)
                    {
                        if ((new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - o).magnitude <= (r + 0.35f + noise.GetNoise(x * noiseFreq + 3.75f, y * noiseFreq - 18.63f, z * noiseFreq + 1.55f) * noiseScale))
                        {
                            if (rand.NextDouble() < variantRate)
                            {
                                world.SetBlock(new Vector3Int(x, y, z), Block.From32bitColor(idVariant));
                            }
                            else
                            {
                                world.SetBlock(new Vector3Int(x, y, z), Block.From32bitColor(id));
                            }
                        }
                    }
                }
            }
        }
    private Vector3Int GetCellCoordsForMouse()
    {
        Vector3 mousepos     = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 cellPosition = grid.WorldToCell(mousepos);

        return(Vector3Int.CeilToInt(cellPosition));
    }
    public Vector3Int GetTilePositionForWorldPoint(Vector2 wp)
    {
        Vector3 mousepos     = Camera.main.ScreenToWorldPoint(wp);
        Vector3 cellPosition = grid.WorldToCell(mousepos);

        return(Vector3Int.CeilToInt(cellPosition));
    }
示例#8
0
    public void MoveEnemy(GameObject enemy)
    {
        var script        = enemy.GetComponent <EnemyScript>();
        var movementInput = script.MovementPattern;

        if (levelGrid.HasTile(Vector3Int.CeilToInt(enemy.transform.position + movementInput)))
        {
            script.Destination = levelGrid.WorldToCell(enemy.transform.position + movementInput);
        }
        else
        {
            if (levelGrid.HasTile(Vector3Int.CeilToInt(enemy.transform.position) +
                                  new Vector3Int(Mathf.CeilToInt(movementInput.x), 0, 0)))
            {
                enemy.transform.position = new Vector3(enemy.transform.position.x + CellSize,
                                                       enemy.transform.position.y * -1, 0f);
                script.Destination = enemy.transform.position;
                return;
            }
            if (levelGrid.HasTile(Vector3Int.CeilToInt(enemy.transform.position) +
                                  new Vector3Int(0, Mathf.CeilToInt(movementInput.y), 0)))
            {
                enemy.transform.position = new Vector3(enemy.transform.position.x * -1,
                                                       enemy.transform.position.y + CellSize, 0f);
                script.Destination = enemy.transform.position;
            }
        }
    }
示例#9
0
        public static SDFRawData SceneToSDF(GameObject go, Vector3 validPos, int layerMask = -1)
        {
            float cellSize = 0.25f;
            float sdfScale = 0.25f;
            var   bounds   = GetBoundsFromGameObject(go);

            bounds = AlignBounds(bounds);
            var voxel = Creat(bounds, cellSize);

            AddGameObject(voxel, go, layerMask);
            var        heightfield = VoxelToHeightfield(voxel);
            var        grid        = HeightfieldToPlaneGrid(heightfield, 0, 2);
            Vector2Int size        = new Vector2Int(voxel.Size.x, voxel.Size.z);
            var        pos         = Vector3Int.CeilToInt((validPos - voxel.Bounds.min) / voxel.CellSize);

            grid.Mask = CalcClosePoint(grid.Mask, size, new Vector2Int(pos.x, pos.z));

            grid = FilterEdge(grid);
            //生成sdf信息
            sbyte[] data = new sbyte[grid.Width * grid.Length];
            SDFGenerate.Gen(grid.Mask, grid.Width, grid.Length, cellSize, sdfScale, data);
            SDFRawData sdf   = new SDFRawData();
            TSVector2  orign = new TSVector2(grid.OriginPoint.x, grid.OriginPoint.y);

            sdf.Init(grid.Width, grid.Length, cellSize, sdfScale, orign, data);
            return(sdf);
        }
示例#10
0
        // Creates bricks at the coarsest level for all areas that are overlapped by the pass in volume
        private void Rasterize(Volume volume, List <Brick> outBricks)
        {
            Profiler.BeginSample("Rasterize");
            // Calculate bounding box for volume in refvol space
            var AABB = volume.CalculateAABB();

            // Calculate smallest brick size capable of covering shortest AABB dimension
            float minVolumeSize    = Mathf.Min(AABB.size.x, Mathf.Min(AABB.size.y, AABB.size.z));
            int   brickSubDivLevel = Mathf.Min(Mathf.CeilToInt(Mathf.Log(minVolumeSize, 3)), m_MaxSubdivision);
            int   brickTotalSize   = (int)Mathf.Pow(3, brickSubDivLevel);

            // Extend AABB to have origin that lies on a grid point
            AABB.Encapsulate(new Vector3(
                                 brickTotalSize * Mathf.Floor(AABB.min.x / brickTotalSize),
                                 brickTotalSize * Mathf.Floor(AABB.min.y / brickTotalSize),
                                 brickTotalSize * Mathf.Floor(AABB.min.z / brickTotalSize)));

            // Calculate origin of bricks and how many are needed to cover volume
            Vector3Int origin          = Vector3Int.FloorToInt(AABB.min);
            Vector3    logicalBrickRes = Vector3Int.CeilToInt(AABB.size / brickTotalSize);

            // Cover the volume with bricks
            for (int x = 0; x < logicalBrickRes.x; x++)
            {
                for (int y = 0; y < logicalBrickRes.y; y++)
                {
                    for (int z = 0; z < logicalBrickRes.z; z++)
                    {
                        Vector3Int pos = origin + new Vector3Int(x, y, z) * brickTotalSize;
                        outBricks.Add(new Brick(pos, brickSubDivLevel));
                    }
                }
            }
            Profiler.EndSample();
        }
示例#11
0
    public static void FillNoisySphere(World world, uint id, Vector3 o, float r, FastNoiseLite noise, float noiseScale, uint idVariant, float variantRate)
    {
#if PROFILE
        UnityEngine.Profiling.Profiler.BeginSample("TestTree.FillNoisySphere");
#endif
        var rand = new System.Random();

        Vector3Int min = Vector3Int.FloorToInt(o) - Vector3Int.one * Mathf.CeilToInt(r + noiseScale);
        Vector3Int max = Vector3Int.CeilToInt(o) + Vector3Int.one * Mathf.CeilToInt(r + noiseScale);

        for (int x = min.x; x <= max.x; x++)
        {
            for (int y = min.y; y <= max.y; y++)
            {
                for (int z = min.z; z <= max.z; z++)
                {
                    if ((new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - o).magnitude <= (r + 0.35f + noise.GetNoise(x, y, z) * noiseScale))
                    {
                        if (rand.NextDouble() < variantRate)
                        {
                            world.SetBlock(new Vector3Int(x, y, z), Block.From32bitColor(idVariant));
                        }
                        else
                        {
                            world.SetBlock(new Vector3Int(x, y, z), Block.From32bitColor(id));
                        }
                    }
                }
            }
        }

#if PROFILE
        UnityEngine.Profiling.Profiler.EndSample();
#endif
    }
示例#12
0
    private void Awake()
    {
        initialOffset     = Vector3Int.CeilToInt(gameObject.transform.position);
        reactionManager   = GetComponent <ReactionManager>();
        metaDataLayer     = GetComponent <MetaDataLayer>();
        MatrixMove        = GetComponentInParent <MatrixMove>();
        tileChangeManager = GetComponentInParent <TileChangeManager>();


        OnEarthquake.AddListener((worldPos, magnitude) =>
        {
            var cellPos = metaTileMap.WorldToCell(worldPos);

            var bounds =
                new BoundsInt(cellPos - new Vector3Int(magnitude, magnitude, 0), new Vector3Int(magnitude * 2, magnitude * 2, 1));

            foreach (var pos in bounds.allPositionsWithin)
            {
                foreach (var player in Get <PlayerScript>(pos, true))
                {
                    if (player.IsGhost)
                    {
                        continue;
                    }
                    player.registerTile.ServerSlip(true);
                }
                //maybe shake items somehow, too
            }
        });
    }
    public void Initial()
    {
        HackPowerDisplayer                    = GameObject.Find("HackPowerDisplayer");
        choosingXLine                         = Instantiate(choosingXLine);
        choosingXLine.transform.parent        = this.gameObject.transform;
        choosingXLine.transform.localPosition = new Vector3(1, 0, 0);
        choosingYLine                         = Instantiate(choosingYLine);
        choosingYLine.transform.parent        = this.transform;
        choosingYLine.transform.localPosition = new Vector3(0, 1, 0);
        unlockedHorizontals                   = new UnlockedHorizontal[ySize];
        unlockedVerticals                     = new UnlockedVertical[xSize];
        //Array[0]は交差点につき未割当。
        GameObject Lines = new GameObject();

        Lines.transform.parent = this.gameObject.transform;
        Lines.transform.name   = "Lines";

        Referenceosition = Vector3Int.CeilToInt(this.gameObject.transform.position);
        for (int i = 1; i < ySize; i++)
        {
            unlockedHorizontals[i]     = new UnlockedHorizontal();
            unlockedHorizontals[i].HLF =
                Instantiate(HorizontalLineFacility, new Vector3Int(Referenceosition.x, Referenceosition.y + i, 0), Quaternion.identity);
            unlockedHorizontals[i].HLF.gameObject.transform.parent = Lines.transform;
        }
        for (int j = 1; j < xSize; j++)
        {
            unlockedVerticals[j]     = new UnlockedVertical();
            unlockedVerticals[j].VLF =
                Instantiate(VerticalLineFacility, new Vector3Int(Referenceosition.x + j, Referenceosition.y, 0), Quaternion.identity);
            unlockedVerticals[j].VLF.transform.parent = Lines.transform;
        }
    }
示例#14
0
    public void seeDirectionMoving(int d)
    {
        switch (d)
        {
        case 1:
            goToCell = new Vector3Int(currentCell.x - Vector3Int.CeilToInt(myGrid.cellSize).x, currentCell.y, currentCell.z);     //Izquierda
            Player.GetComponent <SpriteRenderer>().sprite = PlayerSprites[2];
            UIGround.GetComponent <DirectionControl>().RotatorDirectionsUIGround(1);
            break;

        case 2:
            goToCell = new Vector3Int(currentCell.x, currentCell.y - Vector3Int.CeilToInt(myGrid.cellSize).y, currentCell.z);     //Abajo
            Player.GetComponent <SpriteRenderer>().sprite = PlayerSprites[0];
            UIGround.GetComponent <DirectionControl>().RotatorDirectionsUIGround(2);
            break;

        case 3:
            goToCell = new Vector3Int(currentCell.x + Vector3Int.CeilToInt(myGrid.cellSize).x, currentCell.y, currentCell.z);     // Derecha
            Player.GetComponent <SpriteRenderer>().sprite = PlayerSprites[3];
            UIGround.GetComponent <DirectionControl>().RotatorDirectionsUIGround(3);

            break;

        case 0:
            goToCell = new Vector3Int(currentCell.x, currentCell.y + Vector3Int.CeilToInt(myGrid.cellSize).y, currentCell.z);     // Arriba
            Player.GetComponent <SpriteRenderer>().sprite = PlayerSprites[1];
            UIGround.GetComponent <DirectionControl>().RotatorDirectionsUIGround(0);
            break;

        default:
            break;
        }
    }
示例#15
0
 private void UnloadChunk(Chunk c)
 {
     chunks.Remove(Vector3Int.CeilToInt(c.position));
     unloadedChunks.Add(Vector3Int.CeilToInt(c.position), c);
     c.gameObject.SetActive(false);
     c.enabled = false;
     //Destroy(c.gameObject);
 }
示例#16
0
 private static void GetMinMax(Bounds bounds, TerrainData terrain, out Vector3Int min, out Vector3Int max)
 {
     min   = Vector3Int.FloorToInt(bounds.min);
     max   = Vector3Int.CeilToInt(bounds.max);
     min.x = Mathf.Max(min.x, 0);
     min.z = Mathf.Max(min.z, 0);
     max.x = Mathf.Min(max.x, terrain.heightmapWidth - 1);
     max.z = Mathf.Min(max.z, terrain.heightmapHeight - 1);
 }
示例#17
0
    // Update is called once per frame
    void Update()
    {
        transform.Translate(Time.deltaTime * speed, 0, 0);

        if (!CookieController.singleton.traversableMap.HasTile(Vector3Int.CeilToInt(gameObject.transform.position)))
        {
            Destroy(gameObject);
        }
    }
示例#18
0
    private void Update()
    {
        if (true)
        {
            LogicTile temp = GameBoard.Instance.GetTileByPos(Vector3Int.CeilToInt(transform.position));
            GameBoard.Instance.FindMovePath(temp, charAttr.Move);

            foreach (LogicTile Lt in GameBoard.Instance.MoveTiles)
            {
            }
        }
    }
示例#19
0
    // Update is called once per frame
    void Update()
    {
        Vector3      screenToWorld = cam.ScreenToWorldPoint(Input.mousePosition);
        RaycastHit2D rayHit        = Physics2D.Raycast(screenToWorld, Vector2.zero);

        //if (map.GetSprite(mousePosition) != null)
        if (rayHit)
        {
            mousePosition = Vector3Int.CeilToInt(new Vector3(rayHit.point.x, rayHit.point.y, 0));
            Debug.Log(mousePosition.ToString() + map.GetSprite(mousePosition).name + map.GetTile(mousePosition).name);
        }
    }
示例#20
0
    private void InitServerState()
    {
        if (flyingDirection == Vector2.zero)
        {
            Logger.LogWarning($"{gameObject.name} move direction unclear", Category.Matrix);
            serverState.Direction = Orientation.Up;
        }
        else
        {
            serverState.Direction = Orientation.From(Vector2Int.RoundToInt(flyingDirection));
        }

        Vector3Int initialPositionInt =
            Vector3Int.RoundToInt(new Vector3(transform.position.x, transform.position.y, 0));

        initialPosition = initialPositionInt;
        InitialPos      = initialPosition.RoundToInt();
        //initialOrientation = Orientation.From( serverState.Direction );
        serverState.initialOrientation = serverState.Direction;

        var child = transform.GetChild(0);

        MatrixInfo = MatrixManager.Get(child.gameObject);
        var childPosition = Vector3Int.CeilToInt(new Vector3(child.transform.position.x, child.transform.position.y, 0));

        pivot = initialPosition - childPosition;
        Pivot = pivot.RoundToInt();

        Logger.LogTraceFormat("{0}: pivot={1} initialPos={2}, initialOrientation={3}", Category.Matrix, gameObject.name,
                              pivot, initialPositionInt, serverState.initialOrientation);
        serverState.Speed       = 1f;
        serverState.Position    = initialPosition;
        serverState.orientation = serverState.initialOrientation;
        serverTargetState       = serverState;

        clientState       = serverState;
        clientTargetState = serverState;
        if (SensorPositions == null)
        {
            CollisionSensor[] sensors = GetComponentsInChildren <CollisionSensor>();
            if (sensors.Length == 0)
            {
                SensorPositions = new Vector3Int[0];
                return;
            }

            SensorPositions = sensors.Select(sensor => Vector3Int.RoundToInt(sensor.transform.localPosition)).ToArray();

            Logger.Log($"Initialized sensors at {string.Join(",", SensorPositions)}," +
                       $" direction is {State.Direction}", Category.Matrix);
        }
    }
示例#21
0
    public void AdvanceStage()
    {
        if (IsDieing)
        {
            return;
        }

        var directionToPlayer = Vector3Int.CeilToInt(_target.transform.position - transform.position);

        directionToPlayer.Clamp(new Vector3Int(-1, -1, -1), Vector3Int.one);

        Move(new Vector2Int(directionToPlayer.x, directionToPlayer.y));
    }
示例#22
0
    public Color GetGripColorAt(Vector3 position)
    {
        Sprite    tileSprite = gripTilemap.GetSprite(Vector3Int.CeilToInt(position - new Vector3(1, 1, 0)));
        Texture2D tileTex    = TextureFromSprite(tileSprite);

        tileTex.name = "tileTex";
        float xcoord     = position.x - (int)position.x;
        float ycoord     = position.y - (int)position.y;
        Color pointColor = tileTex.GetPixel((int)(32 - xcoord * -32), (int)(32 - ycoord * -32));

        Debug.DrawRay(position, Vector3.forward, pointColor);
        Destroy(tileTex);
        return(pointColor);
    }
示例#23
0
    private void ComputeBoundsFromLayers()
    {
        _mapBounds = new BoundsInt();

        foreach (Tilemap layer in _tilemapLayers)
        {
            layer.CompressBounds();
            _mapBounds.min = Vector3Int.Min(layer.cellBounds.min, _mapBounds.min);
            _mapBounds.max = Vector3Int.Max(layer.cellBounds.max, _mapBounds.max);
        }

        _mapBounds.min += Vector3Int.FloorToInt(transform.position);
        _mapBounds.max += Vector3Int.CeilToInt(transform.position);
    }
示例#24
0
    private void AddWallPositionToList(Vector3 wallPosition, List <Vector3Int> wallList, List <Vector3Int> doorList)
    {
        Vector3Int point = Vector3Int.CeilToInt(wallPosition);

        if (wallList.Contains(point))
        {
            doorList.Add(point);
            wallList.Remove(point);
        }
        else
        {
            wallList.Add(point);
        }
    }
示例#25
0
    public static bool AddBlock(RaycastHit hit, Block block)
    {
        Chunk chunk = hit.collider.GetComponent <Chunk>();

        if (chunk == null)
        {
            return(false);
        }
        Vector3Int pos = GetBlockPos(hit);

        pos += Vector3Int.CeilToInt(hit.normal);
        chunk.World.SetBlock(pos.x, pos.y, pos.z, block);
        return(true);
    }
示例#26
0
    private void Awake()
    {
        metaTileMap = GetComponent <MetaTileMap>();
        if (metaTileMap == null)
        {
            Logger.LogError($"MetaTileMap was null on {gameObject.name}");
        }

        networkedMatrix   = transform.parent.GetComponent <NetworkedMatrix>();
        initialOffset     = Vector3Int.CeilToInt(gameObject.transform.position);
        reactionManager   = GetComponent <ReactionManager>();
        metaDataLayer     = GetComponent <MetaDataLayer>();
        MatrixMove        = GetComponentInParent <MatrixMove>();
        tileChangeManager = GetComponentInParent <TileChangeManager>();
        underFloorLayer   = GetComponentInChildren <UnderFloorLayer>();
        tilemapsDamage    = GetComponentsInChildren <TilemapDamage>().ToList();

        if (MatrixManager.Instance.InitializingMatrixes.ContainsKey(gameObject.scene) == false)
        {
            MatrixManager.Instance.InitializingMatrixes.Add(gameObject.scene, new List <Matrix>());
        }
        MatrixManager.Instance.InitializingMatrixes[gameObject.scene].Add(this);


        OnEarthquake.AddListener((worldPos, magnitude) =>
        {
            var cellPos = metaTileMap.WorldToCell(worldPos);

            var bounds =
                new BoundsInt(cellPos - new Vector3Int(magnitude, magnitude, 0),
                              new Vector3Int(magnitude * 2, magnitude * 2, 1));

            foreach (var pos in bounds.allPositionsWithin)
            {
                foreach (var player in Get <PlayerScript>(pos, true))
                {
                    if (player.IsGhost)
                    {
                        continue;
                    }

                    player.registerTile.ServerSlip(true);
                }

                //maybe shake items somehow, too
            }
        });
    }
示例#27
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Vector3 vec = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         pathfinding.grid.GetXY(vec, out int x, out int y);
         List <PathNode> path = pathfinding.FindPath(Vector3Int.CeilToInt(player.position).x, Vector3Int.CeilToInt(player.position).y, x, y);
         if (path != null)
         {
             for (int i = 0; i < path.Count - 1; i++)
             {
                 Debug.DrawLine(new Vector3(path[i].X, path[i].Y), new Vector3(path[i + 1].X, path[i + 1].Y), Color.red, 5000f);
             }
         }
     }
 }
示例#28
0
    void Look()
    {
        transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * RotateSpeed);
        Eye.Rotate(Vector3.left * Input.GetAxis("Mouse Y") * RotateSpeed);

        RaycastHit hit;

        if (Physics.Raycast(Eye.position, Eye.forward, out hit, 10f))
        {
            if (!(lookingObject == hit.collider.gameObject))
            {
                ClearLookingObject();

                lookingObject = hit.collider.gameObject;
                var mesh = lookingObject.GetComponent <MeshRenderer>();
                if (mesh != null)
                {
                    var block = new MaterialPropertyBlock();
                    block.SetColor("_Color", new Color(0.4f, 0.4f, 0.4f, 1));
                    mesh.SetPropertyBlock(block);
                }
            }

            if (Input.GetButtonDown("Punch"))
            {
                Chunk.SetBlock("unicraft:air", LookingBlock.Location);
            }

            if (Input.GetButtonDown("Interact"))
            {
                BlockBase bl;
                if ((bl = BlockRegister.Instance[LookingBlock.BlockId]) is IInteractable)
                {
                    (bl as IInteractable).OnInteract(LookingBlock.Location, this);
                }
                else
                {
                    var candidate = Vector3Int.CeilToInt(LookingBlock.Location + hit.normal);
                    Chunk.SetBlock(UniCraft.BlockIdInHand, candidate);
                }
            }
        }
        else
        {
            ClearLookingObject();
        }
    }
    private void Update()
    {
        float axisHorizontal = Input.GetAxisRaw("Horizontal");
        float axisVertical   = Input.GetAxisRaw("Vertical");

        if (axisVertical == 1)
        {
            inputDirection = Vector2.up;
        }
        else if (axisVertical == -1)
        {
            inputDirection = Vector2.down;
        }
        else if (axisHorizontal == 1)
        {
            inputDirection = Vector2.right;
        }
        else if (axisHorizontal == -1)
        {
            inputDirection = Vector2.left;
        }

        Vector3Int inputNextCell = gridPosition + Vector3Int.CeilToInt((Vector3)inputDirection);
        bool       canTurn       = maze.CanMove(inputNextCell);

        if (canTurn)
        {
            direction = inputDirection;
        }

        Vector3Int nextCell = gridPosition + Vector3Int.CeilToInt((Vector3)direction);
        bool       canMove  = maze.CanMove(nextCell);

        if (canMove)
        {
            Move();
        }

        gridPosition = maze.grid.WorldToCell(transform.position);

        bool centering = Centering(canMove);

        moving = canMove || centering;
        anim.SetBool("moving", moving);

        DectectCollisions();
    }
示例#30
0
    // check player fire cell for injured or die ai ship
    void CheckFireCell(RaycastHit hit)
    {
        if (hit.collider.CompareTag("Ship"))
        {
            aSource.PlayOneShot(audioManager.ship);

            GameObject shipInjured = Instantiate(hitShip);
            shipInjured.transform.position = Vector3Int.RoundToInt(hit.collider.transform.position);
            shipInjured.transform.SetParent(otherPlayerFeildData.transform);
            shipInjured.transform.localPosition = Vector3Int.CeilToInt(shipInjured.transform.localPosition);

            hit.collider.GetComponentInChildren <MeshRenderer>().enabled = true;

            var ship = otherPlayerFeildData.Ships.Find(x => x.go == hit.collider.transform.parent.gameObject);
            ship.status = PlayerField.shipStatus.Injured;

            // check ship status
            if (CheckShipDie(hit.collider.transform.parent))
            {
                aSource.PlayOneShot(audioManager.ship);

                hit.collider.transform.parent.position -= new Vector3(0, 0.2f, 0);
                // set die in playerfield
                ship.status = PlayerField.shipStatus.Die;
                Debug.Log("ship " + ship.go.name + " " + ship.status);
                otherPlayerFeildData.CheckGameStatus();
            }
        }
        if (hit.collider.CompareTag("Field"))
        {
            // check fire in place
            var checkCell = Vector3Int.RoundToInt(hit.point);

            if (!CheckFire(checkCell))
            {
                aSource.PlayOneShot(audioManager.empty);

                GameObject fire = Instantiate(cross);
                fire.transform.localPosition = checkCell + new Vector3(0, -1f, 0);
                fire.transform.SetParent(otherPlayerFeildData.transform);
                fire.transform.localPosition = Vector3Int.CeilToInt(fire.transform.localPosition);
            }
            playerCanShot = false;
        }
    }