using UnityEngine.Scripting.APIUpdating;
namespace UnityEngine.XR.Interaction.Toolkit.Interactors
{
///
/// An interface that represents an object that can be contained as a member in an .
/// A Group member can be either an Interactor or another Group. Only one member in a Group can perform interaction at a time.
///
///
/// Implementations of this interface must also implement either or
/// to be functional within the Group.
///
///
///
[MovedFrom("UnityEngine.XR.Interaction.Toolkit")]
public interface IXRGroupMember
{
///
/// The Interaction Group that contains this member.
///
IXRInteractionGroup containingGroup { get; }
///
/// An calls this method just after this member has been added to the Group's
/// list or just after the Group has registered with the . This method is
/// called just before the member is re-registered with the Interaction Manager so that it can be registered as
/// being part of a Group.
///
///
/// Implementations of this method should ensure that returns
/// after this method is called.
///
/// The Interaction Group that this member is now a part of.
void OnRegisteringAsGroupMember(IXRInteractionGroup group);
///
/// An calls this method just after this member has been removed from the Group's
/// list or before the Group unregisters with the . This method is called
/// just before the member is re-registered with the Interaction Manager so that it can be registered as being
/// not part of a Group.
///
///
/// Implementations of this method should ensure that returns
/// after this method is called.
///
void OnRegisteringAsNonGroupMember();
}
///
/// Extension methods for .
///
///
[MovedFrom("UnityEngine.XR.Interaction.Toolkit")]
public static class XRGroupMemberExtensions
{
///
/// Gets the last Interaction Group in this Group member's chain of containing Groups that are contained within
/// other Groups. The Interaction Group returned will have no containing Group.
///
/// The Group member to operate on.
/// Returns the last Interaction Group in this Group member's chain of containing Groups that are
/// contained within other Groups. The Interaction Group returned will have no containing Group. Returns
/// if does not have a containing Group.
public static IXRInteractionGroup GetTopLevelContainingGroup(this IXRGroupMember groupMember)
{
var topLevelContainingGroup = groupMember.containingGroup;
var nextContainingGroup = topLevelContainingGroup;
while (nextContainingGroup != null)
{
topLevelContainingGroup = nextContainingGroup;
nextContainingGroup = topLevelContainingGroup is IXRGroupMember groupMemberGroup
? groupMemberGroup.containingGroup
: null;
}
return topLevelContainingGroup;
}
}
}