Переглянути джерело

重新让蝌蚪使用刚体,实现蝌蚪的击落等控制效果

HY-LSZNWIN10\Administrator 2 місяців тому
батько
коміт
86f771516c

+ 137 - 8
ActionTowerDefense/Assets/Resources/Prefab/Enemy/Enemy_Polliwog.prefab

@@ -46,8 +46,8 @@ BoxCollider:
   m_IsTrigger: 1
   m_Enabled: 1
   serializedVersion: 2
-  m_Size: {x: 0.9698016, y: 0.7297894, z: 2}
-  m_Center: {x: 0.077417046, y: 0.3368947, z: 0}
+  m_Size: {x: 1.0390339, y: 0.7297894, z: 2}
+  m_Center: {x: 0.042800903, y: 0.3368947, z: 0}
 --- !u!114 &1709563751208538466
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -140,7 +140,7 @@ MonoBehaviour:
   stackingWordsNum: 0
   resistances:
     controlOrder: 0
-    Float: 0
+    Float: -0
     BlowUp: 0
     ShotDown: 0
     Weak: 0
@@ -343,6 +343,8 @@ Transform:
   - {fileID: 4044399378262385515}
   - {fileID: 816689562064130092}
   - {fileID: 3372769376507897098}
+  - {fileID: 907761969314661049}
+  - {fileID: 2058339830308799942}
   m_Father: {fileID: 646884720114117071}
   m_RootOrder: 1
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -366,6 +368,51 @@ Animator:
   m_HasTransformHierarchy: 1
   m_AllowConstantClipSamplingOptimization: 1
   m_KeepAnimatorControllerStateOnDisable: 0
+--- !u!1 &1924299706538448007
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 2058339830308799942}
+  - component: {fileID: 3888338561730733447}
+  m_Layer: 8
+  m_Name: BodyCollider
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &2058339830308799942
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1924299706538448007}
+  m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 3248298059236281109}
+  m_RootOrder: 4
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!65 &3888338561730733447
+BoxCollider:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1924299706538448007}
+  m_Material: {fileID: 13400000, guid: ae11ca82bc783194e8fdded3f8828a76, type: 2}
+  m_IsTrigger: 0
+  m_Enabled: 1
+  serializedVersion: 2
+  m_Size: {x: 0.46103674, y: 0.12790298, z: 2}
+  m_Center: {x: -0.17371398, y: 0.15066338, z: 0}
 --- !u!1 &2658578937632965927
 GameObject:
   m_ObjectHideFlags: 0
@@ -515,6 +562,70 @@ MonoBehaviour:
     layerMixModes: 01000000
     layerBlendModes: 01000000
   updateTiming: 1
+--- !u!1 &3936486259959304397
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 907761969314661049}
+  - component: {fileID: 2785765483746129938}
+  - component: {fileID: 7116616475404866513}
+  m_Layer: 22
+  m_Name: Foot
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &907761969314661049
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3936486259959304397}
+  m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 3248298059236281109}
+  m_RootOrder: 3
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!65 &2785765483746129938
+BoxCollider:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3936486259959304397}
+  m_Material: {fileID: 0}
+  m_IsTrigger: 1
+  m_Enabled: 1
+  serializedVersion: 2
+  m_Size: {x: 0.48482826, y: 0.1711464, z: 2}
+  m_Center: {x: -0.21250014, y: 0.05192423, z: 0}
+--- !u!114 &7116616475404866513
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 3936486259959304397}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: c42213c575288a148b692aad7ab56bab, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  rb: {fileID: 0}
+  moveCharacter: {fileID: 0}
+  canOnGiant: 0
+  haveGravity: 1
+  trigGroundList: []
+  platform: {fileID: 0}
 --- !u!1 &5701931315761984808
 GameObject:
   m_ObjectHideFlags: 0
@@ -668,8 +779,8 @@ BoxCollider:
   m_IsTrigger: 1
   m_Enabled: 1
   serializedVersion: 2
-  m_Size: {x: 0.71258783, y: 0.49622822, z: 2}
-  m_Center: {x: -0.055391967, y: 0.3900652, z: 0}
+  m_Size: {x: 0.8959243, y: 0.6256423, z: 2}
+  m_Center: {x: -0.02843076, y: 0.36849666, z: 0}
 --- !u!114 &5849284137114900647
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -785,6 +896,7 @@ GameObject:
   - component: {fileID: 8023685214597940640}
   - component: {fileID: 3151684978354758052}
   - component: {fileID: 4087616115681235363}
+  - component: {fileID: 4735255374642079313}
   m_Layer: 8
   m_Name: Enemy_Polliwog
   m_TagString: Enemy
@@ -825,7 +937,7 @@ MonoBehaviour:
   bodyTrans: {fileID: 646884720114117071}
   beSearchTrigger: {fileID: 1461416353662333947}
   searchTrigger: {fileID: 0}
-  bodyCollider: {fileID: 0}
+  bodyCollider: {fileID: 1924299706538448007}
   uiHp: {fileID: 99864860648192471}
   beHitTrigger: {fileID: 1709563751208538466}
   attackController: {fileID: 4087616115681235363}
@@ -854,7 +966,7 @@ MonoBehaviour:
   canFly: 1
   canControlFly: 0
   nowCanFly: 0
-  canNotShotDown: 1
+  canNotShotDown: 0
   canNotAddForce: 0
   canNotChangeHurt: 0
   isDie: 0
@@ -870,7 +982,7 @@ MonoBehaviour:
   Attack_summonShootCanTransmit: 0
   debugAttackFrom: 0
   hitResistance: 0
-  foot: {fileID: 0}
+  foot: {fileID: 7116616475404866513}
   attributeStatus: {fileID: 0}
   hitFeedbackSystem: {fileID: 0}
   spineEvent: {fileID: 0}
@@ -948,6 +1060,7 @@ MonoBehaviour:
   rotationSpeedDeviation: 15
   rotationSmoothing: 5
   updateInterval: 1
+  isInGroup: 1
 --- !u!114 &4087616115681235363
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -1169,6 +1282,22 @@ MonoBehaviour:
     shootTrack: 0
     shootAlwaysTrack: 0
     skill: {fileID: 0}
+--- !u!54 &4735255374642079313
+Rigidbody:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 8023685214597940645}
+  serializedVersion: 2
+  m_Mass: 5
+  m_Drag: 0
+  m_AngularDrag: 0
+  m_UseGravity: 0
+  m_IsKinematic: 1
+  m_Interpolate: 0
+  m_Constraints: 116
+  m_CollisionDetection: 0
 --- !u!1 &8707527156012311288
 GameObject:
   m_ObjectHideFlags: 0

+ 1 - 0
ActionTowerDefense/Assets/Scripts/Characters/AttributeStatus.cs

@@ -540,6 +540,7 @@ public class AttributeStatus : MonoBehaviour
         {
             vec3.x = -vec3.x;
         }
+        rb.isKinematic = false;
         rb.useGravity = true;
         rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;
         rb.velocity = Vector3.zero;

+ 49 - 3
ActionTowerDefense/Assets/Scripts/Characters/Polliwog.cs

@@ -30,14 +30,21 @@ public class Polliwog : Enemy
 
     private List<Polliwog> nearbyFish = new List<Polliwog>();
     private float lastUpdateNearbyFishTime;
-
+    public bool isInGroup = true;
     public override void Awake()
     {
         base.Awake();
+        TryGetComponent<Rigidbody>(out rb);
     }
     protected override void OnEnable()
     {
+        if (PolliwogManager.GetInstance().IsFull())
+        {
+            gameObject.SetActive(false);
+            return;
+        }
         base.OnEnable();
+        rb.isKinematic = true;
         PolliwogManager.GetInstance().AddPolliwog(this);
         isDie = false;
         currentVelocity = Vector2.zero;
@@ -62,10 +69,24 @@ public class Polliwog : Enemy
 
     public override void ChangeState(CharacterState newState)
     {
+        Debug.Log("´Ó" + state + "ÇĐťťľ˝" + newState);
         if (state == newState)
         {
             return;
         }
+        switch (state)
+        {
+            case CharacterState.HitStun:
+            case CharacterState.SpecialStatus_Float:
+            case CharacterState.SpecialStatus_BlowUp:
+            case CharacterState.SpecialStatus_ShotDown:
+            case CharacterState.SpecialStatus_Weak:
+                isInGroup = true;
+                currentVelocity = Vector2.zero;
+                rb.velocity = Vector3.zero;
+                rb.isKinematic = true;
+                break;
+        }
         state = newState;
         switch (newState)
         {
@@ -82,6 +103,15 @@ public class Polliwog : Enemy
                 dieKeepTime = totalDieKeepTime;
                 DropSouls();
                 break;
+            case CharacterState.HitStun:
+            case CharacterState.SpecialStatus_Float:
+            case CharacterState.SpecialStatus_BlowUp:
+            case CharacterState.SpecialStatus_ShotDown:
+            case CharacterState.SpecialStatus_Weak:
+                rb.isKinematic = false;
+                isInGroup = false;
+                currentVelocity = Vector2.zero;
+                break;
             default:
                 break;
         }
@@ -107,7 +137,8 @@ public class Polliwog : Enemy
 
     public override void OnState()
     {
-        if (state == CharacterState.None)
+        if (PlayersInput.instance.Length > 0) playerTarget = PlayersInput.instance[0].transform;
+        if (state == CharacterState.None || playerTarget == null)
         {
             return;
         }
@@ -158,6 +189,7 @@ public class Polliwog : Enemy
                 {
                     attackController.attackTrigger.gameObject.SetActive(true);
                 }
+                transform.position += (Vector3)currentVelocity * Time.fixedDeltaTime;
                 break;
             case CharacterState.Die:
                 currentVelocity = Vector2.zero;
@@ -171,8 +203,22 @@ public class Polliwog : Enemy
                     break;
                 }
                 break;
+            case CharacterState.HitStun:
+                hitFeedbackSystem.HitStunUpdate();
+                break;
+            case CharacterState.SpecialStatus_Float:
+                attributeStatus.SpecialStateEffect(SpecialState.FloatState);
+                break;
+            case CharacterState.SpecialStatus_BlowUp:
+                attributeStatus.SpecialStateEffect(SpecialState.BlownUp);
+                break;
+            case CharacterState.SpecialStatus_ShotDown:
+                attributeStatus.SpecialStateEffect(SpecialState.ShotDown);
+                break;
+            case CharacterState.SpecialStatus_Weak:
+                attributeStatus.SpecialStateEffect(SpecialState.Weak);
+                break;
         }
-        transform.position += (Vector3)currentVelocity * Time.fixedDeltaTime;
     }
 
     public Vector2 CalculateMove1()

+ 3 - 3
ActionTowerDefense/Assets/Scripts/PolliwogManager.cs

@@ -13,7 +13,7 @@ public class PolliwogManager : MonoBehaviour
     private float lastQuadTreeUpdateTime;
     private Rect quadTreeBounds;
 
-    public const int maxNum = 150;
+    public const int maxNum = 100;
 
     public static PolliwogManager GetInstance()
     {
@@ -39,9 +39,9 @@ public class PolliwogManager : MonoBehaviour
         lastQuadTreeUpdateTime = Time.time;
 
         quadTree.Clear();
-        foreach (var fish in list)
+        foreach (Polliwog fish in list)
         {
-            quadTree.Insert(fish);
+            if(fish.isInGroup) quadTree.Insert(fish);
         }
     }
 

+ 1 - 1
ActionTowerDefense/Assets/Scripts/PolliwogShot.cs

@@ -24,7 +24,7 @@ public class PolliwogShot : SpecialSkills
     {
         for (int i = 0; i < num; i++)
         {
-            if (PolliwogManager.GetInstance().IsFull()) continue;
+            if (PolliwogManager.GetInstance().IsFull()) break;
             PoolManager.InstantiateAsync("Prefab/Enemy/Enemy_Polliwog", pos.position, new Quaternion(0, 0, 0, 0), null, obj =>
             {
                 Polliwog pol = obj.GetComponent<Polliwog>();