Update
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef974dc08c6164c40ace6831a186d447
|
||||
folderAsset: yes
|
||||
timeCreated: 1476379025
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,298 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Invector.vMelee
|
||||
{
|
||||
using Invector.vCamera;
|
||||
using Invector.vItemManager;
|
||||
using vCharacterController;
|
||||
public class vCreateMeleeCharacterEditor : EditorWindow
|
||||
{
|
||||
GUISkin skin;
|
||||
public GameObject template;
|
||||
|
||||
public bool useGameController = true;
|
||||
public bool useInventory = true;
|
||||
|
||||
public GameObject inventory;
|
||||
public vItemListData itemListData;
|
||||
|
||||
public GameObject charObj;
|
||||
Animator charAnimator;
|
||||
|
||||
Vector2 rect = new Vector2(500, 660);
|
||||
UnityEditor.Editor humanoidpreview;
|
||||
Texture2D m_Logo;
|
||||
|
||||
/// <summary>
|
||||
/// 3rdPersonController Menu
|
||||
/// </summary>
|
||||
[MenuItem("Invector/Melee Combat/Create Melee Controller", false, 1)]
|
||||
public static void CreateNewCharacter()
|
||||
{
|
||||
GetWindow<vCreateMeleeCharacterEditor>();
|
||||
}
|
||||
|
||||
bool isHuman, isValidAvatar, charExist;
|
||||
public virtual void OnEnable()
|
||||
{
|
||||
m_Logo = Resources.Load("icon_v2") as Texture2D;
|
||||
if (Selection.activeObject)
|
||||
{
|
||||
charObj = Selection.activeGameObject;
|
||||
}
|
||||
if (charObj)
|
||||
{
|
||||
charAnimator = charObj.GetComponent<Animator>();
|
||||
humanoidpreview = Editor.CreateEditor(charObj);
|
||||
}
|
||||
|
||||
charExist = charAnimator != null;
|
||||
isHuman = charExist ? charAnimator.isHuman : false;
|
||||
isValidAvatar = charExist ? charAnimator.avatar.isValid : false;
|
||||
}
|
||||
|
||||
public virtual void OnGUI()
|
||||
{
|
||||
if (!skin)
|
||||
{
|
||||
skin = Resources.Load("vSkin") as GUISkin;
|
||||
}
|
||||
|
||||
GUI.skin = skin;
|
||||
|
||||
this.minSize = rect;
|
||||
this.titleContent = new GUIContent("Character", null, "Third Person Character Creator");
|
||||
GUILayout.BeginVertical("Character Creator Window", "window");
|
||||
GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
|
||||
GUILayout.Space(5);
|
||||
|
||||
GUILayout.BeginVertical("box");
|
||||
|
||||
if (!charObj)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Make sure your FBX model is set as Humanoid!", MessageType.Info);
|
||||
}
|
||||
else if (!charExist)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Missing a Animator Component", MessageType.Error);
|
||||
}
|
||||
else if (!isHuman)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This is not a Humanoid", MessageType.Error);
|
||||
}
|
||||
else if (!isValidAvatar)
|
||||
{
|
||||
EditorGUILayout.HelpBox(charObj.name + " is a invalid Humanoid", MessageType.Info);
|
||||
}
|
||||
|
||||
template = EditorGUILayout.ObjectField("Template", template, typeof(GameObject), true, GUILayout.ExpandWidth(true)) as GameObject;
|
||||
charObj = EditorGUILayout.ObjectField("FBX Model", charObj, typeof(GameObject), true, GUILayout.ExpandWidth(true)) as GameObject;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("--- Optional---");
|
||||
|
||||
useGameController = EditorGUILayout.Toggle("Add GameController", useGameController);
|
||||
useInventory = EditorGUILayout.Toggle("Add Inventory", useInventory);
|
||||
|
||||
if (useInventory)
|
||||
{
|
||||
inventory = EditorGUILayout.ObjectField("Inventory Prefab", inventory, typeof(GameObject), true, GUILayout.ExpandWidth(true)) as GameObject;
|
||||
itemListData = EditorGUILayout.ObjectField("ItemListData", itemListData, typeof(vItemListData), true, GUILayout.ExpandWidth(true)) as vItemListData;
|
||||
}
|
||||
if (GUI.changed && charObj != null && charObj.GetComponent<vThirdPersonController>() == null)
|
||||
{
|
||||
humanoidpreview = Editor.CreateEditor(charObj);
|
||||
}
|
||||
|
||||
if (charObj != null && charObj.GetComponent<vThirdPersonController>() != null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This gameObject already contains the component vThirdPersonController", MessageType.Warning);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
//GUILayout.BeginHorizontal("box");
|
||||
//EditorGUILayout.LabelField("Need to know how it works?");
|
||||
//if (GUILayout.Button("Video Tutorial"))
|
||||
//{
|
||||
// Application.OpenURL("https://www.youtube.com/watch?v=KQ5xha36tfE&index=1&list=PLvgXGzhT_qehtuCYl2oyL-LrWoT7fhg9d");
|
||||
//}
|
||||
//GUILayout.EndHorizontal();
|
||||
|
||||
if (charObj)
|
||||
{
|
||||
charAnimator = charObj.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
charExist = charAnimator != null;
|
||||
isHuman = charExist ? charAnimator.isHuman : false;
|
||||
isValidAvatar = charExist ? charAnimator.avatar.isValid : false;
|
||||
|
||||
if (CanCreate())
|
||||
{
|
||||
DrawHumanoidPreview();
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (GUILayout.Button("Create"))
|
||||
{
|
||||
Create();
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
public virtual bool CanCreate()
|
||||
{
|
||||
return isValidAvatar && isHuman && charObj != null && charObj.GetComponent<vThirdPersonController>() == null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the Preview window
|
||||
/// </summary>
|
||||
public virtual void DrawHumanoidPreview()
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (humanoidpreview != null)
|
||||
{
|
||||
humanoidpreview.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(100, 400), "window");
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject InstantiateNewCharacter(GameObject selected)
|
||||
{
|
||||
if (selected == null)
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
|
||||
if (selected.scene.IsValid())
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
|
||||
return PrefabUtility.InstantiatePrefab(selected) as GameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Created the Third Person Controller
|
||||
/// </summary>
|
||||
public virtual void Create()
|
||||
{
|
||||
// base for the character
|
||||
GameObject newCharacter = InstantiateNewCharacter(charObj);
|
||||
|
||||
if (!newCharacter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject _template = Instantiate(template, newCharacter.transform.position, newCharacter.transform.rotation);
|
||||
|
||||
// finds the '3D Model' gameobject or crate one if it doesn't exist
|
||||
Transform modelParent = _template.transform.Find("3D Model");
|
||||
|
||||
if (modelParent == null)
|
||||
{
|
||||
modelParent = new GameObject("3D Model").transform;
|
||||
modelParent.parent = _template.transform;
|
||||
}
|
||||
|
||||
// finds the 'Invector Components' gameobject or crate one if it doesn't exist
|
||||
Transform componentsParent = _template.transform.Find("Invector Components");
|
||||
|
||||
if (componentsParent == null)
|
||||
{
|
||||
componentsParent = new GameObject("Invector Components").transform;
|
||||
componentsParent.parent = _template.transform;
|
||||
}
|
||||
|
||||
newCharacter.transform.parent = modelParent;
|
||||
newCharacter.transform.localPosition = Vector3.zero;
|
||||
newCharacter.transform.localEulerAngles = Vector3.zero;
|
||||
_template.name = "vMeleeController_" + charObj.gameObject.name;
|
||||
|
||||
Animator animatorController = newCharacter.GetComponent<Animator>();
|
||||
Animator animatorTemplate = _template.GetComponent<Animator>();
|
||||
|
||||
animatorTemplate.avatar = animatorController.avatar;
|
||||
animatorTemplate.Rebind();
|
||||
DestroyImmediate(animatorController);
|
||||
|
||||
newCharacter.tag = "Player";
|
||||
|
||||
var p_layer = LayerMask.NameToLayer("Player");
|
||||
newCharacter.layer = p_layer;
|
||||
|
||||
foreach (Transform t in newCharacter.transform.GetComponentsInChildren<Transform>())
|
||||
{
|
||||
t.gameObject.layer = p_layer;
|
||||
}
|
||||
|
||||
Selection.activeGameObject = _template;
|
||||
|
||||
// search for a MainCamera and attach to the tpCamera
|
||||
var mainCamera = Camera.main;
|
||||
var tpCamera = _template.GetComponentInChildren<vThirdPersonCamera>();
|
||||
|
||||
if (mainCamera == null)
|
||||
{
|
||||
mainCamera = new GameObject("MainCamera", typeof(Camera), typeof(AudioListener)).GetComponent<Camera>();
|
||||
mainCamera.tag = "MainCamera";
|
||||
}
|
||||
|
||||
if (mainCamera.transform.parent != tpCamera.transform)
|
||||
{
|
||||
mainCamera.transform.parent = tpCamera.transform;
|
||||
mainCamera.transform.localPosition = Vector3.zero;
|
||||
mainCamera.transform.localEulerAngles = Vector3.zero;
|
||||
}
|
||||
|
||||
// add the gameController example
|
||||
if (useGameController)
|
||||
{
|
||||
GameObject gC = null;
|
||||
var gameController = FindObjectOfType<vGameController>();
|
||||
if (gameController == null)
|
||||
{
|
||||
gC = new GameObject("vGameController_Example");
|
||||
gC.AddComponent<vGameController>();
|
||||
}
|
||||
}
|
||||
|
||||
if (useInventory)
|
||||
{
|
||||
// add prefab inventory to the 'Invector Components' gameObject inside the Controller
|
||||
inventory = Instantiate(inventory, componentsParent.transform.position, componentsParent.transform.rotation);
|
||||
inventory.gameObject.transform.parent = componentsParent.transform;
|
||||
inventory.transform.localPosition = Vector3.zero;
|
||||
inventory.transform.localEulerAngles = Vector3.zero;
|
||||
|
||||
// add shooter melee item list data
|
||||
var _itemManager = _template.GetComponent<vItemManager>();
|
||||
_itemManager.itemListData = itemListData;
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove ItemManager from the character
|
||||
var _inventory = _template.GetComponent<vItemManager>();
|
||||
DestroyImmediate(_inventory as vItemManager, true);
|
||||
}
|
||||
|
||||
// load bones for the BodySnapControl
|
||||
var _bodySnap = _template.GetComponentInChildren<vBodySnappingControl>();
|
||||
_bodySnap.LoadBones();
|
||||
|
||||
UnityEditor.SceneView.lastActiveSceneView.FrameSelected();
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02a4e7a48de713e4c9a33da11544a1c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- m_PersistentViewDataDictionary: {instanceID: 0}
|
||||
- template: {fileID: 123100320241753025, guid: d9a4707ba2be96f49b3704765aafa732,
|
||||
type: 3}
|
||||
- inventory: {fileID: 3444320678111530354, guid: 3ae53b796aaabf94ba9bd40ed132f17d,
|
||||
type: 3}
|
||||
- itemListData: {fileID: 11400000, guid: 96e918a0f3173b14dbbbe08b7523b670, type: 2}
|
||||
- charObj: {fileID: 199726, guid: 5563b2c1cf35cae4f8490dfea2d2aa41, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Invector
|
||||
{
|
||||
// MELEE COMBAT FEATURES
|
||||
public partial class vMenuComponent
|
||||
{
|
||||
public const string path = "Invector/Melee Combat/Components/";
|
||||
|
||||
[MenuItem(path + "Melee Manager")]
|
||||
static void MeleeManagerMenu()
|
||||
{
|
||||
if (Selection.activeGameObject)
|
||||
Selection.activeGameObject.AddComponent<vMelee.vMeleeManager>();
|
||||
else
|
||||
Debug.Log("Please select a vCharacter to add the component.");
|
||||
}
|
||||
|
||||
[MenuItem(path + "WeaponHolderManager (Player Only)")]
|
||||
static void WeaponHolderMenu()
|
||||
{
|
||||
if (Selection.activeGameObject && Selection.activeGameObject.GetComponent<Invector.vCharacterController.vThirdPersonInput>() != null)
|
||||
Selection.activeGameObject.AddComponent<Invector.vItemManager.vWeaponHolderManager>();
|
||||
else
|
||||
Debug.Log("Please select the Player to add the component.");
|
||||
}
|
||||
|
||||
[MenuItem(path + "LockOn (Player Only)")]
|
||||
static void LockOnMenu()
|
||||
{
|
||||
if (Selection.activeGameObject && Selection.activeGameObject.GetComponent<Invector.vCharacterController.vThirdPersonInput>() != null)
|
||||
Selection.activeGameObject.AddComponent<vCharacterController.vLockOn>();
|
||||
else
|
||||
Debug.Log("Please select a Player to add the component.");
|
||||
}
|
||||
|
||||
[MenuItem(path + "DrawHide MeleeWeapons")]
|
||||
static void DrawMeleeWeaponMenu()
|
||||
{
|
||||
if (Selection.activeGameObject && Selection.activeGameObject.GetComponent<Invector.vCharacterController.vMeleeCombatInput>() != null)
|
||||
Selection.activeGameObject.AddComponent<vDrawHideMeleeWeapons>();
|
||||
else
|
||||
Debug.Log("Please select a Player to add the component.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff99e6ba5dc57ab43b12c4177a80f216
|
||||
timeCreated: 1495232492
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vCharacterController
|
||||
{
|
||||
public class vBlockUnarmedAttack : MonoBehaviour
|
||||
{
|
||||
private vMeleeCombatInput meleeCombatInput;
|
||||
[SerializeField] protected bool useUnarmedAttack;
|
||||
public bool IsActiveUnarmedAttack
|
||||
{
|
||||
get
|
||||
{
|
||||
return useUnarmedAttack;
|
||||
}
|
||||
protected set
|
||||
{
|
||||
useUnarmedAttack = value;
|
||||
}
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
///Get the melee combat input component
|
||||
meleeCombatInput = GetComponent<vMeleeCombatInput>();
|
||||
///Use update event of the input to handle attack input
|
||||
meleeCombatInput.onUpdate += HandleAttackInput;
|
||||
}
|
||||
|
||||
private void HandleAttackInput()
|
||||
{
|
||||
///Disable input usage if Unarmed
|
||||
if (!IsActiveUnarmedAttack)
|
||||
{
|
||||
meleeCombatInput.weakAttackInput.useInput = meleeCombatInput.isArmed;
|
||||
meleeCombatInput.strongAttackInput.useInput = meleeCombatInput.isArmed;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActiveUnarmedAttack(bool value)
|
||||
{
|
||||
if (value != IsActiveUnarmedAttack)
|
||||
{
|
||||
IsActiveUnarmedAttack = value;
|
||||
meleeCombatInput.weakAttackInput.useInput = value;
|
||||
meleeCombatInput.strongAttackInput.useInput = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3186834037368c4bb284972a79d82c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,361 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vCharacterController
|
||||
{
|
||||
using vEventSystems;
|
||||
using vMelee;
|
||||
|
||||
// here you can modify the Melee Combat inputs
|
||||
// if you want to modify the Basic Locomotion inputs, go to the vThirdPersonInput
|
||||
[vClassHeader("MELEE INPUT MANAGER", iconName = "inputIcon")]
|
||||
public class vMeleeCombatInput : vThirdPersonInput, vIMeleeFighter
|
||||
{
|
||||
#region Variables
|
||||
|
||||
[vEditorToolbar("Inputs")]
|
||||
[Header("Melee Inputs")]
|
||||
public GenericInput weakAttackInput = new GenericInput("Mouse0", "RB", "RB");
|
||||
public GenericInput strongAttackInput = new GenericInput("Alpha1", false, "RT", true, "RT", false);
|
||||
public GenericInput blockInput = new GenericInput("Mouse1", "LB", "LB");
|
||||
|
||||
internal vMeleeManager meleeManager;
|
||||
protected virtual bool _isAttacking { get; set; }
|
||||
public virtual bool isAttacking { get => _isAttacking || cc.IsAnimatorTag("Attack"); protected set { _isAttacking = value; } }
|
||||
public virtual bool isBlocking { get; protected set; }
|
||||
public virtual bool isArmed { get { return meleeManager != null && (meleeManager.rightWeapon != null || (meleeManager.leftWeapon != null && meleeManager.leftWeapon.meleeType != vMeleeType.OnlyDefense)); } }
|
||||
public virtual bool isEquipping { get; protected set; }
|
||||
|
||||
[HideInInspector]
|
||||
public bool lockMeleeInput;
|
||||
|
||||
public void SetLockMeleeInput(bool value)
|
||||
{
|
||||
lockMeleeInput = value;
|
||||
|
||||
if (value)
|
||||
{
|
||||
isAttacking = false;
|
||||
isBlocking = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetLockAllInput(bool value)
|
||||
{
|
||||
base.SetLockAllInput(value);
|
||||
SetLockMeleeInput(value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public virtual bool lockInventory
|
||||
{
|
||||
get
|
||||
{
|
||||
return isAttacking || cc.isDead || cc.customAction || cc.isRolling;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
}
|
||||
|
||||
protected override void LateUpdate()
|
||||
{
|
||||
UpdateMeleeAnimations();
|
||||
base.LateUpdate();
|
||||
}
|
||||
|
||||
protected override void FixedUpdate()
|
||||
{
|
||||
base.FixedUpdate();
|
||||
}
|
||||
|
||||
public override void InputHandle()
|
||||
{
|
||||
if (cc == null || cc.isDead)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.InputHandle();
|
||||
|
||||
if (MeleeAttackConditions() && !lockMeleeInput)
|
||||
{
|
||||
MeleeWeakAttackInput();
|
||||
MeleeStrongAttackInput();
|
||||
BlockingInput();
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetAttackTriggers();
|
||||
isBlocking = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region MeleeCombat Input Methods
|
||||
|
||||
/// <summary>
|
||||
/// WEAK ATK INPUT
|
||||
/// </summary>
|
||||
public virtual void MeleeWeakAttackInput()
|
||||
{
|
||||
if (animator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (weakAttackInput.GetButtonDown() && MeleeAttackStaminaConditions())
|
||||
{
|
||||
TriggerWeakAttack();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TriggerWeakAttack()
|
||||
{
|
||||
animator.SetInteger(vAnimatorParameters.AttackID, AttackID);
|
||||
animator.SetTrigger(vAnimatorParameters.WeakAttack);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// STRONG ATK INPUT
|
||||
/// </summary>
|
||||
public virtual void MeleeStrongAttackInput()
|
||||
{
|
||||
if (animator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (strongAttackInput.GetButtonDown() && (!meleeManager.CurrentActiveAttackWeapon || meleeManager.CurrentActiveAttackWeapon.useStrongAttack) && MeleeAttackStaminaConditions())
|
||||
{
|
||||
TriggerStrongAttack();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TriggerStrongAttack()
|
||||
{
|
||||
animator.SetInteger(vAnimatorParameters.AttackID, AttackID);
|
||||
animator.SetTrigger(vAnimatorParameters.StrongAttack);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BLOCK INPUT
|
||||
/// </summary>
|
||||
public virtual void BlockingInput()
|
||||
{
|
||||
if (animator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isBlocking = blockInput.GetButton() && cc.currentStamina > 0 && !cc.customAction && !isAttacking;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the Sprint method to cancel Sprinting when Attacking
|
||||
/// </summary>
|
||||
public override void SprintInput()
|
||||
{
|
||||
if (sprintInput.useInput)
|
||||
{
|
||||
bool canSprint = cc.useContinuousSprint ? sprintInput.GetButtonDown() : sprintInput.GetButton();
|
||||
cc.Sprint(canSprint && !isAttacking);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Conditions
|
||||
|
||||
protected virtual bool MeleeAttackStaminaConditions()
|
||||
{
|
||||
var result = cc.currentStamina - meleeManager.GetAttackStaminaCost();
|
||||
return result >= 0;
|
||||
}
|
||||
|
||||
protected virtual bool MeleeAttackConditions()
|
||||
{
|
||||
if (meleeManager == null)
|
||||
{
|
||||
meleeManager = GetComponent<vMeleeManager>();
|
||||
}
|
||||
|
||||
return meleeManager != null && cc.isGrounded && !cc.customAction && !cc.isJumping && !cc.isCrouching && !cc.isRolling && !isEquipping && !animator.IsInTransition(cc.baseLayer);
|
||||
}
|
||||
|
||||
public override bool JumpConditions()
|
||||
{
|
||||
|
||||
return !isAttacking && base.JumpConditions();
|
||||
}
|
||||
|
||||
public override bool RollConditions()
|
||||
{
|
||||
return base.RollConditions() && !isAttacking && !animator.IsInTransition(cc.upperBodyLayer) && !animator.IsInTransition(cc.fullbodyLayer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Update Animations
|
||||
|
||||
protected virtual void UpdateMeleeAnimations()
|
||||
{
|
||||
if (animator == null || meleeManager == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
animator.SetInteger(vAnimatorParameters.AttackID, AttackID);
|
||||
animator.SetInteger(vAnimatorParameters.DefenseID, DefenseID);
|
||||
animator.SetBool(vAnimatorParameters.IsBlocking, isBlocking);
|
||||
animator.SetFloat(vAnimatorParameters.MoveSet_ID, meleeMoveSetID, .2f, vTime.fixedDeltaTime);
|
||||
isEquipping = cc.IsAnimatorTag("IsEquipping");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default moveset id used when is without weapon
|
||||
/// </summary>
|
||||
public virtual int defaultMoveSetID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to ignore the Weapon moveset id and use the <seealso cref="defaultMoveSetID"/>
|
||||
/// </summary>
|
||||
public virtual bool overrideWeaponMoveSetID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current moveset id based if is using weapon or not
|
||||
/// </summary>
|
||||
public virtual int meleeMoveSetID
|
||||
{
|
||||
get
|
||||
{
|
||||
int id = meleeManager.GetMoveSetID();
|
||||
if (id == 0 || overrideWeaponMoveSetID)
|
||||
{
|
||||
id = defaultMoveSetID;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ResetMeleeAnimations()
|
||||
{
|
||||
if (meleeManager == null || !animator)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
animator.SetBool(vAnimatorParameters.IsBlocking, false);
|
||||
}
|
||||
|
||||
public virtual int AttackID
|
||||
{
|
||||
get
|
||||
{
|
||||
return meleeManager ? meleeManager.GetAttackID() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int DefenseID
|
||||
{
|
||||
get
|
||||
{
|
||||
return meleeManager ? meleeManager.GetDefenseID() : 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Melee Methods
|
||||
|
||||
public virtual void OnEnableAttack()
|
||||
{
|
||||
if (meleeManager == null)
|
||||
{
|
||||
meleeManager = GetComponent<vMeleeManager>();
|
||||
}
|
||||
|
||||
if (meleeManager == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cc.currentStaminaRecoveryDelay = meleeManager.GetAttackStaminaRecoveryDelay();
|
||||
cc.currentStamina -= meleeManager.GetAttackStaminaCost();
|
||||
isAttacking = true;
|
||||
cc.isSprinting = false;
|
||||
}
|
||||
|
||||
public virtual void OnDisableAttack()
|
||||
{
|
||||
isAttacking = false;
|
||||
}
|
||||
|
||||
public virtual void ResetAttackTriggers()
|
||||
{
|
||||
animator.ResetTrigger(vAnimatorParameters.WeakAttack);
|
||||
animator.ResetTrigger(vAnimatorParameters.StrongAttack);
|
||||
}
|
||||
|
||||
public virtual void BreakAttack(int breakAtkID)
|
||||
{
|
||||
ResetAttackTriggers();
|
||||
OnRecoil(breakAtkID);
|
||||
}
|
||||
|
||||
public virtual void OnRecoil(int recoilID)
|
||||
{
|
||||
animator.SetInteger(vAnimatorParameters.RecoilID, recoilID);
|
||||
animator.SetTrigger(vAnimatorParameters.TriggerRecoil);
|
||||
animator.SetTrigger(vAnimatorParameters.ResetState);
|
||||
animator.ResetTrigger(vAnimatorParameters.WeakAttack);
|
||||
animator.ResetTrigger(vAnimatorParameters.StrongAttack);
|
||||
}
|
||||
|
||||
public virtual void OnReceiveAttack(vDamage damage, vIMeleeFighter attacker)
|
||||
{
|
||||
// character is blocking
|
||||
if (!damage.ignoreDefense && isBlocking && meleeManager != null && meleeManager.CanBlockAttack(damage.sender.position))
|
||||
{
|
||||
var damageReduction = meleeManager.GetDefenseRate();
|
||||
if (damageReduction > 0)
|
||||
{
|
||||
damage.ReduceDamage(damageReduction);
|
||||
}
|
||||
|
||||
if (attacker != null && meleeManager != null && meleeManager.CanBreakAttack())
|
||||
{
|
||||
attacker.BreakAttack(meleeManager.GetDefenseRecoilID());
|
||||
}
|
||||
|
||||
meleeManager.OnDefense();
|
||||
cc.currentStaminaRecoveryDelay = damage.staminaRecoveryDelay;
|
||||
cc.currentStamina -= damage.staminaBlockCost;
|
||||
}
|
||||
// apply damage
|
||||
damage.hitReaction = !isBlocking || damage.ignoreDefense;
|
||||
cc.TakeDamage(damage);
|
||||
}
|
||||
|
||||
public virtual vICharacter character
|
||||
{
|
||||
get { return cc; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public static partial class vAnimatorParameters
|
||||
{
|
||||
public static int AttackID = Animator.StringToHash("AttackID");
|
||||
public static int DefenseID = Animator.StringToHash("DefenseID");
|
||||
public static int IsBlocking = Animator.StringToHash("IsBlocking");
|
||||
public static int MoveSet_ID = Animator.StringToHash("MoveSet_ID");
|
||||
public static int RecoilID = Animator.StringToHash("RecoilID");
|
||||
public static int TriggerRecoil = Animator.StringToHash("TriggerRecoil");
|
||||
public static int WeakAttack = Animator.StringToHash("WeakAttack");
|
||||
public static int StrongAttack = Animator.StringToHash("StrongAttack");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6422a02e39355444d9497a080cf1a955
|
||||
timeCreated: 1470415245
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user