コード例 #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_MouseGroup.CalculateLength() == 0)
            {
                return(inputDeps);
            }

            var handle = JobHandle.CombineDependencies(inputDeps, m_BuildPhysicsWorldSystem.FinalJobHandle);

            if (Input.GetMouseButtonDown(0) && (Camera.main != null))
            {
                var mice           = m_MouseGroup.ToComponentDataArray <MousePick>(Allocator.TempJob);
                var IgnoreTriggers = mice[0].IgnoreTriggers != 0;
                mice.Dispose();

                // Schedule picking job, after the collision world has been built
                handle = new Pick
                {
                    CollisionWorld   = m_BuildPhysicsWorldSystem.PhysicsWorld.CollisionWorld,
                    NumDynamicBodies = m_BuildPhysicsWorldSystem.PhysicsWorld.NumDynamicBodies,
                    SpringData       = SpringDatas,
                    RayInput         = MousePickBehaviour.CreateRayCastFromMouse(),
                    Near             = Camera.main.nearClipPlane,
                    Forward          = Camera.main.transform.forward,
                    IgnoreTriggers   = IgnoreTriggers,
                }.Schedule(JobHandle.CombineDependencies(handle, m_BuildPhysicsWorldSystem.FinalJobHandle));

                PickJobHandle = handle;

                handle.Complete(); // TODO.ma figure out how to do this properly...we need a way to make physics sync wait for
                // any user jobs that touch the component data, maybe a JobHandle LastUserJob or something that the user has to set
            }

            if (Input.GetMouseButtonUp(0))
            {
                SpringDatas[0] = new SpringData();
            }

            return(handle);
        }
コード例 #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_MouseGroup.CalculateLength() == 0)
            {
                return(inputDeps);
            }

            var Positions = GetComponentDataFromEntity <Translation>();

            // If there's a pick job, wait for it to finish
            if (m_PickSystem.PickJobHandle != null)
            {
                JobHandle.CombineDependencies(inputDeps, m_PickSystem.PickJobHandle.Value).Complete();
            }

            // If there's a picked entity, drag it
            MousePickSystem.SpringData springData = m_PickSystem.SpringDatas[0];
            var physicsWorld = m_PickSystem.m_BuildPhysicsWorldSystem.PhysicsWorld;

            if (springData.Dragging != 0)
            {
                Entity entity = m_PickSystem.SpringDatas[0].Entity;

                if (!m_WasDragging)
                {
                    GameMgr.g.PlayPickMonsterSoundEffect(entity);
                }

                m_WasDragging = true;
                Translation posComponent = Positions[entity];
                m_SelectedEntity = entity;

                var hits = new NativeList <RaycastHit>(Allocator.TempJob);
                physicsWorld.CollisionWorld.CastRay(MousePickBehaviour.CreateRayCastFromMouse(), ref hits);
                var terrainEntities = m_TerrainEntityQuery.ToEntityArray(Allocator.TempJob);
                foreach (var terrainEntity in terrainEntities)
                {
                    var index = physicsWorld.GetRigidBodyIndex(terrainEntity);
                    foreach (var hit in hits.ToArray())
                    {
                        if (hit.RigidBodyIndex == index)
                        {
                            posComponent.Value.x = hit.Position.x;
                            posComponent.Value.z = hit.Position.z;
                            Positions[entity]    = posComponent;
                            break;
                        }
                    }
                }

                hits.Dispose();
                terrainEntities.Dispose();
            }
            else if (m_WasDragging)
            {
                m_WasDragging = false;
                var hits = new NativeList <RaycastHit>(Allocator.TempJob);
                physicsWorld.CollisionWorld.CastRay(MousePickBehaviour.CreateRayCastFromMouse(), ref hits);

                var roomEntities = m_RoomEntityQuery.ToEntityArray(Allocator.TempJob);
                foreach (var room in roomEntities)
                {
                    var index = physicsWorld.GetRigidBodyIndex(room);
                    foreach (var hit in hits.ToArray())
                    {
                        if (hit.RigidBodyIndex == index)
                        {
                            GameMgr.MoveMonsterToRoom(m_SelectedEntity, room, 0);
                        }
                    }
                }

                hits.Dispose();
                roomEntities.Dispose();
            }

            return(inputDeps);
        }