Ejemplo n.º 1
0
    void Update()
    {
        for (int i = 0; i < num; i++)
        {
            rnd[i] = new Random(seed.NextUInt());
        }
        var jobWall = new UpdateWall {
            position = pos, accel = acc, scale = areaSize
        };
        var jobSmlt = new UpdateSmlt {
            position = pos, velocity = vel, accel = acc, dstThreshold = distThreshold, weights = simWeight
        };
        var jobMove = new UpdateMove {
            position = pos, velocity = vel, accel = acc, dt = Time.deltaTime, limit = velThreshold
        };
        var jobBlck = new UpdateBlck {
            position = pos, result = rst
        };
        var handlerWall = jobWall.Schedule(num, 0);
        var handlerSmlt = jobSmlt.Schedule(num, 0, handlerWall);
        var handlerMove = jobMove.Schedule(trs, handlerSmlt);
        var handlerBlck = jobBlck.Schedule(handlerMove);

        handlerBlck.Complete();
    }
    void Update()
    {
        // add instance
        if (Input.GetKey(add))
        {
            AddInstance();
        }
        // remove instance
        if (num > 0 && Input.GetKey(remove))
        {
            var i = UnityEngine.Random.Range(0, num);
            Destroy(trs[i].gameObject);
            pos.RemoveAtSwapBack(i);
            vel.RemoveAtSwapBack(i);
            acc.RemoveAtSwapBack(i);
            trs.RemoveAtSwapBack(i);
            num--;
        }

        var jobWall = new UpdateWall {
            position = pos.AsDeferredJobArray(), accel = acc.AsDeferredJobArray(), scale = areaSize
        };
        var jobSmlt = new UpdateSmlt {
            position = pos.AsDeferredJobArray(), velocity = vel.AsDeferredJobArray(), accel = acc.AsDeferredJobArray(), dstThreshold = distThreshold, weights = simWeight
        };
        var jobMove = new UpdateMove {
            position = pos.AsDeferredJobArray(), velocity = vel.AsDeferredJobArray(), accel = acc.AsDeferredJobArray(), dt = Time.deltaTime, limit = velThreshold
        };
        var jobBlck = new UpdateBlck {
            position = pos.AsDeferredJobArray(), result = rst
        };
        var handlerWall = jobWall.Schedule(num, 0);
        var handlerSmlt = jobSmlt.Schedule(num, 0, handlerWall);
        var handlerMove = jobMove.Schedule(trs, handlerSmlt);
        var handlerBlck = jobBlck.Schedule(handlerMove);

        handlerBlck.Complete();
    }