Photon Quantum 2.1.1

Public Member Functions | Properties | List of all members
Quantum.PhysicsJoints2D.JointsIterator Struct Reference

An auxiliary struct to iterate over the joints on a PhysicsJoints2D component. Use PhysicsJoints2D.GetIterator to acquire an iterator for the component's joint buffer. More...

Inherits IEnumerator< Joint >.

Public Member Functions

JointsIterator GetEnumerator ()
 The iterator is also an enumerator. This method is useful for accessing the elements in a foreach loop, for instance. More...
 
bool MoveNext ()
 Moves to the next joint. More...
 
void Reset ()
 Resets the iterator to its original state. More...
 

Properties

Joint Current [get]
 A copy of the current joint being iterated. To modify the actual element in the buffer, use CurrentUnsafe instead. More...
 
int CurrentIndex [get]
 The index on the buffer of the element currently being iterated. The index is out of the valid range if the iterator has just been created on Reset. More...
 
JointCurrentUnsafe [get]
 A pointer to the current joint being iterated. This allows modifications to the element in the actual buffer of joints. More...
 

Detailed Description

An auxiliary struct to iterate over the joints on a PhysicsJoints2D component. Use PhysicsJoints2D.GetIterator to acquire an iterator for the component's joint buffer.

If new elements are added while iterating and this causes the buffer to be expanded, the iterator will keep iterating over the previous buffer, which is not immediately disposed (see AddJoint). In this case, further changes to elements in the buffer being iterated will not modify the elements on the new buffer. Hence, the addition of elements while iterating is not recommended, unless the access to the elements are read-only.

var jointsComponent = f.Unsafe.GetPointer<PhysicsJoints2D>(entity);
var jointsIterator = jointsComponent->GetIterator(f);
while (jointsIterator.MoveNext()) {
// CurrentUnsafe is a pointer to the element in the buffer
jointsIterator.CurrentUnsafe->Enabled = true;
// Current is a copy of the joint being currently iterated
var jointCopy = jointsIterator.Current;
Assert.Check(jointCopy.Enabled);
// by default, the iterator will go through the elements in reverse order.
// this allows the removal of elements while iterating without this causing elements to be skipped as a byproduct.
if (jointCopy.Type == Physics2D.JointType.None) {
jointsComponent->RemoveAtUnordered(f, jointsIterator.CurrentIndex);
}
}

Member Function Documentation

◆ GetEnumerator()

JointsIterator Quantum.PhysicsJoints2D.JointsIterator.GetEnumerator ( )
inline

The iterator is also an enumerator. This method is useful for accessing the elements in a foreach loop, for instance.

Returns
A copy of this iterator on its current state.

◆ MoveNext()

bool Quantum.PhysicsJoints2D.JointsIterator.MoveNext ( )
inline

Moves to the next joint.

Returns
True if there is a next element.

◆ Reset()

void Quantum.PhysicsJoints2D.JointsIterator.Reset ( )
inline

Resets the iterator to its original state.

Property Documentation

◆ CurrentUnsafe

Joint* Quantum.PhysicsJoints2D.JointsIterator.CurrentUnsafe
get

A pointer to the current joint being iterated. This allows modifications to the element in the actual buffer of joints.

Exceptions
NullReferenceExceptionIf the iterator buffer is null.
ArgumentOutOfRangeExceptionIf the iterator current index is outside the valid range of the buffer: [0, count).

◆ Current

Joint Quantum.PhysicsJoints2D.JointsIterator.Current
get

A copy of the current joint being iterated. To modify the actual element in the buffer, use CurrentUnsafe instead.

◆ CurrentIndex

int Quantum.PhysicsJoints2D.JointsIterator.CurrentIndex
get

The index on the buffer of the element currently being iterated. The index is out of the valid range if the iterator has just been created on Reset.