コード例 #1
0
    public void Update()
    {
        // generate a new Ray to test against every frame
        var point   = UnityEngine.Random.insideUnitSphere;
        var testRay = new Ray(Vector3.zero - point, Vector3.right + Vector3.up + point);

        m_RayIntersectionJob = new RayIntersectionJob()
        {
            ray         = testRay,
            results     = m_RayIntersectionResults,
            boundsArray = m_NativeBounds
        };

        // instead of keeping a results array between frames and clearing it, here we
        // use the TempJob allocator for an array we'll dispose quickly (within 4 frames)
        var results = new NativeArray <Bounds>(new Bounds[10], Allocator.TempJob);

        m_RayIntersectionListJob = new RayIntersectionListJob()
        {
            boundsIntersected = m_RayIntersectionResults,
            boundsArray       = m_NativeBounds,
            results           = results
        };

        m_RayIntersectionJobHandle     = m_RayIntersectionJob.Schedule(m_NativeBounds.Length, 64);
        m_RayIntersectionListJobHandle = m_RayIntersectionListJob.Schedule(m_RayIntersectionJobHandle);
    }
コード例 #2
0
    public void Update()
    {
        var point = UnityEngine.Random.insideUnitSphere * 100f;

        // check if a point intersects any of the cube's bounds
        m_Job = new BoundsContainsPointJob()
        {
            point       = point,
            boundsArray = m_NativeBounds,
        };

        // check if a bounding box outside that point intersects any cubes
        m_IntersectionJob = new BoundsIntersectionJob()
        {
            boundsToCheck = new Bounds(point, Vector3.one),
            boundsArray   = m_NativeBounds
        };

        var randomVec = UnityEngine.Random.insideUnitSphere;
        var testRay   = new Ray(Vector3.zero - randomVec, Vector3.right + Vector3.up + randomVec);

        m_RayIntersectionJob = new RayIntersectionJob()
        {
            ray         = testRay,
            results     = m_RayIntersectionResults,
            boundsArray = m_NativeBounds
        };

        m_Results = new NativeArray <Bounds>(new Bounds[20], Allocator.TempJob);

        m_RayIntersectionListJob = new RayIntersectionListJob()
        {
            boundsIntersected = m_RayIntersectionResults,
            boundsArray       = m_NativeBounds,
            results           = m_Results
        };

        m_RayIntersectionJobHandle     = m_RayIntersectionJob.Schedule(m_NativeBounds.Length, 64);
        m_RayIntersectionListJobHandle = m_RayIntersectionListJob.Schedule(m_RayIntersectionJobHandle);

        m_JobHandle             = m_Job.Schedule(m_Positions.Length, 64);
        m_IntersectionJobHandle = m_IntersectionJob.Schedule(m_NativeBounds.Length, 64);
    }