diff options
author | chai <chaifix@163.com> | 2020-10-17 10:12:31 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-17 10:12:31 +0800 |
commit | f99c4d56cf95c563e95d3965ffd6d8ba33b660ee (patch) | |
tree | cbec1f362d5eb0fd2ee67885cae17a527796f41c /Assets/Scripts/Physics/PhysicsWorld.cs | |
parent | ecb0cbe03d3eef32fdb7b43fa3c60f0f241b0129 (diff) |
*ability system
Diffstat (limited to 'Assets/Scripts/Physics/PhysicsWorld.cs')
-rw-r--r-- | Assets/Scripts/Physics/PhysicsWorld.cs | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/Assets/Scripts/Physics/PhysicsWorld.cs b/Assets/Scripts/Physics/PhysicsWorld.cs index 3514934c..444fe392 100644 --- a/Assets/Scripts/Physics/PhysicsWorld.cs +++ b/Assets/Scripts/Physics/PhysicsWorld.cs @@ -30,7 +30,7 @@ public class PhysicsWorld : Singleton<PhysicsWorld> // 重力加速度
private readonly Vector3 m_Gravity = new Vector3(0, -9.8f, 0);
// 当前管理的碰撞体
- private List<PhysicsPrimitive> m_Primitives;
+ private List<PhysicsPrimitive> m_Primitives = new List<PhysicsPrimitive>();
private float m_TimeCount;
private readonly int[] m_CollisionTable = {
@@ -41,9 +41,10 @@ public class PhysicsWorld : Singleton<PhysicsWorld> /*wall */ 0, 0, 0, 0,
};
+ private List<Animator> m_Animators = new List<Animator>();
+
public void Init()
{
- m_Primitives = new List<PhysicsPrimitive>();
m_TimeCount = Time.time;
}
@@ -66,6 +67,19 @@ public class PhysicsWorld : Singleton<PhysicsWorld> m_Primitives.Remove(prim);
}
+ public void AddAnimator(Animator animator)
+ {
+ if (m_Animators.Contains(animator))
+ return;
+ m_Animators.Add(animator);
+ }
+
+ public void RemoveAnimator(Animator animator)
+ {
+ if (m_Animators.Contains(animator))
+ m_Animators.Remove(animator);
+ }
+
/// <summary>
/// 物理系统已稳定的逻辑帧率执行
/// </summary>
@@ -82,14 +96,34 @@ public class PhysicsWorld : Singleton<PhysicsWorld> m_TimeCount -= dt;
}
- private void Tick()
+ void Tick()
{
float deltaTime = 1f / m_UpdateRate;
+ // animator -> OnAnimatorMove() -> physics
+ UpdateAnimator(deltaTime);
+ UpdatePrimitives(deltaTime);
+ }
+
+ // 更新动画,并处理OnAnimatorMove()
+ void UpdateAnimator(float deltaTime)
+ {
+ for (int i = 0; i < m_Animators.Count; ++i)
+ {
+ Animator animator = m_Animators[i];
+ animator.speed = 1;
+ animator.Update(deltaTime);
+ animator.speed = 0;
+ }
+ }
+
+ // 更新物理系统
+ void UpdatePrimitives(float deltaTime)
+ {
int groupCount = (int)PhysicsGroup.GroupCount;
for (int i = 0; i < m_Primitives.Count; ++i)
{
PhysicsPrimitive prim1 = m_Primitives[i];
- for(int j = i + 1; j < m_Primitives.Count; ++j)
+ for (int j = i + 1; j < m_Primitives.Count; ++j)
{
PhysicsPrimitive prim2 = m_Primitives[j];
@@ -104,13 +138,13 @@ public class PhysicsWorld : Singleton<PhysicsWorld> continue;
PhysicsCollisionInfo info;
- if(PhysicsHelper.PrimvsPrim(prim1, prim2, out info))
+ if (PhysicsHelper.PrimvsPrim(prim1, prim2, out info))
{
//没有physics body的primitive将不会被移动,只有那些绑定了physics body的会被施加物理效果,比如角色身体、物品
}
}
}
- }
+ }
}
\ No newline at end of file |