LizzyFox-code/BrgContainer

Can I remove a random cube in real time?

Closed this issue · 2 comments

How do I delete a random cube in real time?

Yes, you can do it by Remove method:

var dataBuffer = batchHandle.AsInstanceDataBuffer();
dataBuffer.Remove(index, count);

Thank you. However, I modified the Update function a bit, in SampleBrgContainer.cs. I use dataBuffer.InstanceCount instead of m_CubeCount.

private void Update()
{
m_JobHandle.Complete();

var dataBuffer = m_BatchHandle.AsInstanceDataBuffer();
m_Time += Time.deltaTime;
if (m_Time > 2f)
{
    var index = (int)(Random.value * (dataBuffer.InstanceCount - 1));
    dataBuffer.Remove(index, 1);
    m_Time = 0;
}

transform.position = m_CenterFlock.Value;
m_BatchHandle.Upload();

var averageCenterJob = new AverageCenterJob
{
    InstanceDataBuffer = dataBuffer,
    Center = m_CenterFlock,
    Size = dataBuffer.InstanceCount,
    ObjectToWorldPropertyId = m_ObjectToWorldPropertyId
};
var averageCenterHandle = averageCenterJob.ScheduleByRef();

var sampleJob = new SampleJob
{
    Weights = m_Weights,
    Goal = m_Destination.position,
    NoiseOffsets = m_NoiseOffsets,
    Time = Time.time,
    DeltaTime = Time.deltaTime,
    MaxDistance = m_SeparationDistance,
    Speed = m_MaxSpeed,
    RotationSpeed = m_RotationSpeed,
    Size = dataBuffer.InstanceCount,
    InstanceDataBuffer = dataBuffer,
    ObjectToWorldPropertyId = m_ObjectToWorldPropertyId
};
m_JobHandle = sampleJob.ScheduleParallelByRef(dataBuffer.InstanceCount, 32, averageCenterHandle);

}