| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using Spine.Unity;
- using Spine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- //角色状态
- public enum CharacterState
- {
- None = 0,
- Idle = 1,
- Run = 2,
- Rise = 3, //空中上升
- Fall = 4, //空中下落
- Attack = 6,
- KeepAttack = 7,
- Summon = 8,
- Rush = 9,
- Sprint = 10,
- Die = 11,
- Weak = 12,
- Float = 15, //空中漂浮
- Coma = 21, //昏迷
- LockSoul = 25, //在锁魂塔中
- Conduct = 26, //在指挥中
- SpecialStatus,
- }
- public class Character : MonoBehaviour
- {
- [Header("骨骼")]
- public SkeletonMecanim mecanim;
- public Skeleton skeleton;
- [HideInInspector]
- public MeshRenderer meshRenderer;
- [Header("动画控制器")]
- public Animator ani;
-
- [Header("重要动画时间")]
- public float totalDieKeepTime = 2f;
- public float totalAttack_summonTime = 0.5f;
- public float totalAttack_marchTime = 0.5f;
- [Header("死亡后多久尸体消失")]
- [HideInInspector]
- public float dieKeepTime;
-
- [Header("组件")]
- public Rigidbody rb;
- public Transform bodyTrans;
- public BeSearchTrigger beSearchTrigger;
- public SearchTrigger searchTrigger;
- public GameObject bodyCollider;
- public UIHP uiHp;
- public BeHitTrigger beHitTrigger;
- public AttackController attackController;
- [HideInInspector]
- public Character targetCharacter;
- [HideInInspector]
- public Character attackTarget;
- [Header("角色状态")]
- [DisplayOnly]
- public CharacterState state;
- public int totalHp = 100;
- public int hp;
- [DisplayOnly]
- public bool isDie = false; //已死亡
- [DisplayOnly]
- public bool isRevive; //从虚弱状态恢复中
- public bool canNotAddForce; //不会被打飞
- public bool canNotChangeHurt; //不会被打虚弱
- [HideInInspector]
- public float invincibleTime; //无敌时间
- public GameObject injuryNumText;//伤害跳字
- public bool showInjuryNum; //伤害跳字开关
- public bool canFly = false;
- [Header("护甲")]
- public int armor;
- [Header("锁魂塔")]
- public LockSoul ls;
- public bool isInSoulTower; //在锁魂塔范围内
- [Header("体型增大")]
- [HideInInspector]
- public bool beLarger = false;
- public float toLargeSize = 0; //变大程度
- private Vector3 speed = new Vector3(1, 1, 0); //变大速度
- [Header("特效")]
- public GameObject cookEffect; //吃串加血
- [Header("传送门")]
- public bool Attack_summonShootCanTransmit; //普攻1弓箭可以被传送
- //调试开关
- [Header("debug攻击者")] public bool debugAttackFrom;
- public virtual void Init()
- {
- //确保组件不丢失
- if (!mecanim)
- {
- mecanim = GetComponentInChildren<SkeletonMecanim>();
- }
- if (mecanim && skeleton == null)
- {
- skeleton = mecanim.skeleton;
- }
- if (!meshRenderer)
- {
- meshRenderer = mecanim.GetComponent<MeshRenderer>();
- }
- if (!ani)
- {
- ani = GetComponentInChildren<Animator>();
- }
- //血量重置
- hp = totalHp;
- uiHp.Show(hp, totalHp);
- ChangeState(CharacterState.Idle);
- if (attackController == null)
- {
- attackController = GetComponent<AttackController>();
- }
- attackController.Init();
- attackTarget = attackController.attackTarget;
- targetCharacter = attackController.targetCharacter;
- }
- public virtual void FixedUpdate()
- {
- OnState();
- }
- public void Turn()
- {
- bodyTrans.localScale = new Vector3(-bodyTrans.localScale.x, bodyTrans.localScale.y, bodyTrans.localScale.z);
- }
- public virtual void OnState()
- {
- }
- public virtual void ChangeState(CharacterState newState)
- {
- }
- public void DebugAttackFrom(string attackFrom, int damage)
- {
- Debug.Log(attackFrom + "对" + gameObject.name + "造成了" + damage.ToString() + "点伤害");
- }
- public virtual void BeHit(int damage, Vector3 force, bool changeHurt, float repelValue)
- {
- //无敌状态下免伤
- if (invincibleTime > 0)
- {
- return;
- }
- //非无敌状态扣血
- hp -= damage;
- //伤害跳字
- if (showInjuryNum)
- {
- GameObject injuryNum = Instantiate(injuryNumText);
- injuryNum.transform.position = new Vector3(transform.position.x + Random.Range(-1f, 1f), transform.position.y + 1, transform.position.z);
- TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
- text.text = damage.ToString();
- if (gameObject.CompareTag("Player"))
- {
- text.color = Color.red;
- }
- }
- uiHp.Show(hp, totalHp);
- if (hp <= 0)
- {
- if (!canNotAddForce)
- rb.AddForce(force);
- ChangeState(CharacterState.Die);
- return;
- }
- }
- public virtual Vector3 GetMoveDir()
- {
- Vector3 moveDir = Vector3.zero;
- return moveDir;
- }
- public virtual void SetSortingOrder(int order)
- {
- meshRenderer.sortingOrder = order;
- }
- //吃串增加血量上限
- public void HpUp(float value, float larger)
- {
- cookEffect.transform.GetChild(0).gameObject.SetActive(true);
- int add = 0;
- value = value / 100;
- add = (int)(totalHp * value);
- totalHp += add;
- hp += add;
- uiHp.Show(hp, totalHp);
- float cur = transform.localScale.x;
- toLargeSize = cur * larger;
- beLarger = true;
- }
- //体型变大
- public void Enlarge()
- {
- transform.localScale = Vector3.SmoothDamp(transform.localScale, new Vector3(1, 1, 1) * (toLargeSize + 0.1f), ref speed, 0.6f);
- if (transform.localScale.x >= toLargeSize - 0.1f)
- {
- beLarger = false;
- transform.localScale = new Vector3(toLargeSize, toLargeSize, toLargeSize);
- toLargeSize = 0;
- }
- }
- }
|