Update
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.Items.AnimatorAudioStates
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Character;
|
||||
using Opsive.UltimateCharacterController.StateSystem;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The AnimatorAudioState will return a Item Substate Index parameter based on the object's state.
|
||||
/// </summary>
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
public abstract class AnimatorAudioStateSelector
|
||||
{
|
||||
protected Item m_Item;
|
||||
protected GameObject m_Character;
|
||||
protected UltimateCharacterLocomotion m_CharacterLocomotion;
|
||||
protected AnimatorAudioStateSet.AnimatorAudioState[] m_States;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the selector.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The GameObject that the state belongs to.</param>
|
||||
/// <param name="characterLocomotion">The character that the state bleongs to.</param>
|
||||
/// <param name="item">The item that the state belongs to.</param>
|
||||
/// <param name="states">The states which are being selected.</param>
|
||||
public virtual void Initialize(GameObject gameObject, UltimateCharacterLocomotion characterLocomotion, Item item, AnimatorAudioStateSet.AnimatorAudioState[] states)
|
||||
{
|
||||
m_Item = item;
|
||||
m_Character = characterLocomotion.gameObject;
|
||||
m_CharacterLocomotion = characterLocomotion;
|
||||
m_States = states;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts or stops the state selection. Will activate or deactivate the state with the name specified within the AnimatorAudioState.
|
||||
/// </summary>
|
||||
/// <param name="start">Is the object starting?</param>
|
||||
public virtual void StartStopStateSelection(bool start)
|
||||
{
|
||||
// Activate or deactivate the state.
|
||||
var stateIndex = GetStateIndex();
|
||||
if (stateIndex == -1 || stateIndex >= m_States.Length) {
|
||||
return;
|
||||
}
|
||||
|
||||
var stateName = m_States[stateIndex].StateName;
|
||||
if (string.IsNullOrEmpty(stateName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
StateManager.SetState(m_Character, stateName, start);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current state index. -1 indicates this index is not set by the class.
|
||||
/// </summary>
|
||||
/// <returns>The current state index.</returns>
|
||||
public virtual int GetStateIndex()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next state.
|
||||
/// </summary>
|
||||
/// <returns>Was the state changed successfully?</returns>
|
||||
public virtual bool NextState() { return true; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the state at the specified index valid?
|
||||
/// </summary>
|
||||
/// <param name="index">The index to check the state of.</param>
|
||||
/// <returns>True if the state at the specified index is valid.</returns>
|
||||
protected bool IsStateValid(int index) { return (m_States[index].AllowDuringMovement || !m_CharacterLocomotion.Moving) &&
|
||||
(!m_States[index].RequireGrounded || m_CharacterLocomotion.Grounded); }
|
||||
|
||||
/// <summary>
|
||||
/// Returns an additional value that should be added to the Item Substate Index.
|
||||
/// </summary>
|
||||
/// <returns>An additional value that should be added to the Item Substate Index.</returns>
|
||||
public virtual int GetAdditionalItemSubstateIndex() { return 0; }
|
||||
|
||||
/// <summary>
|
||||
/// The selector has been destroyed.
|
||||
/// </summary>
|
||||
public virtual void OnDestroy() { }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8221a8d305f63f945aa70c31c68d83fc
|
||||
timeCreated: 1506087731
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,232 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.Items.AnimatorAudioStates
|
||||
{
|
||||
using Opsive.Shared.Utility;
|
||||
using Opsive.UltimateCharacterController.Audio;
|
||||
using Opsive.UltimateCharacterController.StateSystem;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The AnimatorAudioStateSet represets a set of animation parameters and audio clips that should be played together.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class AnimatorAudioStateSet
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains a single animator and audio clip state.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class AnimatorAudioState : StateObject
|
||||
{
|
||||
[Tooltip("Is the AnimatorAudioState enabled?")]
|
||||
[SerializeField] protected bool m_Enabled = true;
|
||||
[Tooltip("Can the state be selected when the character is moving?")]
|
||||
[SerializeField] protected bool m_AllowDuringMovement = true;
|
||||
[Tooltip("Does the state require the character to be grounded?")]
|
||||
[SerializeField] protected bool m_RequireGrounded;
|
||||
[Tooltip("The name of the state that should be active when the animation is playing.")]
|
||||
[SerializeField] protected string m_StateName;
|
||||
[Tooltip("The value of the animator's Item Substate Index parameter.")]
|
||||
[SerializeField] protected int m_ItemSubstateIndex;
|
||||
[Tooltip("Contains an array of AudioClips.")]
|
||||
[SerializeField] protected AudioClipSet m_AudioClipSet = new AudioClipSet();
|
||||
|
||||
public bool Enabled { get { return m_Enabled; } set { m_Enabled = value; } }
|
||||
public bool AllowDuringMovement { get { return m_AllowDuringMovement; } set { m_AllowDuringMovement = value; } }
|
||||
public bool RequireGrounded { get { return m_RequireGrounded; } set { m_RequireGrounded = value; } }
|
||||
public string StateName { get { return m_StateName; } set { m_StateName = value; } }
|
||||
public int ItemSubstateIndex { get { return m_ItemSubstateIndex; } set { m_ItemSubstateIndex = value; } }
|
||||
public AudioClipSet AudioClipSet { get { return m_AudioClipSet; } set { m_AudioClipSet = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor.
|
||||
/// </summary>
|
||||
public AnimatorAudioState() { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with one parameter.
|
||||
/// </summary>
|
||||
/// <param name="itemSubstateIndex">The value of the animator's Item Substate Index parameter.</param>
|
||||
public AnimatorAudioState(int itemSubstateIndex)
|
||||
{
|
||||
m_ItemSubstateIndex = itemSubstateIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plays the audio clip with a random set index.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The GameObject that is playing the audio clip.</param>
|
||||
/// <param name="reservedIndex">The index of the component that should be played. -1 indicates any component.</param>
|
||||
public void PlayAudioClip(GameObject gameObject, int reservedIndex)
|
||||
{
|
||||
m_AudioClipSet.PlayAudioClip(gameObject, reservedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
[Tooltip("The serialization data for the AnimatorAudioStateState.")]
|
||||
[SerializeField] protected Serialization m_AnimatorAudioStateSelectorData;
|
||||
[Tooltip("An array of possible states for the animator parameter and audio clip.")]
|
||||
[SerializeField] protected AnimatorAudioState[] m_States;
|
||||
|
||||
public Serialization AnimatorAudioStateSelectorData { get { return m_AnimatorAudioStateSelectorData; }
|
||||
set
|
||||
{
|
||||
m_AnimatorAudioStateSelectorData = value;
|
||||
if (!Application.isPlaying) {
|
||||
DeserializeAnimatorAudioStateSelector(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
public AnimatorAudioState[] States { get { return m_States; } set { m_States = value; } }
|
||||
|
||||
private AnimatorAudioStateSelector m_AnimatorAudioStateSelector;
|
||||
|
||||
public AnimatorAudioStateSelector AnimatorAudioStateSelector
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Application.isPlaying && m_AnimatorAudioStateSelector == null) { DeserializeAnimatorAudioStateSelector(null, null); }
|
||||
return m_AnimatorAudioStateSelector;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor.
|
||||
/// </summary>
|
||||
public AnimatorAudioStateSet()
|
||||
{
|
||||
var animatorAudioOutputSelector = System.Activator.CreateInstance(typeof(Sequence)) as AnimatorAudioStateSelector;
|
||||
m_AnimatorAudioStateSelectorData = Serialization.Serialize(animatorAudioOutputSelector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with one parameter.
|
||||
/// </summary>
|
||||
/// <param name="itemSubstateIndex">The value of the animator's Item Substate Index parameter.</param>
|
||||
public AnimatorAudioStateSet(int itemSubstateParameter) : this()
|
||||
{
|
||||
if (m_States == null) {
|
||||
m_States = new AnimatorAudioState[] { new AnimatorAudioState(itemSubstateParameter) };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the AnimatorAudioStateSelector data.
|
||||
/// </summary>
|
||||
/// <param name="item">A reference to the item that the state belongs to.</param>
|
||||
/// <param name="characterLocomotion">A reference to the character that the state belongs to.</param>
|
||||
public void DeserializeAnimatorAudioStateSelector(Item item, Character.UltimateCharacterLocomotion characterLocomotion)
|
||||
{
|
||||
if (m_AnimatorAudioStateSelectorData != null) {
|
||||
m_AnimatorAudioStateSelector = m_AnimatorAudioStateSelectorData.DeserializeFields(MemberVisibility.Public) as AnimatorAudioStateSelector;
|
||||
if (characterLocomotion != null && Application.isPlaying) {
|
||||
if (m_AnimatorAudioStateSelector != null) {
|
||||
m_AnimatorAudioStateSelector.Initialize(item.gameObject, characterLocomotion, item, m_States);
|
||||
} else {
|
||||
Debug.LogError("Error: The AnimatorAudioState is null. Select the item " + item.name + " within the inspector to serialize.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the default values.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The GameObject that the AnimatorAudioStateSet is attached to.</param>
|
||||
public void Awake(GameObject gameObject)
|
||||
{
|
||||
for (int i = 0; i < m_States.Length; ++i) {
|
||||
m_States[i].Initialize(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current state index of the selector. -1 indicates this index is not set by the class.
|
||||
/// </summary>
|
||||
/// <returns>The current state index.</returns>
|
||||
public int GetStateIndex()
|
||||
{
|
||||
if (m_AnimatorAudioStateSelector == null || m_States.Length == 0) {
|
||||
return -1;
|
||||
}
|
||||
return m_AnimatorAudioStateSelector.GetStateIndex();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts or stops the state selection. Will activate or deactivate the state with the name specified within the AnimatorAudioState.
|
||||
/// </summary>
|
||||
/// <param name="start">Is the object starting?</param>
|
||||
public void StartStopStateSelection(bool start)
|
||||
{
|
||||
m_AnimatorAudioStateSelector.StartStopStateSelection(start);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Item Substate Index parameter value. -1 indicates this value is not set by the class.
|
||||
/// </summary>
|
||||
/// <returns>The current Item Substate Index parameter value.</returns>
|
||||
public int GetItemSubstateIndex()
|
||||
{
|
||||
var stateIndex = GetStateIndex();
|
||||
if (stateIndex == -1 || stateIndex >= m_States.Length) {
|
||||
return -1;
|
||||
}
|
||||
return m_States[stateIndex].ItemSubstateIndex + m_AnimatorAudioStateSelector.GetAdditionalItemSubstateIndex();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plays the audio clip.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The GameObject that is playing the audio clip.</param>
|
||||
public void PlayAudioClip(GameObject gameObject)
|
||||
{
|
||||
PlayAudioClip(gameObject, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plays the audio clip.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The GameObject that is playing the audio clip.</param>
|
||||
/// <param name="reservedIndex">The index of the component that should be played. -1 indicates any component.</param>
|
||||
public void PlayAudioClip(GameObject gameObject, int reservedIndex)
|
||||
{
|
||||
if (m_AnimatorAudioStateSelector == null || m_States.Length == 0) {
|
||||
return;
|
||||
}
|
||||
var stateIndex = m_AnimatorAudioStateSelector.GetStateIndex();
|
||||
if (stateIndex == -1 || stateIndex >= m_States.Length) {
|
||||
return;
|
||||
}
|
||||
m_States[stateIndex].PlayAudioClip(gameObject, reservedIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next state of the selector.
|
||||
/// </summary>
|
||||
public bool NextState()
|
||||
{
|
||||
if (m_AnimatorAudioStateSelector == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_AnimatorAudioStateSelector.NextState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object has been destroyed.
|
||||
/// </summary>
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (m_AnimatorAudioStateSelector == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_AnimatorAudioStateSelector.OnDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb8de77a24a752b45ac2455791f423ad
|
||||
timeCreated: 1518730146
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
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.Items.AnimatorAudioStates
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The MatchingRecoil state will return the same state index as what was retrieved by the use state selector.
|
||||
/// </summary>
|
||||
public class MatchingRecoil : RecoilAnimatorAudioStateSelector
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the current state index. -1 indicates this index is not set by the class.
|
||||
/// </summary>
|
||||
/// <returns>The current state index.</returns>
|
||||
public override int GetStateIndex()
|
||||
{
|
||||
return m_UseStateIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3347f549befc39f48b7cc2a2a8359f80
|
||||
timeCreated: 1506089511
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,61 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.Items.AnimatorAudioStates
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Character;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The Random state will move from one state to another in a random order.
|
||||
/// </summary>
|
||||
public class Random : AnimatorAudioStateSelector
|
||||
{
|
||||
private int m_CurrentIndex = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the selector.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The GameObject that the state belongs to.</param>
|
||||
/// <param name="characterLocomotion">The character that the state bleongs to.</param>
|
||||
/// <param name="item">The item that the state belongs to.</param>
|
||||
/// <param name="states">The states which are being selected.</param>
|
||||
public override void Initialize(GameObject gameObject, UltimateCharacterLocomotion characterLocomotion, Item item, AnimatorAudioStateSet.AnimatorAudioState[] states)
|
||||
{
|
||||
base.Initialize(gameObject, characterLocomotion, item, states);
|
||||
|
||||
// Call next state so the index will be initialized to a random value.
|
||||
NextState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current state index. -1 indicates this index is not set by the class.
|
||||
/// </summary>
|
||||
/// <returns>The current state index.</returns>
|
||||
public override int GetStateIndex()
|
||||
{
|
||||
return m_CurrentIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next state.
|
||||
/// </summary>
|
||||
/// <returns>Was the state changed successfully?</returns>
|
||||
public override bool NextState()
|
||||
{
|
||||
var count = 0;
|
||||
var size = m_States.Length;
|
||||
if (size == 0) {
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
m_CurrentIndex = UnityEngine.Random.Range(0, size);
|
||||
++count;
|
||||
} while ((!IsStateValid(m_CurrentIndex) || !m_States[m_CurrentIndex].Enabled) && count <= size);
|
||||
return count <= size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff3afdb748f182d49b99fa43259778b8
|
||||
timeCreated: 1506089511
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,61 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.Items.AnimatorAudioStates
|
||||
{
|
||||
using Opsive.UltimateCharacterController.Character;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The RandomRecoil state will move from one state to another in a random order.
|
||||
/// </summary>
|
||||
public class RandomRecoil : RecoilAnimatorAudioStateSelector
|
||||
{
|
||||
private int m_CurrentIndex;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the selector.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The GameObject that the state belongs to.</param>
|
||||
/// <param name="characterLocomotion">The character that the state bleongs to.</param>
|
||||
/// <param name="item">The item that the state belongs to.</param>
|
||||
/// <param name="states">The states which are being selected.</param>
|
||||
public override void Initialize(GameObject gameObject, UltimateCharacterLocomotion characterLocomotion, Item item, AnimatorAudioStateSet.AnimatorAudioState[] states)
|
||||
{
|
||||
base.Initialize(gameObject, characterLocomotion, item, states);
|
||||
|
||||
// Call next state so the index will be initialized to a random value.
|
||||
NextState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current state index. -1 indicates this index is not set by the class.
|
||||
/// </summary>
|
||||
/// <returns>The current state index.</returns>
|
||||
public override int GetStateIndex()
|
||||
{
|
||||
return m_CurrentIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next state.
|
||||
/// </summary>
|
||||
/// <returns>Was the state changed successfully?</returns>
|
||||
public override bool NextState()
|
||||
{
|
||||
var count = 0;
|
||||
var size = m_States.Length;
|
||||
if (size == 0) {
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
m_CurrentIndex = UnityEngine.Random.Range(0, size);
|
||||
++count;
|
||||
} while ((!IsStateValid(m_CurrentIndex) || !m_States[m_CurrentIndex].Enabled) && count <= size);
|
||||
return count <= size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7615a4bfdfd14e84ab05257699c55770
|
||||
timeCreated: 1506089511
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,72 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.Items.AnimatorAudioStates
|
||||
{
|
||||
using Opsive.Shared.Game;
|
||||
using Opsive.UltimateCharacterController.Objects.ItemAssist;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The RecoilAnimatorAudioState will return a Item Substate Index parameter based on the object's recoil state.
|
||||
/// If the character hit a blocking object then the block recoil state index value will be added to the current index value.
|
||||
/// </summary>
|
||||
public abstract class RecoilAnimatorAudioStateSelector : AnimatorAudioStateSelector
|
||||
{
|
||||
[Tooltip("The base index when the melee weapon is blocked. The state's index will be added to this value.")]
|
||||
[SerializeField] protected int m_BlockedRecoilItemSubstateIndex;
|
||||
|
||||
protected int m_HitColliderCount;
|
||||
protected Collider[] m_HitColliders;
|
||||
protected int m_UseStateIndex;
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next state.
|
||||
/// </summary>
|
||||
/// <param name="hitCollidersCount">The number of colliders that were hit.</param>
|
||||
/// <param name="hitColliders">The colliders that were hit.</param>
|
||||
/// <param name="useStateIndex">The index that was played by the use state.</param>
|
||||
public virtual void NextState(int hitColliderCount, Collider[] hitColliders, int useStateIndex)
|
||||
{
|
||||
m_HitColliderCount = hitColliderCount;
|
||||
m_HitColliders = hitColliders;
|
||||
m_UseStateIndex = useStateIndex;
|
||||
NextState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an additional value that should be added to the Item Substate Index.
|
||||
/// </summary>
|
||||
/// <returns>An additional value that should be added to the Item Substate Index.</returns>
|
||||
public override int GetAdditionalItemSubstateIndex()
|
||||
{
|
||||
if (IsBlocked()) {
|
||||
return m_BlockedRecoilItemSubstateIndex;
|
||||
}
|
||||
return base.GetAdditionalItemSubstateIndex();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the item currently being blocked by an object that should cause recoil?
|
||||
/// </summary>
|
||||
/// <returns>True if the item is currently being blocked by an object that should cause recoil.</returns>
|
||||
private bool IsBlocked()
|
||||
{
|
||||
for (int i = 0; i < m_HitColliderCount; ++i) {
|
||||
ShieldCollider shieldCollider;
|
||||
var hitGameObject = m_HitColliders[i].gameObject;
|
||||
if ((shieldCollider = hitGameObject.GetCachedComponent<ShieldCollider>()) != null) {
|
||||
if (shieldCollider.Shield.DurabilityValue > 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (hitGameObject.GetCachedComponent<RecoilObject>() != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06c0311bc4b1f1d459ff2bcfaf60e01d
|
||||
timeCreated: 1506087731
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,66 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.Items.AnimatorAudioStates
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The Sequence state will move from one state to the in a sequence order.
|
||||
/// </summary>
|
||||
public class Sequence : AnimatorAudioStateSelector
|
||||
{
|
||||
[Tooltip("Resets the index back to the start after the specified delay. Set to -1 to never reset.")]
|
||||
[SerializeField] protected float m_ResetDelay = -1;
|
||||
|
||||
public float ResetDelay { get { return m_ResetDelay; } set { m_ResetDelay = value; } }
|
||||
|
||||
private int m_CurrentIndex = -1;
|
||||
private float m_LastUsedTime = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Starts or stops the state selection.
|
||||
/// </summary>
|
||||
/// <param name="start">Is the object starting?</param>
|
||||
public override void StartStopStateSelection(bool start)
|
||||
{
|
||||
base.StartStopStateSelection(start);
|
||||
|
||||
// The Sequence task can reset which index is returned if the next state is selected too slowly.
|
||||
if (start && m_ResetDelay != -1 && m_LastUsedTime != -1 && m_LastUsedTime + m_ResetDelay < Time.time) {
|
||||
m_CurrentIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current state index. -1 indicates this index is not set by the class.
|
||||
/// </summary>
|
||||
/// <returns>The current state index.</returns>
|
||||
public override int GetStateIndex()
|
||||
{
|
||||
return m_CurrentIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next state.
|
||||
/// </summary>
|
||||
/// <returns>Was the state changed successfully?</returns>
|
||||
public override bool NextState()
|
||||
{
|
||||
m_LastUsedTime = Time.time;
|
||||
var count = 0;
|
||||
var size = m_States.Length;
|
||||
if (size == 0) {
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
m_CurrentIndex = (m_CurrentIndex + 1) % size;
|
||||
count++;
|
||||
} while ((!IsStateValid(m_CurrentIndex) || !m_States[m_CurrentIndex].Enabled) && count <= size);
|
||||
return count <= size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba46ceeb53b9cce448526739b4e9af47
|
||||
timeCreated: 1506089511
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,66 +0,0 @@
|
||||
/// ---------------------------------------------
|
||||
/// Ultimate Character Controller
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
|
||||
namespace Opsive.UltimateCharacterController.Items.AnimatorAudioStates
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The RandomRecoil state will move from one state to another in a sequence order.
|
||||
/// </summary>
|
||||
public class SequenceRecoil : RecoilAnimatorAudioStateSelector
|
||||
{
|
||||
[Tooltip("Resets the index back to the start after the specified delay. Set to -1 to never reset.")]
|
||||
[SerializeField] protected float m_ResetDelay = -1;
|
||||
|
||||
public float ResetDelay { get { return m_ResetDelay; } set { m_ResetDelay = value; } }
|
||||
|
||||
private int m_CurrentIndex = -1;
|
||||
private float m_LastUsedTime = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Starts or stops the state selection.
|
||||
/// </summary>
|
||||
/// <param name="start">Is the object starting?</param>
|
||||
public override void StartStopStateSelection(bool start)
|
||||
{
|
||||
base.StartStopStateSelection(start);
|
||||
|
||||
// The Sequence task can reset which index is returned if the next state is selected too slowly.
|
||||
if (start && m_ResetDelay != -1 && m_LastUsedTime != -1 && m_LastUsedTime + m_ResetDelay < Time.time) {
|
||||
m_CurrentIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current state index. -1 indicates this index is not set by the class.
|
||||
/// </summary>
|
||||
/// <returns>The current state index.</returns>
|
||||
public override int GetStateIndex()
|
||||
{
|
||||
return m_CurrentIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next state.
|
||||
/// </summary>
|
||||
/// <returns>Was the state changed successfully?</returns>
|
||||
public override bool NextState()
|
||||
{
|
||||
m_LastUsedTime = Time.time;
|
||||
var count = 0;
|
||||
var size = m_States.Length;
|
||||
if (size == 0) {
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
m_CurrentIndex = (m_CurrentIndex + 1) % size;
|
||||
++count;
|
||||
} while ((!IsStateValid(m_CurrentIndex) || !m_States[m_CurrentIndex].Enabled) && count <= size);
|
||||
return count <= size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5cd5d2549b11854ab33c9c93a7f4772
|
||||
timeCreated: 1506089511
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user