Procházet zdrojové kódy

漂浮功能移到attackController和attributeStatus里

wgl před 6 měsíci
rodič
revize
94503a1575

+ 0 - 1
ActionTowerDefense/Assets/Scripts/Boss/YuMenGuan/YuMenGuan.cs

@@ -163,7 +163,6 @@ public class YuMenGuan : Boss
         }
         if (Vector2.Distance(bodyTrans.position, targetCharacter.transform.position) <= 0.5f)
         {
-            canMove = false;
             rb.velocity = new Vector3(0, 0, 0);
         }
         Vector3 dir;

+ 6 - 2
ActionTowerDefense/Assets/Scripts/Characters/AttackController.cs

@@ -17,7 +17,7 @@ public enum AttackEffect
     //非控制
     Armor = 100,              //穿甲
     ChangeDamage = 101,       //更改攻击力
-    Vulnerabilit = 102,       //易伤
+    Vulnerable = 102,       //易伤
     SustainedInjury = 103,    //持续伤害
     Burn = 104,               //灼烧
     //中毒
@@ -35,7 +35,11 @@ public class AttackInfo
     [Serializable]
     public struct FloatState
     {
-        public float time;  //漂浮时间
+        public float time;          //漂浮时间
+        public Vector2 upTime;      //上升最大耗时
+        public Vector2 backSpeed;   //往后退的速度
+        public Vector2 rotateSpeed; //旋转速度
+        public Vector2 height;      //上升高度
     }
     private bool ShowFloatStateValue()
     {

+ 105 - 16
ActionTowerDefense/Assets/Scripts/Characters/AttributeStatus.cs

@@ -15,7 +15,7 @@ public class AttributeStatus : MonoBehaviour
     public enum SpecialState
     {
         Null = -1,
-        Float = 0,
+        FloatState = 0,
         ShotDown = 1,
         BlownUp = 2,
         Stun = 3,
@@ -24,16 +24,14 @@ public class AttributeStatus : MonoBehaviour
     public List<SpecialState> curSpecialStates = new List<SpecialState> {SpecialState.Null};    //[0]存放控制类状态,没有则为SpecialState.Null,[1:]存放其他状态
 
     [Header("各状态时间")]
-    [DisplayOnly] public float strikeStunTime;
-
-    [Header("被击飞阻力")]
-    public float decelerationRatioX = 2f;
-    public float decelerationRatioY = 15f;
+    [DisplayOnly] public float attributeTime;
 
     //抗性
     [Serializable]
     public struct Resistances
     {
+        [Range(0, 1)]
+        public float Float;
         [Range(0,1)]
         public float BlowUp;
         [Range(0,1)]
@@ -41,10 +39,25 @@ public class AttributeStatus : MonoBehaviour
         [Range(0,1)]
         public float Stun;
     }
-
     [Header("抗性")]
     public Resistances resistances;
 
+    [Header("被击飞阻力")]
+    public float decelerationRatioX = 2f;
+    public float decelerationRatioY = 15f;
+
+    //漂浮
+    public int floatingState;      //0:不漂浮;1:漂浮中;2:飘着;3:掉下去
+    private Vector3 origPos;        //初始位置
+    private float curHeight;        //当前所在高度
+    private float riseTime;         //上升时间
+    private float backSpeed;        //返回速度
+    private float rotateSpeed;      //旋转速度
+    private float rotateDir;        //旋转方向
+    private float height;           //漂浮高度
+    private float rise = 1;
+    private float normalFallSpeed = 15f;
+
     private void Awake()
     {
         character = GetComponent<MoveCharacter>();
@@ -57,6 +70,60 @@ public class AttributeStatus : MonoBehaviour
     {
         switch (curSpecialStates[0])
         {
+            //漂浮
+            case SpecialState.FloatState:
+                switch (floatingState)
+                {
+                    case 1:
+                        transform.localEulerAngles += new Vector3(0, 0, 1) * rotateDir * rotateSpeed * Time.deltaTime;
+                        curHeight = Mathf.SmoothDamp(curHeight, height, ref rise, riseTime);
+                        transform.position = new Vector3(origPos.x, curHeight, origPos.z);
+                        if (curHeight >= height - 0.02f)
+                        {
+                            floatingState = 2;
+                            height = transform.position.y;
+                        }
+                        break;
+                    case 2:
+                        transform.localEulerAngles += new Vector3(0, 0, 1) * rotateDir * rotateSpeed * Time.deltaTime;
+                        break;
+                    case 3:
+                        if (transform.position.y >= origPos.y + 0.05f)
+                        {
+                            curHeight -= normalFallSpeed * Time.deltaTime;
+                            transform.position = new Vector3(origPos.x, curHeight, origPos.z);
+                        }
+                        else if (foot.TrigGround || curHeight <= origPos.y + 0.05f)
+                        {
+                            floatingState = 0;
+                            character.ChangeState(CharacterState.Idle);
+                            curSpecialStates[0] = SpecialState.Null;
+                            return;
+                        }
+                        break;
+                }
+                PlayerController playerController = GetComponent<PlayerController>();
+                if (playerController != null)
+                {
+                    if (playerController.mp > 0)
+                    {
+                        playerController.lostMp += playerController.mpReplySpeed * Time.deltaTime;
+                        playerController.mp -= playerController.mpReplySpeed * Time.deltaTime;
+                    }
+                    if (playerController.lostMp >= playerController.addMp)
+                    {
+                        Instantiate(playerController.soul, transform.position, new Quaternion(0, 0, 0, 0), null);
+                        playerController.lostMp = 0;
+                    }
+                }
+                attributeTime -= Time.deltaTime;
+                if (attributeTime <= 0)
+                {
+                    transform.localEulerAngles = Vector3.zero;
+                    floatingState = 3;
+                    rb.useGravity = true;
+                }
+                break;
             //击飞
             case SpecialState.BlownUp:
                 if (rb.velocity.magnitude > 0)
@@ -77,7 +144,7 @@ public class AttributeStatus : MonoBehaviour
                 else
                 {
                     //眩晕状态
-                    if (strikeStunTime <= 0)
+                    if (attributeTime <= 0)
                     {
                         curSpecialStates[0] = SpecialState.Null;
                         character.ChangeState(CharacterState.Idle);
@@ -85,7 +152,7 @@ public class AttributeStatus : MonoBehaviour
                     else
                     {
                         rb.velocity = Vector3.zero;
-                        strikeStunTime -= Time.deltaTime;
+                        attributeTime -= Time.deltaTime;
                     }
                 }
                 break;
@@ -109,7 +176,7 @@ public class AttributeStatus : MonoBehaviour
                 else
                 {
                     //眩晕状态
-                    if (strikeStunTime <= 0)
+                    if (attributeTime <= 0)
                     {
                         //被击晕后上升
                         rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
@@ -123,13 +190,13 @@ public class AttributeStatus : MonoBehaviour
                     else
                     {
                         rb.velocity = Vector3.zero;
-                        strikeStunTime -= Time.deltaTime;
+                        attributeTime -= Time.deltaTime;
                     }
                 }
                 break;
             //眩晕
             case SpecialState.Stun:
-                if (strikeStunTime <= 0)
+                if (attributeTime <= 0)
                 {
                     curSpecialStates[0] = SpecialState.Null;
                     character.ChangeState(CharacterState.Idle);
@@ -137,7 +204,7 @@ public class AttributeStatus : MonoBehaviour
                 else
                 {
                     rb.velocity = Vector3.zero;
-                    strikeStunTime -= Time.deltaTime;
+                    attributeTime -= Time.deltaTime;
                 }
                 break;
         }
@@ -146,7 +213,29 @@ public class AttributeStatus : MonoBehaviour
     //受到漂浮
     public void AddFloat(AttackInfo.FloatState floatState)
     {
+        if (curSpecialStates[0] != SpecialState.Null && curSpecialStates[0] < SpecialState.FloatState)
+        {
+            return;
+        }
+
 
+        rb.useGravity = false;
+        floatingState = 1;
+        origPos = transform.position;
+        curHeight = origPos.y;
+        riseTime = UnityEngine.Random.Range(floatState.upTime.x, floatState.upTime.y);
+        backSpeed = UnityEngine.Random.Range(floatState.backSpeed.x, floatState.backSpeed.y);
+        if (gameObject.tag == "Enemy" || gameObject.tag == "Player")
+        {
+            backSpeed = -backSpeed;
+        }
+        rotateSpeed = UnityEngine.Random.Range(floatState.rotateSpeed.x, floatState.rotateSpeed.y);
+        rotateDir = (1.5f - UnityEngine.Random.Range(1, 3)) * 2;
+        height = UnityEngine.Random.Range(floatState.height.x, floatState.height.y);
+        attributeTime = floatState.time * (1 - resistances.Float);
+
+        curSpecialStates[0] = SpecialState.FloatState;
+        character.ChangeState(CharacterState.SpecialStatus);
     }
 
 
@@ -159,7 +248,7 @@ public class AttributeStatus : MonoBehaviour
             {
                 return;
             }
-            strikeStunTime = blowUp.time * (1 - resistances.BlowUp);
+            attributeTime = blowUp.time * (1 - resistances.BlowUp);
             Vector3 vec3 = blowUp.dir.normalized;
             if(dir < 0)
             {
@@ -180,7 +269,7 @@ public class AttributeStatus : MonoBehaviour
             {
                 return;
             }
-            strikeStunTime = shotDown.time * (1 - resistances.ShotDown);
+            attributeTime = shotDown.time * (1 - resistances.ShotDown);
             Vector3 vec3 = shotDown.dir.normalized;
             if (dir < 0)
             {
@@ -201,7 +290,7 @@ public class AttributeStatus : MonoBehaviour
         {
             return;
         }
-        strikeStunTime = stun.time * (1 - resistances.Stun);
+        attributeTime = stun.time * (1 - resistances.Stun);
         curSpecialStates[0] = SpecialState.Stun;
         character.ChangeState(CharacterState.SpecialStatus);
     }

+ 0 - 6
ActionTowerDefense/Assets/Scripts/Characters/Demonic.cs

@@ -592,9 +592,6 @@ public class Demonic : MoveCharacter
             case CharacterState.Die:
                 isDie = false;
                 break;
-            case CharacterState.Float:
-                canMove = true;
-                break;
             case CharacterState.LockSoul:
                 //isReturnSoulTower = true;
                 break;
@@ -628,9 +625,6 @@ public class Demonic : MoveCharacter
                 isDie = true;
                 dieKeepTime = totalDieKeepTime;
                 break;
-            case CharacterState.Float:
-                canMove = false;
-                break;
             case CharacterState.LockSoul:
                 rb.velocity = Vector3.zero;
                 ani.Play("walk", 0, 0);

+ 60 - 69
ActionTowerDefense/Assets/Scripts/Characters/Enemy.cs

@@ -103,40 +103,51 @@ public class Enemy : MoveCharacter
     public override Vector3 GetMoveDir()
     {
         Vector3 moveDir = Vector3.zero;
-        if (canMove)
+        switch (searchState)
         {
-            switch (searchState)
-            {
-                case SearchState.NoTarget:
-                    if (TowerMap.myTowers.Count == 0)
-                    {
-                        moveDir = Vector3.right;
-                        break;
-                    }
-                    float minDistance = Mathf.Infinity;
-                    int id = -1;
-                    for (int i = 0; i < TowerMap.myTowers.Count; i++)
+            case SearchState.NoTarget:
+                if (TowerMap.myTowers.Count == 0)
+                {
+                    moveDir = Vector3.right;
+                    break;
+                }
+                float minDistance = Mathf.Infinity;
+                int id = -1;
+                for (int i = 0; i < TowerMap.myTowers.Count; i++)
+                {
+                    Tower myTower = TowerMap.myTowers[i].GetComponent<Tower>();
+                    if (transform.position.y >
+                        myTower.transform.position.y + myTower.height)
                     {
-                        Tower myTower = TowerMap.myTowers[i].GetComponent<Tower>();
-                        if (transform.position.y >
-                            myTower.transform.position.y + myTower.height)
-                        {
-                            continue;
-                        }
-                        float distance = Vector3.Distance(transform.position,
-                            TowerMap.myTowers[i].transform.position);
-                        if (distance < minDistance)
-                        {
-                            minDistance = distance;
-                            id = i;
-                        }
+                        continue;
                     }
-                    if (id == -1)
+                    float distance = Vector3.Distance(transform.position,
+                        TowerMap.myTowers[i].transform.position);
+                    if (distance < minDistance)
                     {
-                        moveDir = Vector3.right;
-                        break;
+                        minDistance = distance;
+                        id = i;
                     }
-                    if (bodyTrans.position.x > TowerMap.myTowers[id].transform.position.x)
+                }
+                if (id == -1)
+                {
+                    moveDir = Vector3.right;
+                    break;
+                }
+                if (bodyTrans.position.x > TowerMap.myTowers[id].transform.position.x)
+                {
+                    moveDir = Vector3.left;
+                }
+                else
+                {
+                    moveDir = Vector3.right;
+                }
+
+                break;
+            case SearchState.InSearchScope:
+                if (targetCharacter)
+                {
+                    if (targetCharacter.transform.position.x - transform.position.x < 0)
                     {
                         moveDir = Vector3.left;
                     }
@@ -144,45 +155,31 @@ public class Enemy : MoveCharacter
                     {
                         moveDir = Vector3.right;
                     }
-
-                    break;
-                case SearchState.InSearchScope:
-                    if (targetCharacter)
-                    {
-                        if (targetCharacter.transform.position.x - transform.position.x < 0)
-                        {
-                            moveDir = Vector3.left;
-                        }
-                        else
-                        {
-                            moveDir = Vector3.right;
-                        }
-                    }
-                    else
-                    {
-                        moveDir = Vector3.zero;
-                    }
-                    break;
-                case SearchState.InAttackScope:
-                    if (targetCharacter)
+                }
+                else
+                {
+                    moveDir = Vector3.zero;
+                }
+                break;
+            case SearchState.InAttackScope:
+                if (targetCharacter)
+                {
+                    if (targetCharacter.transform.position.x - transform.position.x < 0)
                     {
-                        if (targetCharacter.transform.position.x - transform.position.x < 0)
-                        {
-                            moveDir = Vector3.left;
-                        }
-                        else
-                        {
-                            moveDir = Vector3.right;
-                        }
+                        moveDir = Vector3.left;
                     }
                     else
                     {
-                        moveDir = Vector3.zero;
+                        moveDir = Vector3.right;
                     }
-                    break;
-                default:
-                    break;
-            }
+                }
+                else
+                {
+                    moveDir = Vector3.zero;
+                }
+                break;
+            default:
+                break;
         }
         if (!isBack)
         {
@@ -439,9 +436,6 @@ public class Enemy : MoveCharacter
             case CharacterState.Die:
                 isDie = false;
                 break;
-            case CharacterState.Float:
-                canMove = true;
-                break;
             default:
                 break;
         }
@@ -461,9 +455,6 @@ public class Enemy : MoveCharacter
             case CharacterState.Rush:
                 ani.Play("rush", 0, 0);
                 break;
-            case CharacterState.Float:
-                canMove = false;
-                break;
             case CharacterState.Attack:
                 break;
             case CharacterState.Die:

+ 4 - 124
ActionTowerDefense/Assets/Scripts/Characters/MoveCharacter.cs

@@ -25,7 +25,6 @@ public class MoveCharacter : Character
     public float extraFallGravity = -10; //下落时额外重力加速度
 
     [Header("属性")]
-    public bool canMove = true;
     public float moveSpeed = 5;
     public float flyHeight;
     public float flyUpSpeed = 10;
@@ -55,30 +54,13 @@ public class MoveCharacter : Character
     public float pastComaTime;
 
     [Header("漂浮")]
-    public int floatState;          //0:不漂浮;1:漂浮中;2:飘着;3:掉下去
-    private float rise = 1;
-
-    public float maxTime = 1.5f;    //上升最大耗时
-    public float minTime = 0.1f;    //上升最小耗时
-    public float maxHeight = 12;    //最大上升高度
-    public float minHeight = 7;     //最小上升高度
-    private float curHeight;        //当前所在高度
-    private Vector3 origPos;    //初始位置
-    private float origY;
-    private float height;           //漂浮高度
+
     public float floatTime = 20;    //漂浮时间
-    private float curTime;          //漂浮已进行时长
-    private float riseTime;         //上升时间
-    private float pastTime;         //上升已用时间
 
-    public float maxRotateSpeed = 20;       //最大旋转速度
-    public float minRotateSpeed = 5;        //最小旋转速度
-    private float rotateSpeed;              //旋转速度
-    private float rotateDir;                //旋转方向
-    private float backSpeed;                //往后退的速度
-    public bool isFloat;                    //正在漂浮中
 
-    public float normalFallSpeed;
+
+
+
 
     [Header("临时血量")]
     public GameObject effect;
@@ -116,7 +98,6 @@ public class MoveCharacter : Character
         spinee = bodyTrans.GetChild(0).gameObject;
         mesh = spinee.GetComponent<MeshRenderer>();
         mats = mesh.materials;
-        origY = transform.position.y;
         attributeStatus = GetComponent<AttributeStatus>();
     }
 
@@ -157,98 +138,6 @@ public class MoveCharacter : Character
         matState = state;
     }
 
-    public void FloatStateOn()
-    {
-        if (canMove)
-        {
-            canMove = false;
-            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);
-        }
-    }
-
-    private void RotateSelf()
-    {
-        transform.localEulerAngles += new Vector3(0, 0, 1) * rotateDir * rotateSpeed * Time.deltaTime;
-    }
-
-    public void CharacterFloat()
-    {
-        if (floatState == 1)
-        {
-            RotateSelf();
-            curTime += Time.deltaTime;
-            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)
-        {
-            if (transform.position.y >= origY + 0.05f)
-            {
-                curHeight -= normalFallSpeed * Time.deltaTime;
-                transform.position = new Vector3(origPos.x, curHeight, origPos.z);
-            }
-            else if (foot.TrigGround || curHeight <= origY + 0.05f)
-            {
-                if (gameObject.layer == 7 && isInSoulTower)
-                {
-                    ChangeState(CharacterState.LockSoul);
-                }
-                else
-                {
-                    ChangeState(CharacterState.Idle);
-                }
-                ChangeMat(1);
-                floatState = 0;
-                isFloat = false;
-                canMove = true;
-                if (gameObject.tag == "Player")
-                {
-                    GetComponentInParent<PlayerController>().soulCollector.enabled = true;
-                }
-            }
-        }
-    }
-
     public void GetTemptHP(int addTemptHP, float time)
     {
         isTempt = true;
@@ -285,10 +174,6 @@ public class MoveCharacter : Character
         {
             Enlarge();
         }
-        if (floatState != 0)
-        {
-            CharacterFloat();
-        }
         if (isInvisible)
         {
             invisibleTime -= Time.deltaTime;
@@ -375,11 +260,6 @@ public class MoveCharacter : Character
         }
 
         int damage = attackInfo.damage;
-        //漂浮易伤
-        if (isFloat)
-        {
-            damage = (int)((1 + easyToGetHit) * damage);
-        }
 
         //伤害减免
         if (isDamageReduction)

+ 2 - 19
ActionTowerDefense/Assets/Scripts/Characters/PlayerController.cs

@@ -53,7 +53,7 @@ public class PlayerController : MoveCharacter
     public float mpReplySpeed_2Players; //双人模式下蓝量回复速度
     public float rapidReplySpeed;
     public float lostMp;
-    private float addMp = 10;
+    public float addMp = 10;
     public GameObject soul;
     public GameObject rapidReplyEffect;
     [Tooltip("场上每多一个同种类兵种,召唤兵种蓝耗+x")] public float[] addCostMp;
@@ -441,10 +441,6 @@ public class PlayerController : MoveCharacter
         {
             isKeepBtnRush = true;
         }
-        if (floatState != 0)
-        {
-            CharacterFloat();
-        }
         /*  //到时间自动解除变身
         if (endChange != 0)
         {
@@ -1496,7 +1492,7 @@ public class PlayerController : MoveCharacter
         //SearchTarget();
         //attackTarget = targetCharacter;
 
-        if (isMpRepel && floatState == 0)
+        if (isMpRepel)
         {
             if (mp < totalMp)
             {
@@ -1510,19 +1506,6 @@ public class PlayerController : MoveCharacter
                 }
             }
         }
-        if (floatState != 0)
-        {
-            if (mp > 0)
-            {
-                lostMp += mpReplySpeed * Time.deltaTime;
-                mp -= mpReplySpeed * Time.deltaTime;
-            }
-            if (lostMp >= addMp)
-            {
-                Instantiate(soul, transform.position, new Quaternion(0, 0, 0, 0), null);
-                lostMp = 0;
-            }
-        }
         if (mp > totalMp)
         {
             mp = totalMp;

+ 0 - 1
ActionTowerDefense/Assets/Scripts/Conduct/WavePowerSkill.cs

@@ -75,7 +75,6 @@ public class WavePowerSkill : MonoBehaviour
     public void ActiveFalse()
     {
         pc.conductCanRelease[cacheID] = true;
-        pc.canMove = true;
         pc.rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;
         pc.rb.useGravity = true;
         gameObject.SetActive(false);

+ 8 - 12
ActionTowerDefense/Assets/Scripts/Spirits/FloatEffect.cs

@@ -4,6 +4,7 @@ using UnityEngine;
 
 public class FloatEffect : MonoBehaviour
 {
+    public AttackInfo attackInfo;
     public bool isEnemy = false;
     private GameObject effect;
     private ParticleSystem ps;
@@ -25,26 +26,21 @@ public class FloatEffect : MonoBehaviour
     {
         if (other.gameObject.layer == 8 )
         {
-            Enemy enee = other.GetComponentInParent<Enemy>();
-            if (enee != ene)
-            {
-                enee.FloatStateOn();
-            }
+            AttributeStatus attributeStatus = other.GetComponentInParent<AttributeStatus>();
+            attributeStatus.AddFloat(attackInfo.floatState);
         }
         else if(isEnemy && other.gameObject.layer == 7)
         {
-            Demonic dem = other.GetComponentInParent<Demonic>();
-            if(dem != null)
-            {
-                dem.FloatStateOn();
-            }
+            AttributeStatus attributeStatus = other.GetComponentInParent<AttributeStatus>();
+            attributeStatus.AddFloat(attackInfo.floatState);
         }
-        else if(isEnemy && other.gameObject.layer == 6)
+        if(isEnemy && other.gameObject.layer == 6)
         {
             PlayerController pc = other.GetComponentInParent<PlayerController>();
             pc.lostMp = 0;
             pc.soulCollector.enabled = false;
-            pc.FloatStateOn();
+            AttributeStatus attributeStatus = other.GetComponentInParent<AttributeStatus>();
+            attributeStatus.AddFloat(attackInfo.floatState);
         }
     }