Update
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Items.Actions.PerspectiveProperties;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Describes any third person perspective dependent properties for the flashlight.
|
||||
/// </summary>
|
||||
public class ThirdPersonFlashlightProperties : ThirdPersonItemProperties, IFlashlightPerspectiveProperties
|
||||
{
|
||||
[Tooltip("A reference to the light used by the flashlight.")]
|
||||
[SerializeField] protected GameObject m_Light;
|
||||
|
||||
[Opsive.Shared.Utility.NonSerialized] public GameObject Light { get { return m_Light; } set { m_Light = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the default values.
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
m_Light.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 845cb7c93d20f4f438f86b0e5aa4f698
|
||||
timeCreated: 1503067772
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -50
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,59 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Character;
|
||||
using Opsive.UltimateCharacterController.Items.Actions.PerspectiveProperties;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Describes any third person perspective dependent properties for the GrenadeItem.
|
||||
/// </summary>
|
||||
public class ThirdPersonGrenadeItemProperties : ThirdPersonThrowableItemProperties, IGrenadeItemPerspectiveProperties
|
||||
{
|
||||
[Tooltip("A reference to the pin attachment transform.")]
|
||||
[SerializeField] protected Transform m_PinAttachmentLocation;
|
||||
[Tooltip("The ID of the pin attachment transform. This field will be used if the value is not -1 and the location is null.")]
|
||||
[SerializeField] protected int m_PinAttachmentLocationID = -1;
|
||||
|
||||
[Opsive.Shared.Utility.NonSerialized] public Transform PinAttachmentLocation { get { return m_PinAttachmentLocation; } set { m_PinAttachmentLocation = value; } }
|
||||
[Opsive.Shared.Utility.NonSerialized] public int PinAttachmentLocationID { get { return m_PinAttachmentLocationID; } set { m_PinAttachmentLocationID = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the default values.
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
// If the ID is not -1 then find the transform that it will attach to.
|
||||
if (m_PinAttachmentLocation == null && m_PinAttachmentLocationID != -1) {
|
||||
var character = GetComponentInParent<UltimateCharacterLocomotion>();
|
||||
var objectIdentifiers = character.gameObject.GetComponentsInChildren<Objects.ObjectIdentifier>();
|
||||
if (objectIdentifiers.Length > 0) {
|
||||
for (int i = 0; i < objectIdentifiers.Length; ++i) {
|
||||
#if FIRST_PERSON_CONTROLLER
|
||||
// The first person attachments should be filtered out.
|
||||
if (objectIdentifiers[i].GetComponentInParent<FirstPersonController.Character.FirstPersonObjects>() != null) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (objectIdentifiers[i].ID == m_PinAttachmentLocationID) {
|
||||
m_PinAttachmentLocation = objectIdentifiers[i].transform;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If no IDs match then log a warning and assign the first transform.
|
||||
if (m_PinAttachmentLocation == null) {
|
||||
Debug.LogWarning("Warning: Unable to find the third person pin attachment ObjectIdentifier with the ID " + m_PinAttachmentLocationID + " for item " + name + ".");
|
||||
m_PinAttachmentLocation = objectIdentifiers[0].transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a96b345141e48cc41b0946b4406cbd8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -51
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,18 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Items;
|
||||
|
||||
/// <summary>
|
||||
/// Describes any third person perspective dependent properties for the item.
|
||||
/// </summary>
|
||||
public abstract class ThirdPersonItemProperties : ItemPerspectiveProperties
|
||||
{
|
||||
public override bool FirstPersonItem { get { return false; } }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca8cfba408bce0e4f88f7b67fcffe915
|
||||
timeCreated: 1507594997
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,22 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Items.Actions.PerspectiveProperties;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Describes any third person perspective dependent properties for the magic item.
|
||||
/// </summary>
|
||||
public class ThirdPersonMagicItemProperties : ThirdPersonItemProperties, IMagicItemPerspectiveProperties
|
||||
{
|
||||
[Tooltip("The location that the magic originates from.")]
|
||||
[SerializeField] protected Transform m_OriginLocation;
|
||||
|
||||
public Transform OriginLocation { get { return m_OriginLocation; } set { m_OriginLocation = value; } }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a3b0504779f571418ec05e45a544070
|
||||
timeCreated: 1503067772
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -50
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,40 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Items.Actions;
|
||||
using Opsive.UltimateCharacterController.Items.Actions.PerspectiveProperties;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Describes any third person perspective dependent properties for the MeleeWeapon.
|
||||
/// </summary>
|
||||
public class ThirdPersonMeleeWeaponProperties : ThirdPersonWeaponProperties, IMeleeWeaponPerspectiveProperties
|
||||
{
|
||||
[Tooltip("An array of hitboxes that the MeleeWeapon detects collisions with.")]
|
||||
[SerializeField] protected MeleeWeapon.MeleeHitbox[] m_Hitboxes;
|
||||
[Tooltip("The location that the melee weapon trail is spawned at.")]
|
||||
[SerializeField] protected Transform m_TrailLocation;
|
||||
|
||||
public MeleeWeapon.MeleeHitbox[] Hitboxes { get { return m_Hitboxes; } set { m_Hitboxes = value; } }
|
||||
public Transform TrailLocation { get { return m_TrailLocation; } set { m_TrailLocation = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the default values.
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
for (int i = 0; i < m_Hitboxes.Length; ++i) {
|
||||
if (!m_Hitboxes[i].Initialize(m_Object, m_CharacterTransform)) {
|
||||
Debug.LogError($"Error: Unable to initialize {name}. Ensure the weapon has a collider.", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 336c8468bb0567e40a4cde260cccde9e
|
||||
timeCreated: 1503067772
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -50
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,244 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
using Opsive.Shared.Events;
|
||||
using Opsive.Shared.Game;
|
||||
using Opsive.Shared.Utility;
|
||||
using Opsive.UltimateCharacterController.Character;
|
||||
using Opsive.UltimateCharacterController.Items;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Component which represents the item object actually rendererd.
|
||||
/// </summary>
|
||||
public class ThirdPersonPerspectiveItem : PerspectiveItem
|
||||
{
|
||||
[Tooltip("Should the Object object be spawned based on the character's humanoid bone?")]
|
||||
[SerializeField] protected bool m_UseParentHumanoidBone = true;
|
||||
[Tooltip("If using the humanoid bone, specifies which bone to use.")]
|
||||
[SerializeField] protected HumanBodyBones m_ParentHumanoidBone = HumanBodyBones.RightHand;
|
||||
[Tooltip("The location of the non-dominant hand which should be placed by the IK implementation.")]
|
||||
[SerializeField] protected Transform m_NonDominantHandIKTarget;
|
||||
[Tooltip("The location of the non-dominant hand hint which should be placed by the IK implementation.")]
|
||||
[SerializeField] protected Transform m_NonDominantHandIKTargetHint;
|
||||
[Tooltip("The transform that the item should be holstered to when unequipped.")]
|
||||
[SerializeField] protected Transform m_HolsterTarget;
|
||||
[Tooltip("The ID of the ObjectIdentifier component that the item should be holstered to when unequipped. This id will be used when holster target is null and the the ID is -1.")]
|
||||
[SerializeField] protected int m_HolsterID = -1;
|
||||
|
||||
[NonSerialized] public Transform NonDominantHandIKTarget { get { return m_NonDominantHandIKTarget; } set { m_NonDominantHandIKTarget = value; } }
|
||||
[NonSerialized] public Transform NonDominantHandIKTargetHint { get { return m_NonDominantHandIKTargetHint; } set { m_NonDominantHandIKTargetHint = value; } }
|
||||
[NonSerialized] public Transform HolsterTarget { get { return m_HolsterTarget; } set { m_HolsterTarget = value; } }
|
||||
|
||||
private CharacterIKBase m_CharacterIK;
|
||||
private Transform m_ParentBone;
|
||||
private Transform m_ObjectTransform;
|
||||
private Transform m_StartParentTransform;
|
||||
private Vector3 m_StartLocalPosition;
|
||||
private Quaternion m_StartLocalRotation;
|
||||
private bool m_PickedUp;
|
||||
|
||||
public override bool FirstPersonItem { get { return false; } }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the perspective item.
|
||||
/// </summary>
|
||||
/// <param name="character">The character GameObject that the item is parented to.</param>
|
||||
/// <returns>True if the item was initialized successfully.</returns>
|
||||
public override bool Initialize(GameObject character)
|
||||
{
|
||||
if (!base.Initialize(character)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_CharacterIK = m_Character.GetCachedComponent<CharacterIKBase>();
|
||||
|
||||
if (m_Object != null) {
|
||||
m_ObjectTransform = m_Object.transform;
|
||||
m_StartParentTransform = m_ObjectTransform.parent; // Represents the Items GameObject.
|
||||
m_StartLocalPosition = m_ObjectTransform.localPosition;
|
||||
m_StartLocalRotation = m_ObjectTransform.localRotation;
|
||||
m_ParentBone = m_StartParentTransform.parent; // Represents the bone that the item is equipped to.
|
||||
}
|
||||
|
||||
// If the holster ID isn't -1 then the HolsterTarget reference will contain the Transform that the item should be attached to.
|
||||
if (m_HolsterTarget == null && m_HolsterID != -1) {
|
||||
var objectIDs = m_Character.GetComponentsInChildren<Objects.ObjectIdentifier>();
|
||||
for (int i = 0; i < objectIDs.Length; ++i) {
|
||||
if (m_HolsterID == objectIDs[i].ID) {
|
||||
m_HolsterTarget = objectIDs[i].transform;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_HolsterTarget != null) {
|
||||
// The holster target will be enabled when the item is picked up.
|
||||
m_HolsterTarget.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
EventHandler.RegisterEvent<Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
|
||||
EventHandler.RegisterEvent(m_Character, "OnRespawn", OnRespawn);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the parent that the VisibleItem object should spawn at.
|
||||
/// </summary>
|
||||
/// <param name="character">The character that the item should spawn under.</param>
|
||||
/// <param name="slotID">The character slot that the VisibleItem object should spawn under.</param>
|
||||
/// <param name="parentToItemSlotID">Should the object be parented to the item slot ID?</param>
|
||||
/// <returns>The parent that the VisibleItem object should spawn at.</returns>
|
||||
protected override Transform GetSpawnParent(GameObject character, int slotID, bool parentToItemSlotID)
|
||||
{
|
||||
Transform parent = null;
|
||||
// If using a humanoid bone then use the character's Animator to find the bone and then get the ItemPlacement component from that bone.
|
||||
if (m_UseParentHumanoidBone) {
|
||||
var characterAnimator = character.GetCachedComponent<Animator>();
|
||||
if (characterAnimator != null) {
|
||||
parent = characterAnimator.GetBoneTransform(m_ParentHumanoidBone);
|
||||
if (parent != null) {
|
||||
var itemSlot = parent.GetComponentInChildren<ItemSlot>(true);
|
||||
if (itemSlot != null) {
|
||||
parent = itemSlot.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to using the ItemSlot ID.
|
||||
if (parent == null) {
|
||||
var itemSlots = character.GetComponentsInChildren<ItemSlot>(true);
|
||||
for (int i = 0; i < itemSlots.Length; ++i) {
|
||||
if (itemSlots[i].ID == slotID) {
|
||||
parent = itemSlots[i].transform;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the VisibleItem active?
|
||||
/// </summary>
|
||||
/// <returns>True if the VisibleItem is active.</param>
|
||||
public override bool IsActive()
|
||||
{
|
||||
// If a holster target is specified then the VisibleItem will never completely deactivate. Determine if it is active by the Transform parent.
|
||||
if (m_HolsterTarget != null) {
|
||||
return m_ObjectTransform.parent == m_StartParentTransform;
|
||||
} else {
|
||||
if (m_Object == null) {
|
||||
return m_Item.VisibleObjectActive;
|
||||
}
|
||||
return base.IsActive();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates or deactivates the VisibleItem.
|
||||
/// </summary>
|
||||
/// <param name="active">Should the VisibleItem be activated?</param>
|
||||
public override void SetActive(bool active)
|
||||
{
|
||||
// If a holster target is specified then deactivating the VisibleItem will mean setting the parent transform of the object to that holster target.
|
||||
if (m_HolsterTarget != null) {
|
||||
if (active) {
|
||||
m_ObjectTransform.parent = m_StartParentTransform;
|
||||
m_ObjectTransform.localPosition = m_StartLocalPosition;
|
||||
m_ObjectTransform.localRotation = m_StartLocalRotation;
|
||||
} else {
|
||||
m_ObjectTransform.parent = m_HolsterTarget;
|
||||
m_ObjectTransform.localPosition = Vector3.zero;
|
||||
m_ObjectTransform.localRotation = Quaternion.identity;
|
||||
}
|
||||
} else if (m_Object != null) {
|
||||
// Allow the base object to activate or deactivate the actual object.
|
||||
base.SetActive(active);
|
||||
}
|
||||
|
||||
// When the item activates or deactivates it should specify the IK target of the non-dominant hand (if any).
|
||||
if (m_CharacterIK != null) {
|
||||
m_CharacterIK.SetItemIKTargets(active ? m_ObjectTransform : null, m_ParentBone, active ? m_NonDominantHandIKTarget : null, active ? m_NonDominantHandIKTargetHint : null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The VisibleItem has been picked up by the character.
|
||||
/// </summary>
|
||||
public override void Pickup()
|
||||
{
|
||||
base.Pickup();
|
||||
|
||||
m_PickedUp = true;
|
||||
|
||||
// The object should always be active if it is holstered.
|
||||
if (m_HolsterTarget != null) {
|
||||
m_Object.SetActive(true);
|
||||
|
||||
// The holster target will be disabled until the character picks up the item.
|
||||
m_HolsterTarget.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The item has been removed.
|
||||
/// </summary>
|
||||
public override void Remove()
|
||||
{
|
||||
base.Remove();
|
||||
|
||||
m_PickedUp = false;
|
||||
|
||||
// The object should always be active if it is holstered.
|
||||
if (m_HolsterTarget != null) {
|
||||
m_HolsterTarget.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The character has died.
|
||||
/// </summary>
|
||||
/// <param name="position">The position of the force.</param>
|
||||
/// <param name="force">The amount of force which killed the character.</param>
|
||||
/// <param name="attacker">The GameObject that killed the character.</param>
|
||||
private void OnDeath(Vector3 position, Vector3 force, GameObject attacker)
|
||||
{
|
||||
// When the character dies disable the holster. Do not disable the item's object because that may not be activated again
|
||||
// when the character respawns, whereas the holster target should always be activated since it's an empty GameObject.
|
||||
if (m_HolsterTarget != null && m_PickedUp) {
|
||||
m_HolsterTarget.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The character has respawned.
|
||||
/// </summary>
|
||||
private void OnRespawn()
|
||||
{
|
||||
if (m_HolsterTarget != null && m_PickedUp) {
|
||||
m_HolsterTarget.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the item is destroyed.
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (m_Character == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EventHandler.UnregisterEvent<Vector3, Vector3, GameObject>(m_Character, "OnDeath", OnDeath);
|
||||
EventHandler.UnregisterEvent(m_Character, "OnRespawn", OnRespawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5b5dc98af0593b4589b67fcfc5b4c85
|
||||
timeCreated: 1495587608
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,189 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
using Opsive.Shared.Events;
|
||||
using Opsive.Shared.Utility;
|
||||
using Opsive.UltimateCharacterController.Character;
|
||||
using Opsive.UltimateCharacterController.Items.Actions.PerspectiveProperties;
|
||||
using Opsive.UltimateCharacterController.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Describes any third person perspective dependent properties for the ShootableWeapon.
|
||||
/// </summary>
|
||||
public class ThirdPersonShootableWeaponProperties : ThirdPersonWeaponProperties, IShootableWeaponPerspectiveProperties
|
||||
{
|
||||
[Tooltip("The sensitivity amount for how much the weapon must be looking in the look source direction (-1 is least sensitive and 1 is most).")]
|
||||
[Range(-1, 1)] [SerializeField] protected float m_LookSensitivity = 0.97f;
|
||||
[Tooltip("The location that the weapon is fired at.")]
|
||||
[SerializeField] protected Transform m_FirePointLocation;
|
||||
[Tooltip("The transform that the fire point should be attached to.")]
|
||||
[SerializeField] protected Transform m_FirePointAttachmentLocation;
|
||||
[Tooltip("The ID of the transform that the fire point should be attached to. This field will be used if the value is not -1 and the attachment is null.")]
|
||||
[SerializeField] protected int m_FirePointAttachmentLocationID = -1;
|
||||
[Tooltip("The location that the muzzle flash is spawned at.")]
|
||||
[SerializeField] protected Transform m_MuzzleFlashLocation;
|
||||
[Tooltip("The location that the shell is ejected at.")]
|
||||
[SerializeField] protected Transform m_ShellLocation;
|
||||
[Tooltip("The location that the smoke is spawned at.")]
|
||||
[SerializeField] protected Transform m_SmokeLocation;
|
||||
[Tooltip("The location that the tracer is spawned at.")]
|
||||
[SerializeField] protected Transform m_TracerLocation;
|
||||
[Tooltip("A reference to the weapon's clip that can be reloaded.")]
|
||||
[SerializeField] protected Transform m_ReloadableClip;
|
||||
[Tooltip("A reference to the reloadable clip attachment transform.")]
|
||||
[SerializeField] protected Transform m_ReloadableClipAttachment;
|
||||
[Tooltip("The ID of the reloadable clip attachment transform. This field will be used if the value is not -1 and the attachment is null.")]
|
||||
[SerializeField] protected int m_ReloadableClipAttachmentID = -1;
|
||||
[Tooltip("A reference to the attachment transform that the projectile should be parented to when reloading.")]
|
||||
[SerializeField] protected Transform m_ReloadProjectileAttachment;
|
||||
[Tooltip("The ID of the attachment transform that hte projectile should be parented to when reloading. This field will be used if the value is not -1 and the attachment is null.")]
|
||||
[SerializeField] protected int m_ReloadProjectileAttachmentID = -1;
|
||||
[Tooltip("Optionally specify if the weapon has a camera for the scope.")]
|
||||
[SerializeField] protected GameObject m_ScopeCamera;
|
||||
|
||||
public float LookSensitivity { get { return m_LookSensitivity; } set { m_LookSensitivity = value; } }
|
||||
[NonSerialized] public Transform FirePointLocation { get { return m_FirePointLocation; } set { m_FirePointLocation = value; } }
|
||||
[NonSerialized] public Transform MuzzleFlashLocation { get { return m_MuzzleFlashLocation; } set { m_MuzzleFlashLocation = value; } }
|
||||
[NonSerialized] public Transform ShellLocation { get { return m_ShellLocation; } set { m_ShellLocation = value; } }
|
||||
[NonSerialized] public Transform SmokeLocation { get { return m_SmokeLocation; } set { m_SmokeLocation = value; } }
|
||||
[NonSerialized] public Transform TracerLocation { get { return m_TracerLocation; } set { m_TracerLocation = value; } }
|
||||
[NonSerialized] public Transform ReloadableClip { get { return m_ReloadableClip; } set { m_ReloadableClip = value; } }
|
||||
[NonSerialized] public Transform ReloadableClipAttachment { get { return m_ReloadableClipAttachment; } set { m_ReloadableClipAttachment = value; } }
|
||||
[NonSerialized] public int ReloadableClipAttachmentID { get { return m_ReloadableClipAttachmentID; } set { m_ReloadableClipAttachmentID = value; } }
|
||||
[NonSerialized] public Transform ReloadProjectileAttachment { get { return m_ReloadProjectileAttachment; } set { m_ReloadProjectileAttachment = value; } }
|
||||
[NonSerialized] public int ReloadProjectileAttachmentID { get { return m_ReloadProjectileAttachmentID; } set { m_ReloadProjectileAttachmentID = value; } }
|
||||
[NonSerialized] public GameObject ScopeCamera { get { return m_ScopeCamera; } set { m_ScopeCamera = value; } }
|
||||
|
||||
private ILookSource m_LookSource;
|
||||
private Transform m_ObjectTransform;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private float m_LastLookSensitivity;
|
||||
private int m_ConsistantLookSensitivityCount;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the default values.
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
m_ObjectTransform = m_Object.transform;
|
||||
// The look source is used to determine if the item is facing in the forward direction.
|
||||
m_LookSource = m_CharacterLocomotion.LookSource;
|
||||
|
||||
// The item may be added at runtime while the attachment transform is located on the character.
|
||||
if (m_FirePointAttachmentLocationID != -1 || (m_ReloadableClipAttachment == null && m_ReloadableClip != null) || m_ReloadProjectileAttachmentID != -1) {
|
||||
var character = GetComponentInParent<UltimateCharacterLocomotion>();
|
||||
var objectIdentifiers = character.GetComponentsInChildren<Objects.ObjectIdentifier>();
|
||||
if (objectIdentifiers.Length > 0) {
|
||||
for (int i = 0; i < objectIdentifiers.Length; ++i) {
|
||||
#if FIRST_PERSON_CONTROLLER
|
||||
// The first person attachments should be filtered out.
|
||||
if (objectIdentifiers[i].GetComponentInParent<FirstPersonController.Character.FirstPersonObjects>() != null) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (objectIdentifiers[i].ID == m_FirePointAttachmentLocationID) {
|
||||
m_FirePointAttachmentLocation = objectIdentifiers[i].transform;
|
||||
} else if (objectIdentifiers[i].ID == m_ReloadableClipAttachmentID) {
|
||||
m_ReloadableClipAttachment = objectIdentifiers[i].transform;
|
||||
} else if (objectIdentifiers[i].ID == m_ReloadProjectileAttachmentID) {
|
||||
m_ReloadProjectileAttachment = objectIdentifiers[i].transform;
|
||||
}
|
||||
|
||||
// If the references are found then the loop can end early.
|
||||
if ((m_ReloadableClip == null || m_ReloadableClipAttachmentID == -1 || m_ReloadableClipAttachment != null) &&
|
||||
(m_FirePointAttachmentLocationID == -1 || m_FirePointAttachmentLocation != null) &&
|
||||
(m_ReloadProjectileAttachmentID == -1 || m_ReloadProjectileAttachment != null)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If no IDs match then log a warning.
|
||||
if (m_FirePointAttachmentLocation == null && m_FirePointAttachmentLocationID != -1) {
|
||||
Debug.LogWarning("Warning: Unable to find the third person fire point attachment ObjectIdentifier with the ID " + m_FirePointAttachmentLocationID + " for item " + name + ".");
|
||||
}
|
||||
if (m_ReloadableClipAttachment == null && m_ReloadableClip != null && m_ReloadableClipAttachmentID != -1) {
|
||||
Debug.LogWarning("Warning: Unable to find the third person reload attachment ObjectIdentifier with the ID " + m_ReloadableClipAttachmentID + " for item " + name + ".");
|
||||
}
|
||||
if (m_ReloadProjectileAttachment == null && m_ReloadProjectileAttachmentID != -1) {
|
||||
Debug.LogWarning("Warning: Unable to find the third person reload projectile ObjectIdentifier with the ID " + m_ReloadProjectileAttachmentID + " for item " + name + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_FirePointAttachmentLocation != null) {
|
||||
// If the fire point is null then the found attachment transform becomes the firepoint. If it is not null then the parent is set.
|
||||
if (m_FirePointLocation == null) {
|
||||
m_FirePointLocation = m_FirePointAttachmentLocation;
|
||||
} else {
|
||||
m_FirePointLocation.SetParentOrigin(m_FirePointAttachmentLocation);
|
||||
}
|
||||
}
|
||||
|
||||
EventHandler.RegisterEvent<ILookSource>(m_Character, "OnCharacterAttachLookSource", OnAttachLookSource);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A new ILookSource object has been attached to the character.
|
||||
/// </summary>
|
||||
/// <param name="lookSource">The ILookSource object attached to the character.</param>
|
||||
private void OnAttachLookSource(ILookSource lookSource)
|
||||
{
|
||||
m_LookSource = lookSource;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can the weapon be fired?
|
||||
/// </summary>
|
||||
/// <param name="fireInLookSourceDirection">Should the weapon fire in the LookSource direction?</param>
|
||||
/// <param name="abilityActive">Is the Use ability active?</param>
|
||||
/// <returns>True if the item can be fired.</returns>
|
||||
public bool CanFire(bool abilityActive, bool fireInLookSourceDirection)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!abilityActive) {
|
||||
m_LastLookSensitivity = -1;
|
||||
m_ConsistantLookSensitivityCount = 0;
|
||||
}
|
||||
#endif
|
||||
// The object has to be facing in the same general direction as the look source. When the ability is not active the direction shouldn't prevent
|
||||
// the ability from starting. This will allow the weapon to move to the correct direction while the ability is active.
|
||||
if (abilityActive && fireInLookSourceDirection) {
|
||||
var lookSensitivity = Vector3.Dot(m_ObjectTransform.forward, m_LookSource.LookDirection(m_ObjectTransform.position, false, 0, true));
|
||||
#if UNITY_EDITOR
|
||||
// A common cause for the weapon not being able to fire is because of the look sensitivity. Add a check to display a warning if the look sensitivity is blocking the firing.
|
||||
if (lookSensitivity <= m_LookSensitivity && m_ConsistantLookSensitivityCount != -1) {
|
||||
if (Mathf.Abs(m_LastLookSensitivity - lookSensitivity) < 0.05f) {
|
||||
m_ConsistantLookSensitivityCount++;
|
||||
if (m_ConsistantLookSensitivityCount > 10) {
|
||||
Debug.LogWarning("Warning: The ShootableWeapon is unable to fire because of the Look Sensitivity on the ShootableWeaponProperties. See this page for more info: " +
|
||||
"https://opsive.com/support/documentation/ultimate-character-controller/items/actions/usable/shootable-weapon/", this);
|
||||
m_ConsistantLookSensitivityCount = -1;
|
||||
}
|
||||
} else {
|
||||
m_ConsistantLookSensitivityCount = 0;
|
||||
}
|
||||
m_LastLookSensitivity = lookSensitivity;
|
||||
}
|
||||
#endif
|
||||
return lookSensitivity > m_LookSensitivity;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object has been destroyed.
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
EventHandler.UnregisterEvent<ILookSource>(m_Character, "OnCharacterAttachLookSource", OnAttachLookSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94852f5f099f81e4d8109368c13a11e2
|
||||
timeCreated: 1503067773
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -75
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,25 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Items.Actions.PerspectiveProperties;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Describes any third person perspective dependent properties for the ThrowableItem.
|
||||
/// </summary>
|
||||
public class ThirdPersonThrowableItemProperties : ThirdPersonWeaponProperties, IThrowableItemPerspectiveProperties
|
||||
{
|
||||
[Tooltip("The location to throw the object from.")]
|
||||
[SerializeField] protected Transform m_ThrowLocation;
|
||||
[Tooltip("The location of the trajectory curve.")]
|
||||
[SerializeField] protected Transform m_TrajectoryLocation;
|
||||
|
||||
[Opsive.Shared.Utility.NonSerialized] public Transform ThrowLocation { get { return m_ThrowLocation; } set { m_ThrowLocation = value; } }
|
||||
[Opsive.Shared.Utility.NonSerialized] public Transform TrajectoryLocation { get { return m_TrajectoryLocation; } set { m_TrajectoryLocation = value; } }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d8c4c0c251308b4d88796d86345e6f2
|
||||
timeCreated: 1503067772
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -50
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,15 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.ThirdPersonController.Items
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes any third person perspective dependent properties for the Weapon.
|
||||
/// </summary>
|
||||
public abstract class ThirdPersonWeaponProperties : ThirdPersonItemProperties
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24263c18edd00a749a7c1e4beccccf66
|
||||
timeCreated: 1498481229
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user