| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- using Spine.Unity;
- using Spine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MoveCharacter : Character
- {
- public bool canMove = true;
- public Foot foot;
- public float extraRiseGravity = 0; //上升时额外重力加速度
- public float extraFallGravity = -10; //下落时额外重力加速度
- public float moveSpeed = 5;
- //[HideInInspector]
- public float beRepelValue;
- public float totalBeRepelValue;
- [HideInInspector]
- public float weakTime;
- public float totalWeakTime;
- public float weakUpSpeed = 10f;
- public float decelerationRatio = 1f;
- public float minHurtKeepTime = 0.2f;
- [HideInInspector]
- public float hurtKeepTime = 0;
- public float hurtChangeVelocity = 1;
- [Header("新增眩晕参数")]
- public float comaTime = 5;
- public float pastComaTime;
- public bool isCaughtByCook;
- public bool isBeDropped;
- [Header("新增漂浮效果参数")]
- public float maxTime = 1.5f; //上升最大耗时
- public float minTime = 0.1f; //上升最小耗时
- public float maxHeight = 12; //最大上升高度
- public float minHeight = 7; //最小上升高度
- public float maxRotateSpeed = 20; //最大旋转速度
- public float minRotateSpeed = 5; //最小旋转速度
- public float floatTime = 20; //漂浮时间
- private float curTime; //漂浮已进行时长
- private float height; //漂浮高度
- private float riseTime; //上升时间
- private float curHeight; //当前所在高度
- private float rotateSpeed; //旋转速度
- private float rotateDir; //旋转方向
- private float backSpeed; //往后退的速度
- public bool isFloat; //正在漂浮中
- public int dropDamage; //漂浮摔落伤害
- public float normalFallSpeed;
- public float rapidFallSpeed;
- public float curFallSpeed;
- private Vector3 origPos; //初始位置
- private float origY;
- private float pastTime; //上升已用时间
- private float rise = 1;
- public int floatState; //0:不漂浮;1:漂浮中;2:飘着;3:掉下去
- public GameObject spinee;
- public MeshRenderer mesh;
- public Material[] mats;
- public Material[] outlineMats;
- public Material[] outline1Mats;
- public SkeletonMecanim playerMe;
- public Animator playerAni;
- public Animator playerCol;
- public Transform playerTran;
- public BeSearchTrigger playerBst;
- public GameObject playerBullet;
- public SearchTrigger playerST;
- public Foot playerFoot;
- public GameObject playerSpinee;
- public MeshRenderer playerMesh;
- public Material[] playerMats;
- public Material[] playerOut;
- public bool isInvisible;
- public bool canNotChangeHurt;
- public GameObject soulPrefab;
- public float soulStartSpeed = 1f;
- private void Awake()
- {
- spinee = bodyTrans.GetChild(0).gameObject;
- mesh = spinee.GetComponent<MeshRenderer>();
- mats = mesh.materials;
- origY = transform.position.y;
- curFallSpeed = normalFallSpeed;
- }
- private void Start()
- {
- playerMe = mecanim;
- playerAni = ani;
- playerCol = aniCollider;
- playerTran = bodyTrans;
- playerBst = beSearchTrigger;
- playerBullet = bulletPrefab;
- playerST = searchTrigger;
- playerFoot = foot;
- playerSpinee = spinee;
- playerMesh = mesh;
- playerMats = mats;
- playerOut = outlineMats;
-
- curFallSpeed = normalFallSpeed;
- }
- //0:漂浮 1:正常 2:灵魂不稳定
- public void ChangeMat(int state)
- {
- if(outline1Mats.Length == 0)
- {
- Transform particleSystem = bodyTrans.GetChild(1).GetChild(0);
- if (particleSystem == null ||
- ( particleSystem != null && particleSystem.name != "Particle System"))
- {
- return;
- }
- ParticleSystem.MainModule mainModule;
- switch (state)
- {
- case 0:
- break;
- case 1:
- print(particleSystem.name);
- mainModule =
- particleSystem.GetChild(1).GetComponent<ParticleSystem>().main;
- mainModule.startColor = new ParticleSystem.MinMaxGradient(Color.white);
- mainModule =
- particleSystem.GetChild(2).GetComponent<ParticleSystem>().main;
- mainModule.startColor = new ParticleSystem.MinMaxGradient(Color.white);
- break;
- case 2:
- mainModule =
- particleSystem.GetChild(1).GetComponent<ParticleSystem>().main;
- mainModule.startColor = new ParticleSystem.MinMaxGradient(Color.yellow);
- mainModule =
- particleSystem.GetChild(2).GetComponent<ParticleSystem>().main;
- mainModule.startColor = new ParticleSystem.MinMaxGradient(Color.yellow);
- break;
- default:
- break;
- }
- 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;
- }
- }
- public void FloatStateOn()
- {
- if (!isTran)
- {
- if (canMove)
- {
- canMove = false;
- if (curFallSpeed == 0)
- {
- curFallSpeed = normalFallSpeed;
- }
- isFloat = true;
- ChangeMat(0);
- curTime = 0;
- if (floatState == 0)
- {
- origPos = transform.position;
- origY = origPos.y;
- curHeight = origPos.y;
- }
- origPos.x = transform.position.x;
- ChangeState(CharacterState.Rise);
- floatState = 1;
- riseTime = Random.Range(minTime, maxTime);
- backSpeed = Random.Range(1, 4);
- if (gameObject.tag == "Enemy" || gameObject.tag == "Player")
- {
- backSpeed = -backSpeed;
- }
- rotateSpeed = Random.Range(minRotateSpeed, maxRotateSpeed);
- rotateDir = (1.5f - Random.Range(1, 3)) * 2;
- height = Random.Range(minHeight, maxHeight);
- }
- }
- else
- {
- if (pc == null)
- {
- pc = GetComponentInParent<PlayerController>();
- }
- pc.FloatStateOn();
- }
- }
- public void FloatDrop()
- {
- isBeDropped = true;
- transform.localEulerAngles = new Vector3(0, 0, 0);
- ChangeState(CharacterState.Fall);
- floatState = 3;
- curFallSpeed = rapidFallSpeed;
- }
- private void RotateSelf()
- {
- transform.localEulerAngles += new Vector3(0, 0, 1) * rotateDir * rotateSpeed * Time.deltaTime;
- }
- public void CharacterFloat()
- {
- if (floatState == 1)
- {
- RotateSelf();
- curTime += Time.deltaTime;
- aniCollider.Play("Rise", 0, 0);
- curHeight = Mathf.SmoothDamp(curHeight, height, ref rise, riseTime);
- transform.position = new Vector3(origPos.x, curHeight, origPos.z);
- if (curHeight >= height - 0.02f)
- {
- floatState = 2;
- pastTime = curTime;
- height = transform.position.y;
- ChangeState(CharacterState.Float);
- }
- }
- else if (floatState == 2)
- {
- RotateSelf();
- curTime += Time.deltaTime;
- transform.position = new Vector3(origPos.x + backSpeed * (curTime - pastTime), height, origPos.z);
- if (curTime >= floatTime)
- {
- transform.localEulerAngles = new Vector3(0, 0, 0);
- floatState = 3;
- origPos.x = transform.position.x;
- ChangeState(CharacterState.Fall);
- }
- }
- else if (floatState == 3)
- {
- aniCollider.Play("Fall", 0, 0);
- if (!isBeDropped && transform.position.y >= origY + 0.05f || isBeDropped && !foot.TrigGround)
- {
- curHeight -= curFallSpeed * Time.deltaTime;
- transform.position = new Vector3(origPos.x, curHeight, origPos.z);
- }
- else if (foot.TrigGround || !isBeDropped && curHeight <= origY + 0.05f)
- {
- if (!isBeDropped)
- {
- //transform.position = origPos;
- ChangeState(CharacterState.Idle);
- }
- else
- {
- ChangeState(CharacterState.Coma);
- BeHit(dropDamage, Vector3.zero, false, 0);
- isBeDropped = false;
- }
- ChangeMat(1);
- /*
- foreach (Material m in mats)
- {
- m.SetInt("_Outline", 0);
- }
- */
- floatState = 0;
- isFloat = false;
- canMove = true;
- curFallSpeed = normalFallSpeed;
- if (gameObject.tag == "Player")
- {
- if (pc == null)
- {
- pc = GetComponentInParent<PlayerController>();
- }
- pc.soulCollector.enabled = true;
- }
- }
- }
- }
- public void Update()
- {
- if (beLarger)
- {
- Enlarge();
- }
- if (floatState != 0)
- {
- CharacterFloat();
- }
- if (isSoulUnstable)
- {
- soulUnstableTime -= Time.deltaTime;
- ChangeMat(2);
- if(soulUnstableTime < 0)
- {
- isSoulUnstable = false;
- ChangeMat(1);
- }
- }
- }
- public float easyToGetHit = 0.2f;
- public bool canNotBeHit;
- public override void BeHit(int damage, Vector3 force, bool changeHurt, float repelValue)
- {
- if (!isTran)
- {
- if (canNotBeHit)
- {
- return;
- }
- if (isInvisible)
- {
- return;
- }
- if (invincibleTime > 0)
- {
- return;
- }
- if (isFloat)
- {
- damage = (int)((1 + easyToGetHit) * damage);
- }
- hp -= damage;
- uiHp.Show(hp, totalHp);
- if (hp <= 0)
- {
- ChangeState(CharacterState.Die);
- rb.AddForce(force);
- return;
- }
- if (isSoulUnstable)
- {
- isSoulUnstable = false;
- ChangeMat(1);
- GameObject soulObj = PoolManager.Instantiate(soulPrefab, transform.position);
- Vector3 dir = Vector3.up;
- soulObj.GetComponent<Soul>().Burst(dir * soulStartSpeed);
- }
- if (canNotChangeHurt)
- {
- return;
- }
- if (changeHurt && state == CharacterState.Weak)
- {
- ChangeState(CharacterState.Hurt);
- rb.AddForce(force);
- beRepelValue = totalBeRepelValue;
- return;
- }
- beRepelValue -= repelValue;
- if (changeHurt && beRepelValue <= 0)
- {
- ChangeState(CharacterState.Weak);
-
- }
- }
- else
- {
- if (pc == null)
- {
- pc = GetComponentInParent<PlayerController>();
- }
- pc.BeHit(damage, force, changeHurt, repelValue);
- }
- }
- }
|