예제 #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 (cell != null && gridService.IsOccupied(cell) && cell.cell.occupant.hasOrderList)
                {
                    foreach (var order in cell.cell.occupant.orderList.orderList)
                    {
                        bool isObjectOrder = string.Equals(dragged.objectId, order.id);
                        bool isTypeOrder   = string.Equals(dragged.typeId, order.id);

                        if (cell.cell.occupant.hasGameObject &&
                            (isObjectOrder || isTypeOrder) &&
                            !cell.cell.occupant.orderList.Filled())
                        {
                            float animationLength = 0.3f;
                            var   orderId         = isObjectOrder ? dragged.objectId : dragged.typeId;
                            if (!cell.cell.occupant.orderList.HasFilledOrder(orderId))
                            {
                                AddOrder(orderId, cell.cell.occupant);
                                SceneAttachment.AttachCoroutine(TryCompleteOrderAfterAnimation(dragged, orderId, cell, animationLength));
                                return(true);
                            }
                        }
                    }
                }

                dragged = null;
            }

            return(false);
        }
예제 #2
0
        public void LoadCamp()
        {
            // Load grid
            var sampleMap    = database.Get <string>("player_map_data");
            var gridSettings = new GridSettings()
            {
                type = GridType.ISO, cellSpacing = new FloatVector2(0.5f, 0.7f)
            };
            var grid = mapReader.TILED_ReadGrid(sampleMap, gridSettings);

            gridService.Load(grid);

            // Load grid objects
            var gridObjects = mapReader.TILED_ReadObjects(sampleMap);

            foreach (var gridObject in gridObjects)
            {
                var command = new CommandData();
                command.type   = Constants.COMMAND_SPAWN_OBJ;
                command.output = gridObject.Value;
                command.count  = 1;

                var cell = gridService.GetCell(gridObject.Key.x, gridObject.Key.y);
                commandSystem.Execute(command, cell.position, cell);
            }

            // setup camera
            cameraService.SetBoundary(dataProvider.GetGameConfig().cameraInitPos.ToVector3(), dataProvider.GetGameConfig().cameraBoundaryRadius);
            cameraService.SetZoom(dataProvider.GetGameConfig().cameraInitZoom);
            cameraService.SetPosition(dataProvider.GetGameConfig().cameraInitPos.ToVector3());
        }
예제 #3
0
        public static GameEntity GetInputTargetOnGrid(Vector3 screenPos, SceneSystem sceneSystem, Camera camera, GridService gridService)
        {
            var touched = GetInputTarget(screenPos, sceneSystem, camera);

            if (touched == null)
            {
                var worldPos = GetPlaneTouchPos(screenPos, camera);
                var cell     = gridService.GetCell(worldPos);
                if (cell != null)
                {
                    touched = cell.cell.occupant;
                }
            }
            return(touched);
        }
예제 #4
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);
        }