Exemplo n.º 1
0
        public bool HandleDragEnd(Vector3 screenPos)
        {
            if (dragged != null && dragged.hasGameObject)
            {
                var gridPos = Utils.GetPlaneTouchPos(screenPos, cameraService.activeCamera);
                var cell    = gridService.GetCell(gridPos);

                if (gridService.IsOccupied(cell))
                {
                    var occupant       = cell.cell.occupant;
                    var mergeComboData = dataProvider.GetMergeComboDataForInput(dragged.objectId);
                    var canMerge       = occupant != dragged && mergeComboData != null && dragged.objectId.Equals(occupant.objectId);

                    if (canMerge)
                    {
                        Utils.SetSortingLayer(dragged, Constants.SORTING_LAYER_DEFAULT);

                        var spawnPos = occupant.position;

                        dragged.isDraggable  = false;
                        occupant.isDraggable = false;

                        // destroy the entities
                        gridService.DeAttach(dragged);
                        gridService.DeAttach(occupant);
                        dragged.Destroy();
                        occupant.Destroy();

                        // spawn the output entity
                        var command = new CommandData();
                        command.type   = Constants.COMMAND_SPAWN_OBJ;
                        command.output = mergeComboData.output;
                        command.count  = 1;
                        commandSystem.Execute(command, spawnPos, cell);
                        factoryEntity.CreateVFX(mergeComboData.vfx, spawnPos);

                        // execute the merge complete command
                        commandSystem.Execute(mergeComboData.mergeCompleteCommand, spawnPos, cell);

                        // consume the gesture event
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public IEnumerator TryCompleteOrderAfterAnimation(GameEntity order, string orderId, GameEntity cell, float delay)
        {
            gridService.DeAttach(order);
            order.TweenToPosition(cell.cell.occupant.HUDPivot, delay, LeanTweenType.easeInBack);
            yield return(new WaitForSeconds(delay));

            TryCompleteOrder(order, cell);
        }
Exemplo n.º 3
0
 private void StartDragEntity()
 {
     // start and drag the touched entity
     if (touched != null && touched.isDraggable && touched.hasGameObject)
     {
         dragged = touched;
         touched = null;
         Utils.SetSortingLayer(dragged, Constants.SORTING_LAYER_DRAG);
         draggedInitCell = dragged.grid.pivot;
         gridService.DeAttach(dragged);
         dragged.CancelTween();
         EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_ENTITY_START_DRAG, dragged);
     }
 }
Exemplo n.º 4
0
        protected virtual void ExecuteHeadCommand(CommandData commandData, Vector3 executePos, GameEntity cell, GameEntity trigger = null)
        {
            if (commandData.destroyTrigger && trigger != null)
            {
                if (trigger.hasCommand)
                {
                    commandSystem.Execute(trigger.command.onDestroyCommand, executePos, cell, trigger);
                }

                gridService.DeAttach(trigger);

                trigger.Destroy();
            }

            if (!string.IsNullOrEmpty(commandData.tutorialTrigger))
            {
                TutorialService <TutorialStep> .Notify(commandData.tutorialTrigger);
            }
        }