| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- public class HitFeedbackSystem : MonoBehaviour
- {
- //组件
- private Character character;
- private AttributeStatus attributeStatus;
- [TabGroup("顿帧")] public int freezeFrame;
- [TabGroup("顿帧")] public bool attackFromHasFreezeFrame;
- [TabGroup("顿帧")] [DisplayOnly] public bool isFreeze;
- [HideInInspector] public bool canFreeze;
- [HideInInspector] public bool canBeFreeze = true;
- private RigidbodyConstraints origRC;
- private Vector3 velocity; //顿帧前速度
- public CharacterState curCharacterState; //顿帧前状态
- [HideInInspector] public AttackController.AttackMethod attackMethod;
- [HideInInspector] public Character attackFromData;
- [TabGroup("僵直")] [DisplayOnly] public float hitStunTime;
- [HideInInspector] public bool canHitStun;
- private void Awake()
- {
- character = GetComponentInParent<MoveCharacter>();
- attributeStatus = GetComponent<AttributeStatus>();
- }
- void Start()
- {
-
- }
- private void OnDisable()
- {
- isFreeze = false;
- }
- void FixedUpdate()
- {
- //顿帧
- if (canBeFreeze && isFreeze)
- {
- if (character.rb == null)
- {
- return;
- }
- if (freezeFrame <= 0)
- {
- isFreeze = false;
- character.ani.speed = 1;
- character.rb.constraints = origRC;
- character.rb.velocity = velocity;
- character.ChangeState(curCharacterState);
- if (attackFromData != null)
- {
- attributeStatus.AddSpecialState(attackMethod, attackFromData);
- attackFromData = null;
- }
- }
- freezeFrame -= 1;
- }
- }
- public void HitStunUpdate()
- {
- if (hitStunTime <= 0)
- {
- character.ChangeState(CharacterState.Idle);
- }
- else
- {
- character.rb.velocity = Vector3.zero;
- hitStunTime -= Time.deltaTime;
- }
- }
- //顿帧
- public void FreezeFrame(AttackController.AttackMethod attackMethod, Character attackFrom)
- {
- if (canFreeze)
- {
- if (character.rb == null)
- {
- return;
- }
- this.attackMethod = attackMethod;
- attackFromData = attackFrom;
- canFreeze = false;
- if (!isFreeze)
- {
- HitFeedbackSystem hitFeedbackSystem = (attackFrom as MoveCharacter).hitFeedbackSystem;
- origRC = character.rb.constraints;
- velocity = character.rb.velocity;
- curCharacterState = character.state;
- character.ani.speed = 0;
- character.rb.constraints = RigidbodyConstraints.FreezeAll;
- character.ChangeState(CharacterState.FramePause);
- isFreeze = true;
- if (attackFromHasFreezeFrame && !hitFeedbackSystem.isFreeze)
- {
- hitFeedbackSystem.freezeFrame = freezeFrame;
- hitFeedbackSystem.origRC = attackFrom.rb.constraints;
- hitFeedbackSystem.velocity = attackFrom.rb.velocity;
- hitFeedbackSystem.curCharacterState = attackFrom.state;
- attackFrom.ani.speed = 0;
- attackFrom.rb.constraints = RigidbodyConstraints.FreezeAll;
- attackFrom.ChangeState(CharacterState.FramePause);
- hitFeedbackSystem.isFreeze = true;
- }
- }
- }
- else
- {
- attributeStatus.AddSpecialState(attackMethod,attackFrom);
- }
- }
- //僵直
- public void EnterHitStun(Character attackFrom)
- {
- if (canHitStun)
- {
- canHitStun = false;
- float dir1 = attackFrom.transform.position.x <= character.transform.position.x? 1:-1;
- float dir2 = character.bodyTrans.localScale.x >= 0? 1:-1;
- if(dir1 == dir2)
- {
- character.ani.Play("hitted", 0, 0);
- }
- else
- {
- character.ani.Play("hitted_back", 0, 0);
- }
- character.ChangeState(CharacterState.HitStun);
- character.ChangeStateText(CharacterState.HitStun);
- }
- }
- }
|