| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- using Spine.Unity;
- using Spine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- using Sirenix.OdinInspector;
- public class MoveCharacter : Character
- {
- [Space(30)]
- [Header("MoveCharacter属性")]
- [Header("角色抗击打值")]
- public int hitResistance;
- [FoldoutGroup("组件")] public Foot foot;
- [HideInInspector] public AttributeStatus attributeStatus;
- private ScreenReflectPresets screenReflectPresets;
- [HideInInspector] public HitFeedbackSystem hitFeedbackSystem;
- [HideInInspector] public SpineEvent spineEvent;
- [FoldoutGroup("额外重力",order:-1)] [LabelText("上升")] public float extraRiseGravity = -28.8f; //上升时额外重力加速度
- [FoldoutGroup("额外重力")] [LabelText("下落")] public float extraFallGravity = -14.4f; //下落时额外重力加速度
- [FoldoutGroup("额外重力")] [LabelText("近地")] public float extraGroundGravity = -28.8f;
- [FoldoutGroup("平台", order: -1)] [LabelText("移速增量")]public float velocityAddition;
- [FoldoutGroup("平台")] [DisplayOnly] public float platformPosY;
- [FoldoutGroup("平台")] [DisplayOnly] public float platformRotZ;
- [FoldoutGroup("平台")] public float RotLerpSpeed = 0.6f;
- [FoldoutGroup("平台")] [DisplayOnly] public float RotLerpTime;
- [Header("材质")]
- public float matState = 1;
- public GameObject spinee;
- public MeshRenderer mesh;
- public Material[] mats;
- public Material[] outlineMats;
- public Material[] outline1Mats;
- [Header("属性")]
- public float moveSpeed = 5;
- [FoldoutGroup("飞行兵落地后回升")][LabelText("是否需要判定回升")]
- public bool needToAdjustFlyHeight;
- [FoldoutGroup("飞行兵落地后回升", order:-1)][DisplayOnly] public float flyHeight;
- [FoldoutGroup("飞行兵落地后回升")][LabelText("最大高度")] public float maxFlyHeight;
- [FoldoutGroup("飞行兵落地后回升")][LabelText("最低高度")] public float minFlyHeight;
- float refspeed = 1;
- [FoldoutGroup("飞行兵落地后回升")][LabelText("速度")][Range(0, 1)] public float flyUpTime;
- [HideInInspector]
- public int isAdjustHeight;
- [Header("减伤")]
- public bool isDamageReduction;
- public float reductionDegree;
- public GameObject reductionEffect;
- //技能类,后面移到其他脚本
- [Header("临时血量")]
- public GameObject effect;
- private int temptHP;
- private int curHP;
- private float continueTime;
- private bool isTempt;
- [Header("魂")]
- public GameObject soulPrefab;
- public float soulStartSpeed = 1f;
- [Header("隐身")]
- public bool isInvisible;
- public float invisibleTime;
- [Header("传送门")]
- public bool haveTransmit;
- [HideInInspector]
- public float transmitTime;
- public PortalsController portalsController;
- [Header("受到持续伤害")]
- public bool isSustainedInjury; //是否正在受到持续伤害
- [HideInInspector] public float sustainedInjuryTime; //存储持续伤害经过的时间
- public float sustainedInjury_IntervalTime; //每次伤害的间隔时间
- public int sustainedInjury_damage; //每次造成的伤害
- [Header("受到重伤")]
- public float heavyDamage;
- [Header("被谁击杀")]
- [DisplayOnly]
- public Character killer;
- public virtual void Awake()
- {
- spinee = bodyTrans.GetChild(0).gameObject;
- mesh = spinee.GetComponent<MeshRenderer>();
- mats = mesh.materials;
- attributeStatus = GetComponentInChildren<AttributeStatus>();
- screenReflectPresets = Camera.main.GetComponentInParent<ScreenReflectPresets>();
- hitFeedbackSystem = beHitTrigger.GetComponent<HitFeedbackSystem>();
- }
- private void Start()
- {
- }
- //0:漂浮 1:正常 2:无敌
- public void ChangeMat(int state)
- {
- if((state == 0 && matState == 2) || (state == 2 && matState == 0))
- {
- return;
- }
- if (outline1Mats.Length == 0)
- {
- return;
- }
- if (spinee == null || mesh == null || mats == null)
- {
- spinee = transform.GetChild(0).GetChild(0).gameObject;
- mesh = spinee.GetComponent<MeshRenderer>();
- mats = mesh.materials;
- }
- switch (state)
- {
- case 0:
- mesh.materials = outlineMats;
- break;
- case 1:
- mesh.materials = mats;
- break;
- case 2:
- mesh.materials = outline1Mats;
- break;
- }
- matState = state;
- }
- public void GetTemptHP(int addTemptHP, float time)
- {
- isTempt = true;
- effect.SetActive(true);
- curHP = hp;
- totalHp += addTemptHP;
- hp += addTemptHP;
- temptHP = addTemptHP;
- continueTime = time;
- }
- private void LoseTemptHP()
- {
- isTempt = false;
- effect.SetActive(false);
- totalHp -= temptHP;
- if (hp > curHP)
- {
- hp = curHP;
- }
- }
- public virtual void Update()
- {
- if (isTempt)
- {
- continueTime -= Time.deltaTime;
- if (continueTime <= 0 || hp <= curHP)
- {
- LoseTemptHP();
- }
- }
- if (beLarger)
- {
- Enlarge();
- }/*
- if (isInvisible)
- {
- invisibleTime -= Time.deltaTime;
- if(invisibleTime <= 0)
- {
- isInvisible = false;
- ChangeMat(1);
- }
- }
- if (haveTransmit)
- {
- transmitTime -= Time.deltaTime;
- if(transmitTime <=0)
- {
- haveTransmit = false;
- portalsController.rbs.Remove(rb);
- }
- }*/
- //受到持续伤害
- if (isSustainedInjury)
- {
- SustainedInjury();
- }
- }
- //伤害减免状态开启(减免程度,减免时长)
- public void DamageReductionStateOn(float degree, GameObject effect)
- {
- if (reductionEffect == null)
- {
- reductionEffect = PoolManager.Instantiate(effect, transform.position, new Quaternion(0, 0, 0, 0), transform);
- }
- reductionEffect.SetActive(true);
- isDamageReduction = true;
- reductionDegree = degree;
- canNotChangeHurt = true;
- }
- public void DamageReductionStateToOff(float onTime)
- {
- Invoke("DamageReductionStateOff", onTime);
- }
- private void DamageReductionStateOff()
- {
- isDamageReduction = false;
- reductionEffect.SetActive(false);
- canNotChangeHurt = false;
- }
- //仅造成伤害
- public override void BeHit(int damage)
- {
- if (invincibleTime > 0)
- {
- return;
- }
- base.BeHit(damage);
- }
- //比BeHit(int damage)多传一个attackFrom
- public void BeHit(int damage, Character attackFrom)
- {
- if (invincibleTime > 0)
- {
- return;
- }
- BeHit(damage);
- beHitTrigger.JudgeTurnWhite(isBeHitBySummonAttack, attackFrom);
- if (hp <= 0)
- {
- killer = attackFrom;
- hitFeedbackSystem.curCharacterState = CharacterState.Die;
- return;
- }
- }
- //造成伤害附加其他效果
- public override void BeHit(AttackInfo attackInfo, Character attackFrom)
- {
- if (invincibleTime > 0)
- {
- //attributeStatus.AddSpecialState(attackInfo, attackFrom);
- return;
- }
- screenReflectPresets.ScreenReflect(hitFeedbackSystem, attackInfo.attackValue - hitResistance);
- int damage = attackInfo.damage;
- int armorRate = attributeStatus.resistances.armor;
- if (attackInfo.attackEffect != null && attackInfo.attackEffect.Length > 0)
- {
- foreach (AttackEffect ae in attackInfo.attackEffect)
- {
- switch (ae)
- {
- /*非控制*/
- //穿甲
- case AttackEffect.ArmorPiercing:
- armorRate = attributeStatus.AddArmorPiercing(attackInfo.armorPiercing, damage);
- break;
- //易伤
- case AttackEffect.Vulnerable:
- attributeStatus.AddVulnerable(attackInfo.vulnerable);
- break;
- }
- }
- }
- //计算护甲减免
- damage = (int)(damage * (100f / (100 + armorRate)) + 0.5f);
- //计算易伤
- damage = attributeStatus.DamageCalculation(damage);
- //伤害减免,先注释,用到的时候再改
- //if (isDamageReduction)
- //{
- // damage = (int)((1 - reductionDegree) * damage);
- //}
- hp -= damage;
- //敌方士兵受起手式伤害/我方士兵受伤 闪白
- beHitTrigger.JudgeTurnWhite(attackInfo.isDemSummon, this);
- //伤害跳字
- if (showInjuryNum)
- {
- GameObject injuryNum;
- //是起手式
- if (isBeHitBySummonAttack)
- {
- injuryNum = PoolManager.Instantiate(injuryNumTextSummon);
- injuryNum.transform.position = new Vector3(
- transform.position.x + injuryNumPos_summon.x + Random.Range(-injuryNumRandom_summon.x / 2f, injuryNumRandom_summon.x / 2f),
- transform.position.y + injuryNumPos_summon.y + Random.Range(-injuryNumRandom_summon.y / 2f, injuryNumRandom_summon.y / 2f),
- transform.position.z);
- }
- //不是起手式
- else
- {
- injuryNum = PoolManager.Instantiate(injuryNumText);
- injuryNum.transform.position = injuryNum.transform.position = new Vector3(
- transform.position.x + injuryNumPos_march.x + Random.Range(-injuryNumRandom_march.x / 2f, injuryNumRandom_march.x / 2f),
- transform.position.y + injuryNumPos_march.y + Random.Range(-injuryNumRandom_march.y / 2f, injuryNumRandom_march.y / 2f),
- transform.position.z);
- }
- TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
- text.text = damage.ToString();
- }
- uiHp.Show(hp, totalHp);
- if (hp <= 0)
- {
- killer = attackFrom;
- hitFeedbackSystem.curCharacterState = CharacterState.Die;
- ChangeState(CharacterState.Die);
- return;
- }
-
- //顿帧
- hitFeedbackSystem.FreezeFrame(attackInfo, attackFrom);
- }
- //受到持续伤害
- public void SustainedInjury()
- {
- sustainedInjuryTime += Time.deltaTime;
- if(sustainedInjuryTime >= sustainedInjury_IntervalTime)
- {
- sustainedInjuryTime = 0;
- BeHit(sustainedInjury_damage);
- }
- }
- public override bool AdjustHeight()
- {
- if (canFly)
- {
- if (transform.position.y - flyHeight > 0.1f)
- {
- Vector3 pos = transform.position;
- pos.y = Mathf.SmoothDamp(pos.y, flyHeight+0.3f, ref refspeed, flyUpTime);
- transform.position = pos;
- return false;
- }
- else if (transform.position.y - flyHeight < -0.1f)
- {
- Vector3 pos = transform.position;
- pos.y = Mathf.SmoothDamp(pos.y, flyHeight+0.3f, ref refspeed, flyUpTime);
- transform.position = pos;
- return false;
- }
- else
- {
- Vector3 pos = transform.position;
- pos.y = flyHeight;
- transform.position = pos;
- }
- }
- isAdjustHeight = 2;
- return true;
- }
- }
|