From 34d01108e9f0c5488e8824f768c43801dd8ed4cc Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 4 Sep 2021 14:02:24 +0800 Subject: *misc --- Assets/Scripts/Projectile/Projectile.cs | 59 +++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'Assets/Scripts/Projectile/Projectile.cs') diff --git a/Assets/Scripts/Projectile/Projectile.cs b/Assets/Scripts/Projectile/Projectile.cs index a6411f5f..ba325302 100644 --- a/Assets/Scripts/Projectile/Projectile.cs +++ b/Assets/Scripts/Projectile/Projectile.cs @@ -4,16 +4,18 @@ using UnityEngine; public struct ProjectileInfo { - public UnitController owner; + public string name; + public string tag; + public EventProjectile.EMoveType moveType; + public UnitController owner; public Vector3 position; public Vector3 rotation; public Vector3 scale; - public Vector3 direction; public Vector3 velocity; - public bool towardDirection; + public Vector3 acceleration; + public bool towardDirection; public float lifetime; public bool useGravity; - public float gravity; public string sparkPath; } @@ -35,9 +37,17 @@ public class Projectile : MonoBehaviour public Box colliderGrid; public Vector3 slice; - #endregion + #endregion - [HideInInspector] + //名字,可以用来识别这个projectile + public new string name; + + //标签,可以用来做一些标记 + public new string tag; + + public EventProjectile.EMoveType moveType; + + [HideInInspector] public UnitController owner; [HideInInspector] @@ -46,10 +56,10 @@ public class Projectile : MonoBehaviour [HideInInspector] public Vector3 velocity; // 初始速度 - [HideInInspector] - public float gravity; + [HideInInspector] + public Vector3 acceleration; // 加速度 - [HideInInspector] + [HideInInspector] public bool towardDirection; // foward朝向运动的方向 [HideInInspector] @@ -65,12 +75,16 @@ public class Projectile : MonoBehaviour public void Initialize(ProjectileInfo info) { + this.name = info.name; + this.tag = info.tag; + this.moveType = info.moveType; this.owner = info.owner; this.transform.rotation = Quaternion.Euler(info.rotation); this.transform.position = info.position; this.transform.localScale.Scale(info.scale); this.velocity = info.velocity; - this.lifetime = info.lifetime; + this.acceleration = info.acceleration; + this.lifetime = info.lifetime; this.sparkPath = info.sparkPath; markDestroy = false; @@ -92,15 +106,19 @@ public class Projectile : MonoBehaviour public void Update(float deltaTime) { - this.transform.position += this.velocity * deltaTime; - time += deltaTime; - if (time > this.lifetime || markDestroy) - { - DestroyImmediate(this.gameObject); - } - } + if(moveType == EventProjectile.EMoveType.Kinematic) + { + this.velocity += this.acceleration * deltaTime; + this.transform.position += this.velocity * deltaTime; + } + time += deltaTime; + if (time > this.lifetime || markDestroy) + { + DestroyImmediate(this.gameObject); + } + } - void OnDestroy() + void OnDestroy() { ColliderRegistry.Instance.RemoveProjectile(this); } @@ -179,4 +197,9 @@ public class Projectile : MonoBehaviour } } + public bool HasTag(string tag) + { + return this.tag != null && this.tag.Contains(tag); + } + } \ No newline at end of file -- cgit v1.1-26-g67d0