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);
        }
Пример #2
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);
        }