Exemple #1
0
 protected virtual void OnDrag(Vector2 location)
 {
     // Check to see if the dragged cursor is now
     // hovering over a new tile. Only if there is
     // a targeted actor that it would effect.
     if (targetedActor != null)
     {
         // Where is the cursor right now?
         Vector2Int newTile =
             grid.WorldToGrid(location);
         // What direction do we have to walk in to reach this tile?
         int xStep = (newTile.x - currentTile.x > 0) ? 1 : -1;
         int yStep = (newTile.y - currentTile.y > 0) ? 1 : -1;
         // Step towards the new tile, notifying the targeted actor
         // of each tile that we cross along the way.
         int step = 0;
         while (currentTile != newTile)
         {
             // Hard limit put in place may break behaviour on cursor
             // teleportation. Meant to prevent possible edge cases
             // where the requested tile cannot be walked to.
             if (++step > MAX_CURSOR_STEPS)
             {
                 break;
             }
             // Walk tiles along each axis.
             // This will generally infer a pattern where the cursor
             // moves along a diagonally then flattens, this does not
             // necassarily replicate the linear path of the cursor.
             if (currentTile.x != newTile.x)
             {
                 currentTile.x += xStep;
                 targetedActor.OnDragNewTile(currentTile);
             }
             if (currentTile.y != newTile.y)
             {
                 currentTile.y += yStep;
                 targetedActor.OnDragNewTile(currentTile);
             }
         }
     }
 }