/// <summary>
/// Adds or removes the instantiated reloadable clip.
/// </summary>
/// <param name="add">Should the reloadable clip be instantiated?</param>
/// <param name="firstPerson">Is the first person perspective being affected?</param>
private void AddRemoveReloadableClip(bool add, bool firstPerson)
{
var reloadClipPrefab = m_ReloadAddClipPrefab ?? m_ReloadDropClipPrefab;
// If the perspective properties is null then that perspective isn't setup for the character.
if (reloadClipPrefab == null) {
return;
}
// If the clip can't be detached then the weapon's clip shouldn't be disabled.
if (!m_ReloadDetachAttachClip) {
return;
}
var reloadableClip = GetReloadableClip(firstPerson);
if (reloadableClip == null) {
return;
}
var reloadableClipAttachment = GetReloadableClipAttachment(firstPerson);
if (add) {
var clip = ObjectPoolBase.Instantiate(reloadClipPrefab, reloadableClip.position, reloadableClip.rotation);
var remover = clip.GetCachedComponent<Remover>();
if (remover != null) {
remover.CancelRemoveEvent();
}
// The first person perspective requires the clip to be on the overlay layer so the fingers won't render in front of the clip.
clip.transform.SetLayerRecursively(firstPerson ? LayerManager.Overlay : clip.layer);
clip.transform.SetParentOrigin(reloadableClipAttachment);
clip.transform.SetPositionAndRotation(reloadableClip.position, reloadableClip.rotation);
if (firstPerson) {
m_FirstPersonReloadAddClip = clip;
m_FirstPersonReloadAddClip.SetActive(CharacterLocomotion.FirstPersonPerspective);
} else {
m_ThirdPersonReloadAddClip = clip;
m_ThirdPersonReloadAddClip.SetActive(!CharacterLocomotion.FirstPersonPerspective);
}
} else {
var clip = firstPerson ? m_FirstPersonReloadAddClip : m_ThirdPersonReloadAddClip;
if (clip != null) {
ObjectPoolBase.Destroy(clip);
if (firstPerson) {
m_FirstPersonReloadAddClip = null;
} else {
m_ThirdPersonReloadAddClip = null;
}
}
reloadableClip.gameObject.SetActive(true);
}
}