protected override void OnUpdate()
        {
            var gameState = GetSingleton <GameStateData>();

            if (gameState.State != GameState.Swap)
            {
                return;
            }

            var input        = World.GetExistingSystem <Tiny.Input.InputSystem>();
            var physicsWorld = World.GetExistingSystem <PhysicsWorldSystem>().PhysicsWorld;

            if (InputUtil.GetInputDown(input))
            {
                m_StartPosition = CameraUtil.ScreenPointToWorldPoint(World, InputUtil.GetInputPosition(input));
            }
            else if (InputUtil.GetInputUp(input))
            {
                var endPosition = CameraUtil.ScreenPointToWorldPoint(World, InputUtil.GetInputPosition(input));
                var inputDelta  = endPosition - m_StartPosition;

                var activeInput = GetSingleton <ActiveInput>();
                activeInput.Value = GetSwapInputFromWorldPos(ref physicsWorld, m_StartPosition, inputDelta);

                SetSingleton(activeInput);
            }
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var input        = World.GetExistingSystem <Tiny.Input.InputSystem>();
            var physicsWorld = World.GetExistingSystem <PhysicsWorldSystem>().PhysicsWorld;

            if (InputUtil.GetInputDown(input))
            {
                m_StartPosition = CameraUtil.ScreenPointToViewportPoint(EntityManager, InputUtil.GetInputPosition(input));
            }
            else if (InputUtil.GetInputUp(input))
            {
                var inputPos   = CameraUtil.ScreenPointToViewportPoint(EntityManager, InputUtil.GetInputPosition(input));
                var inputDelta = inputPos - m_StartPosition;

                var cameraMatrices = m_CameraQuery.ToComponentDataArray <CameraMatrices>(Allocator.TempJob);
                var resultPos      = CameraUtil.ViewPortPointToNearClipPoint(cameraMatrices[0], m_StartPosition);

                var activeInput = GetSingleton <ActiveInput>();
                activeInput.Value = GetSwapInputFromWorldPos(ref physicsWorld, resultPos, inputDelta);

                SetSingleton(activeInput);

                cameraMatrices.Dispose();
            }

            return(inputDeps);
        }
Ejemplo n.º 3
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var input        = World.GetExistingSystem <Tiny.Input.InputSystem>();
            var physicsWorld = World.GetExistingSystem <PhysicsWorldSystem>().PhysicsWorld;

            if (InputUtil.GetInputUp(input))
            {
                var inputPos = CameraUtil.ScreenPointToViewportPoint(EntityManager, InputUtil.GetInputPosition(input));

                Debug.Log("inputPos" + inputPos);

                var cameraMatrices = m_CameraQuery.ToComponentDataArray <CameraMatrices>(Allocator.TempJob);
                var resultPos      = CameraUtil.ViewPortPointToNearClipPoint(cameraMatrices[0], inputPos);

                var pointInput = new OverlapPointInput()
                {
                    Position = resultPos,
                    Filter   = CollisionFilter.Default
                };

                if (physicsWorld.OverlapPoint(pointInput, out var overlapPointHit))
                {
                    var body = physicsWorld.AllBodies[overlapPointHit.PhysicsBodyIndex];
                    Debug.Log("input hit physicsbody " + body.Entity.Index);
                    var colorComponent = m_entityManager.GetComponentData <ColorComponent>(body.Entity);
                    colorComponent.Flag = !colorComponent.Flag;
                    m_entityManager.SetComponentData <ColorComponent>(body.Entity, colorComponent);
                }

                cameraMatrices.Dispose();
            }

            return(inputDeps);
        }