Esempio n. 1
0
        public GameEntity CreateGridObject(string objectId)
        {
            var entity     = Contexts.sharedInstance.game.CreateEntity();
            var objectData = database.Get <GridObjectData>(objectId);
            var prefabPath = database.Get <string>(objectData.prefab);

            entity.AddGameObject(objectData.objectId, objectData.typeId, Utils.GenerateUniqueId(database));
            entity.AddResource(prefabPath);
            var defaultFootprint = new List <List <int> >()
            {
                new List <int>()
                {
                    1
                }
            };

            entity.AddGrid(null, new List <GameEntity>(), new Footprint(objectData.footprintData == null ? defaultFootprint : objectData.footprintData), objectData.canSwap);
            var view     = FactoryPool.GetPooled(prefabPath);
            var viewMono = view.GetComponent <ViewMonoComponent>();

            entity.AddView(view, viewMono != null ? viewMono.HUDpivot : view.transform);
            #if UNITY_EDITOR
            entity.viewObject.name = string.Format("ent_{0}_{1}_{2}", entity.objectId, entity.typeId, entity.uniqueId);
            #endif
            EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_GRID_ENTITY_CREATION, entity);

            return(entity);
        }
Esempio n. 2
0
        public bool HandleTouchUp(Vector3 screenPos)
        {
            if (!isTapOnUI)
            {
                var touched = Utils.GetInputTargetOnGrid(screenPos, sceneSystem, cameraService.activeCamera, gridService);
                if (touched != null && (!touched.hasGrid || (touched.hasGrid && touched.grid.cells.Count > 0)))
                {
                    EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_ENTITY_TAP_UP, touched);

                    if (touched.hasGameObject)
                    {
                        TutorialService <TutorialStep> .Notify(string.Format("tap?{0}", touched.objectId));
                    }

                    if (touched.hasCommand && !string.IsNullOrEmpty(touched.command.onTapCommand))
                    {
                        var cell = touched.hasGrid ? touched.grid.pivot : null;
                        commandSystem.Execute(touched.command.onTapCommand, touched.position, cell, touched);
                        AnimateObjectTouch(touched);
                    }
                }
            }
            isTapOnUI = false;
            return(false);
        }
Esempio n. 3
0
        private void CancelDraggedObject()
        {
            if (dragged != null && dragged.hasGameObject)
            {
                EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_ENTITY_CANCEL_DRAG, dragged);

                Utils.SetSortingLayer(dragged, Constants.SORTING_LAYER_DEFAULT);
                gridService.SetEntityOn(dragged, draggedInitCell);
                dragged = null;
            }
        }
        public void WhenCallbackIsSubscribedAndPerformCall_CallToTheCallback()
        {
            var eventDispatcher = new EventDispatcherService();
            var callback1       = Substitute.For <SignalDelegate>();

            eventDispatcher.Subscribe <TestSignal>(callback1);

            var testSignal = new TestSignal("SomeData");

            eventDispatcher.Dispatch(testSignal);

            callback1.Received().Invoke(testSignal);
        }
Esempio n. 5
0
        public async Task DispatchShouldDispatchEvents()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddTransient <IEventHandler <ArticleEvent>, ArticleEventHandler>();

            var dispatcher = new EventDispatcherService(serviceCollection.BuildServiceProvider());

            var domainEvent = new ArticleEvent();

            await dispatcher.Dispatch(domainEvent);

            Assert.True(domainEvent.Handled);
        }
Esempio n. 6
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);
     }
 }
        public void WhenDifferentSignalsAreRegisteredAndPerformCallWithOne_OnlyCallToTheAssociateCallbacksOfThisSignal()
        {
            var eventDispatcher = new EventDispatcherService();
            var callback1       = Substitute.For <SignalDelegate>();
            var callback2       = Substitute.For <SignalDelegate>();

            eventDispatcher.Subscribe <TestSignal>(callback1);
            eventDispatcher.Subscribe <TestSignal2>(callback2);

            var testSignal2 = new TestSignal2(123);

            eventDispatcher.Dispatch(testSignal2);

            callback1.DidNotReceive();
            callback2.Received().Invoke(testSignal2);
        }
Esempio n. 8
0
        public void CleanupEntity(IContext context, IEntity entity)
        {
            var gameEntity = (GameEntity)entity;

            if (gameEntity != null)
            {
                EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_ENTITY_DESTRUCTION, gameEntity);

                // cleanup process for different components

                if (gameEntity.hasView) // return view to the pool
                {
                    gameEntity.localScale = Vector3.one;
                    gameEntity.viewObject.SetActive(false);
                }
            }
        }
Esempio n. 9
0
        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;
            }
        }
Esempio n. 10
0
        public GameEntity CreateCell(int row, int column, string objectId, GameEntity occupant = null)
        {
            var entity     = Contexts.sharedInstance.game.CreateEntity();
            var objectData = database.Get <ObjectData>(objectId);
            var prefabPath = database.Get <string>(objectData.prefab);

            entity.AddGameObject(objectData.objectId, objectData.typeId, Utils.GenerateUniqueId(database));
            entity.AddResource(prefabPath);
            entity.AddCell(row, column, occupant);
            var view     = FactoryPool.GetPooled(prefabPath);
            var viewMono = view.GetComponent <ViewMonoComponent>();

            entity.AddView(view, viewMono != null ? viewMono.HUDpivot : view.transform);
            #if UNITY_EDITOR
            entity.viewObject.name = string.Format("cell_{0}_{1}_{2}_{3}_{4}", entity.objectId, entity.typeId, entity.row, entity.column, entity.uniqueId);
            #endif
            EventDispatcherService <GameEntity> .Dispatch(Constants.EVENT_CELL_ENTITY_CREATION, entity);

            return(entity);
        }
Esempio n. 11
0
        private void MoveToNextStep()
        {
            if (!hasComplete)
            {
                EventDispatcherService <T> .Dispatch(Constants.EVENT_TUT_STEP_COMPLETE, currentStep);

                stepIndex++;

                if (hasComplete)
                {
                    TutorialService <T> .CompleteTutorial(id);
                }
                else
                {
                    current    = TutorialState.AwakeStep;
                    elapseTime = 0f;
                    Update();
                }
            }
        }
Esempio n. 12
0
        public void Init(T[] steps, GUIService guiService, DataBindingService databinding)
        {
            this.steps       = steps;
            this.guiService  = guiService;
            this.databinding = databinding;

            stepIndex = 0;
            LogWrapper.DebugLog("[{0}] {1} init with step count {2}", GetType(), id, steps.Length);

            // setup the awake function
            current    = TutorialState.AwakeStep;
            elapseTime = 0f;

            panelView = guiService.GetPanelView(Constants.PANEL_VIEW_ID_TUTORIAL);
            if (panelView == null)
            {
                throw new System.NullReferenceException("Could not find tutorial panel, please condif a panle in the gui config file with id: " + Constants.PANEL_VIEW_ID_TUTORIAL);
            }

            EventDispatcherService <ActiveTutorial <T> > .Dispatch(Constants.EVENT_TUT_INIT, this);
        }