Пример #1
0
    private void _OnClick()
    {
        Vector3    world   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3Int cellPos = tileMap.WorldToCell(world);
        Vector2Int pos     = TileMapUtil.CovertTileMapPosToDataPos(new Vector2Int(cellPos.x, cellPos.y));

        if (TileMapUtil.IsTileOfType <SwitchableTile>(tileMap, cellPos) && !clickCheckboard[pos.x, pos.y])
        {
            int     num      = nowCheckboard[pos.x, pos.y];
            Vector3 worldPos = tileMap.CellToWorld(cellPos) + new Vector3(0.5f, 0.5f, 0);
            clickCheckboard[pos.x, pos.y] = true;
            GameObject icon;
            if (TileMapUtil.IsHead(num))
            {
                GameObject head = Instantiate(Head);
                head.transform.position = worldPos;
                icon = head;
            }
            else if (TileMapUtil.IsBody(num))
            {
                GameObject body = Instantiate(Body);
                body.transform.position = worldPos;
                icon = body;
            }
            else
            {
                GameObject missing = Instantiate(Missing);
                missing.transform.position = worldPos;
                icon = missing;
            }

            TileMapUtil.SortBattleIcon(icon);
            allyGrid.OnRecevie(pos);
        }
    }
Пример #2
0
 private void _OnUp()
 {
     if (CanMovePlane)
     {
         TileMapUtil.SetPlanePos(movePlane, tileMap);
     }
 }
Пример #3
0
    public void Start()
    {
        checkerboard = new int[row, col];

        Plane plane = Instantiate(objectPlane);

        plane.centerPos = new Vector2Int(5, 6);

        Plane plane1 = Instantiate(objectPlane);

        plane1.centerPos = new Vector2Int(1, 2);

        Plane plane2 = Instantiate(objectPlane);

        plane2.centerPos = new Vector2Int(2, 7);
        plane2.toward    = PlaneToward.Right;

        planes.Add(plane);
        planes.Add(plane1);
        planes.Add(plane2);

        foreach (Plane p in planes)
        {
            p.RefreshData(checkerboard, new Vector2Int(0, 0));
            TileMapUtil.SetPlanePos(p, tileMap);
        }
        TileMapUtil.Draw(tileMap, checkerboard, planeTile, wallTile);
    }
Пример #4
0
    /// <summary>
    /// Gets the cursor's current tile data.
    /// This will only return it if it's new.
    /// </summary>
    /// <returns>The cursor tile data.</returns>
    protected TileData GetCursorCurrentTileData()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (tileMap.GetComponent <Collider> ().Raycast(ray, out hitInfo, Mathf.Infinity))
        {
            // Get hit point on tile map coordinates
            Vector3 tileMapPoint = TileMapUtil.WorldCenteredToTileMap(hitInfo.point, tileMap.TileSize);

            // Don't run if still on the same tile
            if ((controller.CurrentTileCoordinates.x != tileMapPoint.x || controller.CurrentTileCoordinates.z != tileMapPoint.z) && GetCursorConditionalImpl(tileMapPoint))
            {
                Vector3 tmp = controller.CurrentTileCoordinates;
                tmp.x = tileMapPoint.x;
                tmp.z = tileMapPoint.z;
                controller.CurrentTileCoordinates = tmp;

                TileData tileData = tileMap.GetTileMapData().GetTileDataAt(tileMapPoint);

                return(tileData);
            }
        }
        return(null);
    }
    /// <summary>
    /// Highlight this instance.
    /// </summary>
    public void Highlight(bool activateTurnOrderUnitStats)
    {
        Unit.Highlight();
        _image.color = Unit.SelectedColor;
        StartCoroutine(ScaleComponentUp());

        if (activateTurnOrderUnitStats)
        {
            _turnOrderController.ActivateTurnOrderUnitStatus(Unit);
        }

        // If there is a deferred ability, target all units targeted by the ability
        if (Unit.HasDeferredAbility)
        {
            foreach (var unit in Unit.Action.Targets)
            {
                _turnOrderController.TargetUnitImage(unit);
                unit.Highlight();
                unit.TileHighlighter.HighlightAttackTile(unit, unit.Tile.x, unit.Tile.z);
            }
        }
        else
        {
            Unit.TileHighlighter.HighlightTiles(Unit, TileMapUtil.WorldCenteredToTileMap(Unit.transform.position, _tileMap.TileSize));
        }
    }
Пример #6
0
    /// <summary>
    /// Raises the key down escape event.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">E.</param>
    protected override void OnKeyDownEscape(object sender, InfoEventArgs <KeyCode> e)
    {
        if (controller.UnitMenuController.IsActive())
        {
            return;
        }

        nextUnitInLine.Unselect();

        // If the cursor is over the unit, re-highlight the tiles, otherwise, remove highlight from tiles and unit
        Vector3 tileSelectorPosition = TileMapUtil.WorldCenteredToTileMap(selectionIcon.position, tileMap.TileSize);
        Vector3 unitPosition         = nextUnitInLine.Tile;

        if (tileSelectorPosition == unitPosition)
        {
            tileHighlighter.HighlightTiles(nextUnitInLine, nextUnitInLine.Tile);
        }
        else
        {
            tileHighlighter.RemoveHighlightedTiles();
            nextUnitInLine.Dehighlight();
        }

        controller.ChangeState <PlayerTurnState> ();
    }
Пример #7
0
    public void OnRecevie(Vector2Int pos)
    {
        Vector2Int cell    = TileMapUtil.CovertDataPosToTileMapPos(pos);
        Vector3Int cellPos = new Vector3Int(cell.x, cell.y, 0);

        if (TileMapUtil.IsTileOfType <TileBase>(tileMap, cellPos))
        {
            int     num      = nowCheckboard[pos.x, pos.y];
            Vector3 worldPos = tileMap.CellToWorld(cellPos) + new Vector3(0.5f, 0.5f, 0) * 0.5f;

            GameObject icon;
            if (TileMapUtil.IsHead(num))
            {
                GameObject head = Instantiate(Head);
                head.transform.position = worldPos;
                icon = head;
            }
            else if (TileMapUtil.IsBody(num))
            {
                GameObject body = Instantiate(Body);
                body.transform.position = worldPos;
                icon = body;
            }
            else
            {
                GameObject missing = Instantiate(Missing);
                missing.transform.position = worldPos;
                icon = missing;
            }
            icon.transform.localScale = 0.5f * icon.transform.localScale;
            TileMapUtil.SortBattleIcon(icon);
        }
    }
Пример #8
0
    private void Start()
    {
        nowCheckboard = TileMapUtil.testAllyCheckboard;

        List <Vector2Int> heads = new List <Vector2Int>();

        for (int i = 0; i < nowCheckboard.GetLength(0); i++)
        {
            for (int j = 0; j < nowCheckboard.GetLength(1); j++)
            {
                if (nowCheckboard[i, j] == TileMapUtil.headNum)
                {
                    heads.Add(new Vector2Int(i, j));
                }
            }
        }

        foreach (Vector2Int head in heads)
        {
            Plane plane = Instantiate(objectPlane);
            plane.CalculateCenterPosAndToward(head, nowCheckboard);
            plane.ScaleParam = 0.5f;
            plane.RotatePlane();
            TileMapUtil.SetPlanePos(plane, tileMap);
            plane.transform.localScale = 0.5f * plane.transform.localScale;

            planes.Add(plane);
        }

        TileMapUtil.Draw(tileMap, nowCheckboard, planeTile, wallTile);
    }
    /// <summary>
    /// Moves a unit across x tiles.
    /// </summary>
    private IEnumerator MoveToTiles()
    {
        Vector3 oldTile = _pathfinder.GetGeneratedPathAt(0);
        Vector3 newTile = Vector3.zero;
        int     index   = 0;

        while (_pathfinder.GetGeneratedPath() != null && index < _pathfinder.GetGeneratedPath().Count - 1)
        {
            newTile = _pathfinder.GetGeneratedPathAt(index + 1);
            Vector3 startingPosition = TileMapUtil.TileMapToWorldCentered(_pathfinder.GetGeneratedPathAt(index), tileMap.TileSize);
            Vector3 endingPosition   = TileMapUtil.TileMapToWorldCentered(newTile, tileMap.TileSize);

            yield return(StartCoroutine(MoveToTile(controller.HighlightedUnit, startingPosition, endingPosition)));

            index++;
            yield return(null);
        }
        _pathfinder.Clear();

        // After move is finished, swap out tile unit is standing on
        if (!TileMapUtil.IsInvalidTile(oldTile))
        {
            TileMapData tileMapData = tileMap.GetTileMapData();
            TileData    oldTileData = tileMapData.GetTileDataAt(oldTile);
            oldTileData.SwapUnits(tileMapData.GetTileDataAt(newTile));
            controller.HighlightedUnit.Tile = newTile;
        }
        yield break;
    }
 /// <summary>
 /// Discovers the tile in range after some validation.
 /// </summary>
 /// <param name="x">The x coordinate.</param>
 /// <param name="z">The z coordinate.</param>
 private void DiscoverTileInRange(int x, int z)
 {
     // Don't go out of boundary
     if (TileMapUtil.IsInsideTileMapBoundary(_tileMapData, x, z))
     {
         _discoveredTiles.Add(new Vector3(x, 0, z), null);
     }
 }
Пример #11
0
 /// <summary>
 /// Gets the generated path at the specified index;
 /// </summary>
 /// <returns>The generated path at the specified index.</returns>
 /// <param name="index">Index.</param>
 public Vector3 GetGeneratedPathAt(int index)
 {
     if (_generatedPath == null || _generatedPath.Count <= 0)
     {
         return(TileMapUtil.GetInvalidTile());
     }
     return(new Vector3(_generatedPath[index].x, 0, _generatedPath[index].z));
 }
Пример #12
0
    // 根据坐标获得一个节点
    public NodeItem getItem(Vector2 position)
    {
        int x;
        int y;

        TileMapUtil.GetGridFromPos(position, out x, out y);
        x = Mathf.Clamp(x, 0, w - 1);
        y = Mathf.Clamp(y, 0, h - 1);
        return(grid [x, y]);
    }
Пример #13
0
    /// <summary>
    /// Determines whether there are nearby enemies.
    /// </summary>
    /// <returns><c>true</c> if there are nearby enemies; otherwise, <c>false</c>.</returns>
    /// <param name="units">Units.</param>
    private bool IsEnemyNearby(List <Unit> units)
    {
        foreach (Unit unit in units)
        {
            int     range           = (int)unit.GetMovementAttribute().CurrentValue + unit.GetWeaponRange();
            Vector3 tileMapPosition = TileMapUtil.WorldCenteredToTileMap(unit.transform.position, _tileMap.TileSize);
            int     x = (int)tileMapPosition.x;
            int     z = (int)tileMapPosition.z;

            // Outer loop handles the straight lines going N, E, S, W
            for (int index1 = 1; index1 <= range; index1++)
            {
                // Inner loop handles all the other tiles NE, SE, NW, SW
                for (int index2 = 1; index2 <= range - index1; index2++)
                {
                    if (IsEnemyNearby(unit, x + index1, z + index2))                      // North East
                    {
                        return(true);
                    }
                    if (IsEnemyNearby(unit, x + index1, z - index2))                      // South East
                    {
                        return(true);
                    }
                    if (IsEnemyNearby(unit, x - index1, z + index2))                      // North West
                    {
                        return(true);
                    }
                    if (IsEnemyNearby(unit, x - index1, z - index2))                      // South West
                    {
                        return(true);
                    }
                }
                if (IsEnemyNearby(unit, x, z + index1))                  // North
                {
                    return(true);
                }
                if (IsEnemyNearby(unit, x + index1, z))                  // East
                {
                    return(true);
                }
                if (IsEnemyNearby(unit, x, z - index1))                  // South
                {
                    return(true);
                }
                if (IsEnemyNearby(unit, x - index1, z))                  // West
                {
                    return(true);
                }
            }
        }
        return(false);
    }
 /// <summary>
 /// Raises the pointer click event.
 /// When the portrait is clicked on, the camera will move to focus on the unit.
 /// </summary>
 /// <param name="eventData">Event data.</param>
 public void OnPointerClick(PointerEventData eventData)
 {
     // Don't allow events if mission panels are up
     if (!_combatController.MissionObjectivesPanel.activeSelf && !_combatController.PostCombatStatsPanel.activeSelf)
     {
         if (eventData.button == PointerEventData.InputButton.Left)
         {
             StartCoroutine(GameManager.Instance.GetCameraController().MoveToPosition(Unit.transform.position));
             Unit.ActivateCharacterSheet();
             Unit.TileHighlighter.HighlightTiles(Unit, TileMapUtil.WorldCenteredToTileMap(Unit.transform.position, _tileMap.TileSize));
         }
     }
 }
Пример #15
0
    void EffectBombCreate(int vGridX, int vGridY)
    {
        //把bomb从对象池取出来
        GameObject effectBomb = ObjectPoolManager.Instance.Get(ObjectPoolType.EffectBomb.ToString());

        effectBomb.transform.SetParent(null, false);
        effectBomb.gameObject.SetActive(false);
        //指定位置
        Vector2 pos = TileMapUtil.GetPosFromGrid(vGridX, vGridY);

        effectBomb.transform.Set2DPosition(pos);
        //要爆炸
        StartCoroutine(EffectBombExplose(effectBomb, m_BombTime));
    }
    /// <summary>
    /// Plays the walking animation.
    /// </summary>
    /// <param name="unit">Unit.</param>
    /// <param name="sourceTile">Source tile.</param>
    /// <param name="targetTile">Target tile.</param>
    private void PlayWalkingAnimation(Unit unit, Vector3 sourceTile, Vector3 targetTile)
    {
        // Only run if there is an animation controller
        if (unit.GetAnimationController())
        {
            // Get tile direction
            Unit.TileDirection tileDirection = unit.GetDirectionToTarget(
                TileMapUtil.WorldCenteredToTileMap(sourceTile, tileMap.TileSize),
                TileMapUtil.WorldCenteredToTileMap(targetTile, tileMap.TileSize)
                );

            unit.FacedDirection = tileDirection;
            unit.GetAnimationController().PlayWalkingAnimation(unit);
        }
    }
Пример #17
0
    /// <summary>
    /// Applies the VFX to targets.
    /// </summary>
    /// <returns>The VFX to targets.</returns>
    /// <param name="vfxPath">Vfx path.</param>
    /// <param name="targets">Targets.</param>
    protected List <GameObject> ApplyVFXToTargets(string vfxPath, List <Unit> targets)
    {
        List <GameObject> vfxGameObjects = new List <GameObject> ();

        if (vfxPath != null && vfxPath != "")
        {
            GameObject VFXPrefab = Resources.Load <GameObject> (vfxPath);
            foreach (var target in targets)
            {
                GameObject VFX = Instantiate(VFXPrefab);
                Vector3    unitPositionWorld = TileMapUtil.TileMapToWorldCentered(target.Tile, controller.TileMap.TileSize);
                unitPositionWorld.y    = 1;              // TODO: Start using rendering layers to make appear in front of other objects
                VFX.transform.position = unitPositionWorld;
                vfxGameObjects.Add(VFX);
            }
        }
        return(vfxGameObjects);
    }
Пример #18
0
    /// <summary>
    /// Raises the cancel button clicked event.
    /// </summary>
    private void OnCancelButtonClicked()
    {
        // Get active unit when cancel was invoked
        Unit unit = controller.TurnOrderController.GetNextUp();

        // Set back to selected color
        unit.Highlight();

        // Swap unit back to old tile
        TileMapData tileMapData     = controller.TileMap.GetTileMapData();
        TileData    oldTileData     = tileMapData.GetTileDataAt(controller.OldUnitPosition);
        TileData    currentTileData = tileMapData.GetTileDataAt(controller.CurrentUnitPosition);

        currentTileData.SwapUnits(oldTileData);

        // Update tile position on Unit
        unit.Tile = controller.OldUnitPosition;

        // Swap actual world centered position to old position
        unit.transform.position = TileMapUtil.TileMapToWorldCentered(controller.OldUnitPosition, controller.TileMap.TileSize);

        // Revert to old walking animation
        unit.FacedDirection = controller.OldUnitTileDirection;
        unit.GetAnimationController().PlayWalkingAnimation(unit);

        // Swap cached position on controller
        controller.CurrentUnitPosition = controller.OldUnitPosition;

        // Highlight unit
        controller.HighlightCharacter(unit);

        // Highlight tiles around unit
        unit.TileHighlighter.HighlightTiles(unit, unit.Tile);

        // Clear out radial button container list
        controller.RadialButtonContainers.Clear();

        // Destroy radial menu
        Destroy(_radialMenuController.gameObject);

        // Revert back to prior state
        controller.ChangeState <PlayerSelectedState> ();
    }
Пример #19
0
    private void _OnClick()
    {
        Collider2D collider = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition), Layers.PlaneMask);

        if (collider)
        {
            Vector3 world = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            if (TileMapUtil.IsTileOfType <PlaneTile>(tileMap, tileMap.WorldToCell(world)))
            {
                Plane plane = collider.GetComponent <Plane>();
                plane.Toward();
            }
        }

        foreach (Plane plane in planes)
        {
            plane.RefreshData(checkerboard, new Vector2Int(0, 0));
        }
        TileMapUtil.Draw(tileMap, checkerboard, planeTile, wallTile);
    }
Пример #20
0
    /// <summary>
    /// Determines whether an enemy is nearby the unit.
    /// </summary>
    /// <returns><c>true</c> if this instance is enemy nearby the specified unit x z; otherwise, <c>false</c>.</returns>
    /// <param name="unit">Unit.</param>
    /// <param name="x">The x coordinate.</param>
    /// <param name="z">The z coordinate.</param>
    private bool IsEnemyNearby(Unit unit, int x, int z)
    {
        // Don't go out of boundary
        if (!TileMapUtil.IsInsideTileMapBoundary(_tileMap.GetTileMapData(), x, z))
        {
            return(false);
        }

        TileData tileData   = _tileMap.GetTileMapData().GetTileDataAt(x, z);
        Unit     targetUnit = tileData.Unit;

        if (targetUnit != null)
        {
            if (targetUnit.IsPlayerControlled != unit.IsPlayerControlled)
            {
                return(true);
            }
        }
        return(false);
    }
Пример #21
0
    void Start()
    {
        // 初始化格子
        w    = TileMapUtil.GetColumns();
        h    = TileMapUtil.GetRows();
        grid = new NodeItem[w, h];

        bool isObstacle;

        // 将墙的信息写入格子中
        for (int x = 0; x < w; x++)
        {
            for (int y = 0; y < h; y++)
            {
                // 构建一个节点
                TileInfo tileInfo = TileMapUtil.GetTileInfoByGrid(x, y);
                isObstacle = TileMapUtil.IsObstacle(tileInfo.m_ElemType);
                grid[x, y] = new NodeItem(isObstacle, x, y);
            }
        }
    }
Пример #22
0
    private void Init()
    {
        _tileMap    = controller.TileMap;
        _pathfinder = controller.Pathfinder;

        _cpu = controller.TurnOrderController.GetNextUp();
        controller.HighlightedUnit = _cpu;

        // If cpu has persistent highlighted tiles, temporarily remove, then re-apply after move
        _hasPersistentHighlightedTiles = _cpu.TileHighlighter.IsPersistent;
        if (_hasPersistentHighlightedTiles)
        {
            _cpu.TileHighlighter.RemovePersistentHighlightedTiles();
        }

        _cpu.Highlight();
        _cpu.Select();

        // Show terrain related things
        Vector3  cpuTilemapCoordinates = TileMapUtil.WorldCenteredToTileMap(_cpu.transform.position, _tileMap.TileSize);
        TileData tileData = _tileMap.GetTileMapData().GetTileDataAt(cpuTilemapCoordinates);

        controller.TerrainDetailsController.Activate(tileData);

        // Show character sheet
        _cpu.ActivateCharacterSheet();

        // Show movement tiles
        _cpu.TileHighlighter.HighlightTiles(_cpu, cpuTilemapCoordinates, false);

        // Get AI Action
        // TODO: Refactor the shit out of all of this. I'm so not proud of this.
        AI ai = new KamiKazeAI(_cpu, _tileMap.GetTileMapData(), controller.TileDiscoverer, _pathfinder);

        _cpu.Action = ai.GetAction();

        //print (string.Format ("Start CPU Turn: {0}", _selectedCharacter));
        StartCoroutine(Move());
    }
Пример #23
0
    public void SetData(int[,] checkerboard, Vector2Int extraOffset)
    {
        SetCheckboard(checkerboard);
        Vector2Int temp = centerPos;

        int[,] Data = GetPlaneData();
        Vector2Int offset = GetOffset();

        offset += extraOffset;
        for (int i = 0; i < Data.GetLength(0); i++)
        {
            for (int j = 0; j < Data.GetLength(1); j++)
            {
                Vector2Int pos = centerPos + offset + new Vector2Int(i, j);
                checkerboard[pos.x, pos.y] += Data[i, j];

                if (TileMapUtil.IsCenter(checkerboard[pos.x, pos.y]))
                {
                    temp = pos;
                }
            }
        }
        centerPos = temp;
    }
Пример #24
0
    public void RandomPlanePos()
    {
        int[,] doneCheckboard = new int[row, col];
        while (true)
        {
            int doneNum = 0;
            int[,] tempCheckboard = new int[row, col];
            for (int num = 0; num < planes.Count; num++)
            {
                Array         values  = Enum.GetValues(typeof(PlaneToward));
                System.Random random  = new System.Random();
                int           indexTo = random.Next(0, values.Length);
                PlaneToward   to      = (PlaneToward)values.GetValue(indexTo);

                Plane plane = planes[num];
                plane.tempToward = to;

                Dictionary <int, List <int> > queue = new Dictionary <int, List <int> >();

                for (int i = 0; i < row; i++)
                {
                    queue[i] = new List <int>();
                    for (int j = 0; j < col; j++)
                    {
                        if (tempCheckboard[i, j] == 0)
                        {
                            queue[i].Add(j);
                        }
                    }
                }
                bool completed = false;

                while (!completed)
                {
                    List <int> keys = queue.Keys.ToList();
                    int        x    = random.Next(0, keys.Count);
                    int        r    = keys[x];

                    int y = random.Next(0, queue[r].Count);
                    int c = queue[r][y];


                    queue[r].Remove(c);
                    if (queue[r].Count < 1)
                    {
                        queue.Remove(r);
                    }

                    if (queue.Count < 1)
                    {
                        break;
                    }

                    plane.tempCenterPos = new Vector2Int(r, c);

                    if (!plane.CanSetTempPlane(tempCheckboard))
                    {
                        continue;
                    }
                    plane.PreSetData(tempCheckboard);
                    completed = true;
                    doneNum  += 1;
                }
            }
            if (doneNum >= 3)
            {
                doneCheckboard = tempCheckboard;
                break;
            }
        }
        foreach (Plane p in planes)
        {
            p.RandomDone(doneCheckboard);
            p.RotatePlane();
            TileMapUtil.SetPlanePos(p, tileMap);
        }

        checkerboard = doneCheckboard;

        TileMapUtil.Draw(tileMap, checkerboard, planeTile, wallTile);
    }
Пример #25
0
    private void _OnDrag(Vector3 pre, Vector3 touch)
    {
        if (!CanMovePlane)
        {
            return;
        }

        Vector3 preWorld   = Camera.main.ScreenToWorldPoint(pre);
        Vector3 touchWorld = Camera.main.ScreenToWorldPoint(touch);

        movePlane.transform.position = new Vector3(touchWorld.x, touchWorld.y, 0);
        SpriteRenderer renderer = movePlane.GetComponent <SpriteRenderer>();

        if (renderer)
        {
            renderer.sortingOrder = Layers.SortingMovePlane;
        }

        Vector2Int cellPos = TileMapUtil.CovertDataPosToTileMapPos(movePlane.centerPos);
        Vector3    pos     = tileMap.CellToWorld(new Vector3Int(cellPos.x, cellPos.y, 0));

        Vector3Int touchCell    = tileMap.WorldToCell(touchWorld);
        Vector2Int tempCenter   = new Vector2Int(touchCell.x, touchCell.y);
        Vector2Int touchDataPos = TileMapUtil.CovertTileMapPosToDataPos(tempCenter);

        movePlane.tempCenterPos = touchDataPos;
        movePlane.tempToward    = movePlane.toward;

        Vector2Int offset = new Vector2Int(0, 0);

        if (movePlane.CanSetTempPlane(checkerboard))
        {
            offset = touchDataPos - movePlane.centerPos;
        }
        else
        {
            if ((new Vector2(pos.x, pos.y) - new Vector2(touchWorld.x, touchWorld.y)).magnitude > 2.25f)
            {
                return;
            }
            Vector3Int cell = tileMap.WorldToCell(touchWorld) - tileMap.WorldToCell(preWorld);
            offset = TileMapUtil.CovertTileMapPosToDataPos(new Vector2Int(cell.x, cell.y));


            if (Mathf.Abs(offset.x) > 0 || Mathf.Abs(offset.y) > 0)
            {
                offset.x = Mathf.Min(offset.x, 1);
                offset.y = Mathf.Min(offset.y, 1);
                offset.x = Mathf.Max(offset.x, -1);
                offset.y = Mathf.Max(offset.y, -1);
            }
        }

        if (Mathf.Abs(offset.x) > 0 || Mathf.Abs(offset.y) > 0)
        {
            movePlane.Move(offset);
        }

        foreach (Plane plane in planes)
        {
            plane.RefreshData(checkerboard, new Vector2Int(0, 0));
        }

        TileMapUtil.Draw(tileMap, checkerboard, planeTile, wallTile);
    }
Пример #26
0
 private void OnDrawGizmos()
 {
     Gizmos.color = TileMapUtil.GetDebugColor(m_ElemType);
     Gizmos.DrawSphere(transform.position, 0.2f);
 }
Пример #27
0
    public void TestGetInvalidTile()
    {
        Vector3 actual = TileMapUtil.GetInvalidTile();

        Assert.AreEqual(_invalidTile, actual);
    }
Пример #28
0
 public static bool IsSameGrid(Vector2 vPosA, Vector2 vPosB)
 {
     return(TileMapUtil.GetGridFromPos(vPosA) == TileMapUtil.GetGridFromPos(vPosB));
 }
Пример #29
0
 public void TestIsInvalidTile()
 {
     Assert.IsTrue(TileMapUtil.IsInvalidTile(_invalidTile));
 }
Пример #30
0
 public void GetGrid(out int vGridX, out int vGridY)
 {
     _tempVec.x = transform.position.x;
     _tempVec.y = transform.position.y;
     TileMapUtil.GetGridFromPos(_tempVec, out vGridX, out vGridY);
 }