/// <summary> /// The character perspective between first and third person has changed. /// </summary> /// <param name="firstPersonPerspective">Is the character in a first person perspective?</param> protected override void OnChangePerspectives(bool firstPersonPerspective) { base.OnChangePerspectives(firstPersonPerspective); // A new object is used for each perspective. var perspectiveItem = firstPersonPerspective ? m_Item.FirstPersonPerspectiveItem : m_Item.ThirdPersonPerspectiveItem; m_Object = perspectiveItem.GetVisibleObject(); m_ObjectTransform = m_Object.transform; m_ThrowableItemPerpectiveProperties = m_ActivePerspectiveProperties as IThrowableItemPerspectiveProperties; // OnChangePerspective will be called whether or not the throwable item is equipped. Only set the mesh renderer status if the item is equipped. if (m_Item.IsActive()) { // If the object has already been thrown then the mesh renderer should be disabled. if (m_InstantiatedThrownObject != null) { EnableObjectMeshRenderers(m_InstantiatedThrownObject.activeSelf); } else { EnableObjectMeshRenderers(!m_Thrown && !m_DisableVisibleObject); } if (m_Throwing && !m_Thrown) { // Setup the thrown object if the item is in the process of being thrown. var thrownObjectTransform = m_InstantiatedThrownObject.transform; thrownObjectTransform.parent = m_ObjectTransform.parent; var location = m_ThrowableItemPerpectiveProperties.ThrowLocation; thrownObjectTransform.SetPositionAndRotation(location.position, location.rotation); thrownObjectTransform.localScale = location.localScale; m_InstantiatedThrownObject.transform.SetLayerRecursively(m_StartLayer); } } }
/// <summary> /// Initialize the default values. /// </summary> protected override void Awake() { base.Awake(); m_TrajectoryObject = GetComponent <TrajectoryObject>(); m_CharacterLocomotion = m_Character.GetCachedComponent <UltimateCharacterLocomotion>(); m_CharacterTransform = m_CharacterLocomotion.transform; #if ULTIMATE_CHARACTER_CONTROLLER_VR m_VRThrowableItem = GetComponent <IVRThrowableItem>(); #endif if (m_ThrownObject != null && m_TrajectoryObject != null) { // The object has to be instantiated for GetComponent to work. var instantiatedThrownObject = ObjectPool.Instantiate(m_ThrownObject); var trajectoryCollider = instantiatedThrownObject.GetComponent <Collider>(); if (trajectoryCollider != null) { // Only sphere and capsules are supported. if (trajectoryCollider is SphereCollider) { var trajectorySphereCollider = trajectoryCollider as SphereCollider; var sphereCollider = m_GameObject.AddComponent <SphereCollider>(); sphereCollider.center = trajectorySphereCollider.center; sphereCollider.radius = trajectorySphereCollider.radius; sphereCollider.enabled = false; } else if (trajectoryCollider is CapsuleCollider) { var trajectoryCapsuleCollider = trajectoryCollider as CapsuleCollider; var capsuleCollider = m_GameObject.AddComponent <CapsuleCollider>(); capsuleCollider.center = trajectoryCapsuleCollider.center; capsuleCollider.radius = trajectoryCapsuleCollider.radius; capsuleCollider.height = trajectoryCapsuleCollider.height; capsuleCollider.direction = trajectoryCapsuleCollider.direction; capsuleCollider.enabled = false; } else { Debug.LogError($"Error: The collider of type {trajectoryCollider.GetType()} is not supported on the trajectory object " + m_ThrownObject.name); } m_GameObject.layer = LayerManager.SubCharacter; } ObjectPool.Destroy(instantiatedThrownObject); } m_ThrowableItemPerpectiveProperties = m_ActivePerspectiveProperties as IThrowableItemPerspectiveProperties; if (m_ShowTrajectoryOnAim && m_TrajectoryObject == null) { Debug.LogError($"Error: A TrajectoryObject must be added to the {m_GameObject.name} GameObject in order for the trajectory to be shown."); } if (m_ThrownObject == null) { Debug.LogError($"Error: A ThrownObject must be assigned to the {m_GameObject.name} GameObject."); } EventHandler.RegisterEvent <bool, bool>(m_Character, "OnAimAbilityStart", OnAim); EventHandler.RegisterEvent(m_Character, "OnAnimatorReequipThrowableItem", ReequipThrowableItem); }
/// <summary> /// Initialize the visible object transform. /// </summary> protected override void Start() { var perspectiveItem = m_CharacterLocomotion.FirstPersonPerspective ? m_Item.FirstPersonPerspectiveItem : m_Item.ThirdPersonPerspectiveItem; m_Object = perspectiveItem.GetVisibleObject(); m_ObjectTransform = m_Object.transform; var firstPersonPerspectiveItem = m_Item.FirstPersonPerspectiveItem; if (firstPersonPerspectiveItem != null) { var visibleObject = firstPersonPerspectiveItem.GetVisibleObject(); if (visibleObject != null) { m_FirstPersonObjectMeshRenderers = visibleObject.GetComponentsInChildren <MeshRenderer>(true); } } var thirdPersonPerspectiveItem = m_Item.ThirdPersonPerspectiveItem; if (thirdPersonPerspectiveItem != null) { var visibleObject = thirdPersonPerspectiveItem.GetVisibleObject(); if (visibleObject != null) { m_ThirdPersonObjectMeshRenderers = visibleObject.GetComponentsInChildren <MeshRenderer>(true); } } if (m_ThrowableItemPerpectiveProperties == null) { m_ThrowableItemPerpectiveProperties = m_ActivePerspectiveProperties as IThrowableItemPerspectiveProperties; if (m_ThrowableItemPerpectiveProperties == null) { Debug.LogError($"Error: The First/Third Person Throwable Item Properties component cannot be found for the Item {name}." + $"Ensure the component exists and the component's Action ID matches the Action ID of the Item ({m_ID})."); } } // A consumed ItemIdentifier must be specified. If no ItemIdentifier is specified then the item's ItemIdentifier will be used. // The consumed ItemIdentifier is used by the inventory to determine the amount of items remain. if (m_ConsumableItemIdentifier == null) { m_ConsumableItemIdentifier = m_Item.ItemIdentifier; } EnableObjectMeshRenderers(!m_Throwing && CanActivateVisibleObject()); }
/// <summary> /// Initialize the visible object transform. /// </summary> protected override void Start() { var perspectiveItem = m_CharacterLocomotion.FirstPersonPerspective ? m_Item.FirstPersonPerspectiveItem : m_Item.ThirdPersonPerspectiveItem; m_Object = perspectiveItem.GetVisibleObject(); m_ObjectTransform = m_Object.transform; var firstPersonPerspectiveItem = m_Item.FirstPersonPerspectiveItem; if (firstPersonPerspectiveItem != null) { var visibleObject = firstPersonPerspectiveItem.GetVisibleObject(); if (visibleObject != null) { m_FirstPersonObjectRenderers = visibleObject.GetComponentsInChildren <Renderer>(true); } } var thirdPersonPerspectiveItem = m_Item.ThirdPersonPerspectiveItem; if (thirdPersonPerspectiveItem != null) { var visibleObject = thirdPersonPerspectiveItem.GetVisibleObject(); if (visibleObject != null) { m_ThirdPersonObjectRenderers = visibleObject.GetComponentsInChildren <Renderer>(true); } } if (m_ThrowableItemPerpectiveProperties == null) { m_ThrowableItemPerpectiveProperties = m_ActivePerspectiveProperties as IThrowableItemPerspectiveProperties; if (m_ThrowableItemPerpectiveProperties == null) { Debug.LogError($"Error: The First/Third Person Throwable Item Properties component cannot be found for the Item {name}." + $"Ensure the component exists and the component's Action ID matches the Action ID of the Item ({m_ID})."); } } m_Initialized = true; EnableObjectMeshRenderers(!m_Throwing && CanActivateVisibleObject()); }