public void Execute(CommandData commandData, GameEntity trigger = null) { var command = commands[commandData.type] as BaseCommand; var executePos = trigger != null ? trigger.position : Vector3.zero; var executeCell = trigger != null ? trigger.grid.pivot : gridService.GetClosestCell(executePos); if (executePos.sqrMagnitude < Mathf.Epsilon && executeCell != null) { executePos = executeCell.position; } command.ExecuteCommand(commandData, executePos, executeCell, trigger); }
private void HandleDraggedObject(Vector3 screenPos) { if (dragged != null && dragged.hasGameObject) { EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_ENTITY_END_DRAG, dragged); Utils.SetSortingLayer(dragged, Constants.SORTING_LAYER_DEFAULT); var pos = Utils.GetPlaneTouchPos(screenPos, cameraService.activeCamera); var closestCell = gridService.GetClosestCell(pos, false); gridService.SetEntityOn(dragged, closestCell); if (dragged.hasCommand) { commandSystem.Execute(dragged.command.onDragEndCommand, closestCell, dragged); } dragged = null; } }