summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Collider
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Unit/Collider')
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderAttributes.cs136
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderAttributes.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox.cs34
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox_Hitbox.cs124
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox_Hitbox.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs11
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox_ThrowBox.cs13
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox_ThrowBox.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderData.cs136
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderData.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderRegistry.cs35
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderRegistry.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Collider/CollisionSystem.cs262
-rw-r--r--Assets/Scripts/Unit/Collider/CollisionSystem.cs.meta11
16 files changed, 0 insertions, 839 deletions
diff --git a/Assets/Scripts/Unit/Collider/ColliderAttributes.cs b/Assets/Scripts/Unit/Collider/ColliderAttributes.cs
deleted file mode 100644
index 27889441..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderAttributes.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class ColliderTypeAttribute : Attribute
-{
- public ColliderTypeAttribute(ColliderBox.EColliderType type)
- {
- this.type = type;
- }
-
- public ColliderBox.EColliderType type;
-}
-
-
-public class IfAttribute : Attribute
-{
- public IfAttribute(string name)
- {
- this.conditionName = name;
- }
-
- public string conditionName;
-
-}
-
-public class IfNotAttribute : Attribute
-{
- public IfNotAttribute(string name)
- {
- this.conditionName = name;
- }
-
- public string conditionName;
-
-}
-
-public class WhenAttribute : Attribute
-{
- public WhenAttribute(string name, object value)
- {
- this.conditionName = name;
- this.value = (int)value;
- }
-
- public WhenAttribute(string name, params object[] values)
- {
- this.conditionName = name;
- this.values = new List<float>();
- foreach(var v in values)
- {
- this.values.Add((float)v);
- }
- }
-
- public bool IsSatisfied(float v)
- {
- if (values != null)
- return values.Contains(v);
- return value == v;
- }
-
- public string conditionName;
- public float value;
- public List<float> values;
-}
-
-public class AndWhenAttribute : Attribute
-{
- public AndWhenAttribute(string name, object value)
- {
- this.conditionName = name;
- this.value = (int)value;
- }
-
- public AndWhenAttribute(string name, params object[] values)
- {
- this.conditionName = name;
- this.values = new List<float>();
- foreach (var v in values)
- {
- this.values.Add((float)v);
- }
- }
-
- public bool IsSatisfied(float v)
- {
- if (values != null)
- return values.Contains(v);
- return value == v;
- }
-
- public string conditionName;
- public float value;
- public List<float> values;
-}
-
-public class WhenNotAttribute : Attribute
-{
- public WhenNotAttribute(string name, object value)
- {
- this.conditionName = name;
- this.value = (int)value;
- }
-
- public string conditionName;
- public int value;
-}
-
-public class CommentAttribute : Attribute
-{
- public CommentAttribute(string comment, TextAnchor alignment = TextAnchor.MiddleLeft)
- {
- this.comment = comment;
- this.alignment = alignment;
- }
- public string comment;
- public TextAnchor alignment;
-}
-
-public class FoldoutAttribute : Attribute
-{
- public FoldoutAttribute(string title, int count)
- {
- this.title = title;
- this.count = count;
- }
- public string title;
- public int count; // 下面的元素的个数
-}
-
-
-public class HDRAttribute : Attribute
-{
-}
diff --git a/Assets/Scripts/Unit/Collider/ColliderAttributes.cs.meta b/Assets/Scripts/Unit/Collider/ColliderAttributes.cs.meta
deleted file mode 100644
index 9cdbeaf7..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderAttributes.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 618a95231c298694696513e29164d269
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox.cs b/Assets/Scripts/Unit/Collider/ColliderBox.cs
deleted file mode 100644
index 24319ef2..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderBox.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-[Serializable]
-public partial class ColliderBox
-{
- // pivot
- public enum Pivot
- {
- MiddleBottom = 0,
- MiddleCenter = 1,
- }
-
- // 分化为不同的collider类型
- public enum EColliderType
- {
- HitBox,
- HurtBox,
- ThrowBox,
- BlockBox,
- DefendBox,
- }
-
- [DisallowModifiyInGUI]
- [Tooltip("Collider类型")]
- public EColliderType type;
-
- [DisallowModifiyInGUI]
- [Tooltip("Collider原点")]
- public Pivot pivot;
-
-} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox.cs.meta b/Assets/Scripts/Unit/Collider/ColliderBox.cs.meta
deleted file mode 100644
index 439b4b67..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderBox.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: f8d463de484da614bb9cad410152198a
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox_Hitbox.cs b/Assets/Scripts/Unit/Collider/ColliderBox_Hitbox.cs
deleted file mode 100644
index 9f1d629a..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderBox_Hitbox.cs
+++ /dev/null
@@ -1,124 +0,0 @@
-using UnityEngine;
-
-// 打击感相关资料
-// https://gameinstitute.qq.com/community/detail/112371
-//
-
-public partial class ColliderBox
-{
-
- public enum EColorDriftMode : int
- {
- None = 0,
- UI = 1,
- All = 2,
- }
-
- public enum EBlurMode : int
- {
- None = 0,
- Gauß = 1,
- Radial = 2,
- }
-
- public enum ESparkAnchor : int
- {
- CenterOfIntersection = 0, // hitbox和hurtbox相交的矩形中心
- CenterOfOther = 1, // 被攻击的对象的几何中心
- PositionOfOther = 2, // 被攻击对象的原点
- CenterOfHitbox = 3, // hitbox的中心
- FrontOfHitbox = 4, // hitbox的前方
- }
-
- public enum EMeshEffect : int
- {
- None = 0,
- White = 1,
- Red = 2,
- }
-
- // 击中反馈
- public enum EHitResponse
- {
- Light = 0,
- Heavy = 1,
- HitAir = 2,
- HitGround = 3,
- HitInAir = 4,
- }
-
- [ColliderType(EColliderType.HitBox)]
-
- [Tooltip("允许多次击中")]
- public bool multiHit;
-
- public EHitResponse hitResponse;
-
- [Tooltip("击退距离")]
- public Vector3 hitBack;
-
- [Tooltip("击退曲线")]
- public AnimationCurve hitCurve;
-
- [Comment("[ 击中效果 ]", TextAnchor.MiddleCenter)]
-
- [Foldout("时间效果", 3)]
- [Tooltip("全局顿帧")]
- public float freezeGlobal;
- [Tooltip("自身顿帧")]
- public float freezeFramesSelf;
- //[WhenNot("freezeFramesSelf", 0)]
- //public AnimationCurve freezeFramesSelfCurve;
- [Tooltip("对方顿帧")]
- public float freezeFramesOther;
- //[WhenNot("freezeFramesOther", 0)]
- //public AnimationCurve freezeFramesOtherCurve;
-
- [Foldout("粒子效果", 10)]
- [Tooltip("击中后的粒子效果")]
- public string sparkPath;
- [Tooltip("粒子的锚点")]
- public ESparkAnchor sparkAnchor = ESparkAnchor.CenterOfOther;
- [Tooltip("击中后的粒子位置偏移")]
- public Vector3 sparkOffset;
- [Tooltip("击中后的粒子大小")]
- public Vector3 sparkScale = Vector3.one;
- [Tooltip("多个粒子,最多支持3个")]
- public bool multiSparks;
- [If("multiSparks"), Tooltip("击中后的粒子效果")]
- public string spark2Path;
- [If("multiSparks"), Tooltip("粒子的锚点")]
- public ESparkAnchor spark2Anchor = ESparkAnchor.CenterOfOther;
- [If("multiSparks"), Tooltip("击中后的粒子位置偏移")]
- public Vector3 spark2Offset;
- [If("multiSparks"), Tooltip("击中后的粒子效果")]
- public string spark3Path;
- [If("multiSparks"), Tooltip("粒子的锚点")]
- public ESparkAnchor spark3Anchor = ESparkAnchor.CenterOfOther;
- [If("multiSparks"), Tooltip("击中后的粒子位置偏移")]
- public Vector3 spark3Offset;
-
- [Foldout("网格效果", 2)]
- public EMeshEffect selfEffect;
- public EMeshEffect otherEffect;
-
- [Foldout("相机效果", 4)]
- [Tooltip("拉近相机")]
- public bool zoomCamera;
- [Tooltip("是否震屏")]
- public bool shakeScreen;
- [If("shakeScreen"), Tooltip("是否震屏")]
- public Vector2 shakeOffset;
- [If("shakeScreen"), Tooltip("震屏力度")]
- public float shakeStrength;
-
- [Foldout("屏幕效果", 2)]
- [Tooltip("颜色漂移效果")]
- public EColorDriftMode colorDrift;
- public EBlurMode blur;
-
- [Foldout("音效", 1)]
- [Tooltip("音效")]
- public string soundPath;
-
-} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox_Hitbox.cs.meta b/Assets/Scripts/Unit/Collider/ColliderBox_Hitbox.cs.meta
deleted file mode 100644
index 639f1fc5..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderBox_Hitbox.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: ddd96c09da9d8ff468e34a19a4698555
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs b/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs
deleted file mode 100644
index 788b457a..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using UnityEngine;
-
-public partial class ColliderBox
-{
-
- [ColliderType(EColliderType.HurtBox)]
-
- [Tooltip("是否开启重力")]
- public bool useGravity;
-
-} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs.meta b/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs.meta
deleted file mode 100644
index 607eaa13..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 9a6f3f28157915d4799d28475c61a11a
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox_ThrowBox.cs b/Assets/Scripts/Unit/Collider/ColliderBox_ThrowBox.cs
deleted file mode 100644
index 932f1062..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderBox_ThrowBox.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public partial class ColliderBox
-{
- [ColliderType(EColliderType.ThrowBox)]
-
- [Tooltip("是否允许抓取多个")]
- public bool multiple;
-
-} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox_ThrowBox.cs.meta b/Assets/Scripts/Unit/Collider/ColliderBox_ThrowBox.cs.meta
deleted file mode 100644
index 14bc67b2..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderBox_ThrowBox.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 855e124ac6f58354a86276f0cda17fa1
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Collider/ColliderData.cs b/Assets/Scripts/Unit/Collider/ColliderData.cs
deleted file mode 100644
index 58743aff..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderData.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-// 用来返回某一时刻的碰撞盒几何数据
-public struct ColliderInfo
-{
- public bool active;
- public float frame;
- public Vector3 position;
- public Vector3 size;
- public ColliderBox.EColliderType type { get { return collider.type; } }
- public ColliderBox.Pivot pivot { get { return collider.pivot; } }
- public ColliderBox collider;
- public int colliderHash { get { return collider.GetHashCode(); } }
-
- public bool isValid { get { return collider != null; } } // 没有对应的数据时为false
-}
-
-// 某个碰撞盒的属性和帧数据,从属于animation data
-[Serializable]
-public class ColliderData
-{
- [Serializable]
- public class ColliderFrame
- {
- public int frame;
- public bool active;
- public Vector3 position;
- public Vector3 size;
- }
-
- public ColliderBox.EColliderType type { get { return collider.type; } }
- public ColliderBox.Pivot pivot { get { return collider.pivot; } }
-
- public ColliderBox collider;
-
- public List<ColliderFrame> frames;
-
- public ColliderData(ColliderBox.EColliderType type, ColliderBox.Pivot pivot)
- {
- this.frames = new List<ColliderFrame>();
- if (collider == null)
- collider = new ColliderBox();
- collider.type = type;
- collider.pivot = pivot;
- }
-
- public ColliderInfo GetColliderInfo(float frame)
- {
- ColliderInfo info = new ColliderInfo();
- info.active = false; // default
- info.collider = collider;
- info.frame = frame;
- int previous = 0;
- int end = -1;
- for (int i = 0; i < frames.Count; ++i)
- {
- if(frame >= frames[i].frame)
- {
- previous = frames[i].frame;
- }
- if(frames[i].frame > frame)
- {
- end = frames[i].frame;
- break;
- }
- }
- if(end == -1)
- {
- if(type == ColliderBox.EColliderType.HurtBox)
- {
- ColliderFrame pre = frames.Find(s => s.frame == previous);
- if (pre == null)
- return info;
- info.active = pre.active;
- info.position = pre.position;
- info.size = pre.size;
- }
- }
- else
- {
- ColliderFrame pre = frames.Find(s => s.frame == previous);
- ColliderFrame next = frames.Find(s => s.frame == end);
- if (pre == null || next == null)
- return info;
- info.active = pre.active;
- float t = (frame - previous) / (end - previous);
- info.position = Vector3.Lerp(pre.position, next.position, t);
- info.size = Vector3.Lerp(pre.size, next.size, t);
- }
- return info;
- }
-
- public ColliderFrame AddFrame(int frameIndex)
- {
- if (frames == null)
- frames = new List<ColliderFrame>();
- ColliderFrame frame = new ColliderFrame();
- frame.frame = frameIndex;
- frame.active = true;
- frame.position = Vector3.zero;
- frame.size = new Vector3(0.5f,1,1);
- frames.Add(frame);
- frames.Sort((a, b) => {
- if (a == null)
- return 1;
- if (b == null)
- return -1;
- if (a.frame < b.frame)
- return -1;
- if (a.frame > b.frame)
- return 1;
- return 0;
- });
- return frame;
- }
-
- public void DeleteFrame(int frameIndex)
- {
- if (frames == null)
- return;
- ColliderFrame frame = null;
- foreach(var f in frames)
- {
- if (f.frame == frameIndex)
- frame = f;
- }
- if(frame != null)
- {
- frames.Remove(frame);
- }
- }
-
-}
diff --git a/Assets/Scripts/Unit/Collider/ColliderData.cs.meta b/Assets/Scripts/Unit/Collider/ColliderData.cs.meta
deleted file mode 100644
index c66d5502..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderData.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 80e8515ea336e6a4ca6ebadad243468f
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Collider/ColliderRegistry.cs b/Assets/Scripts/Unit/Collider/ColliderRegistry.cs
deleted file mode 100644
index 408ce5a4..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderRegistry.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class ColliderRegistry : Singleton<ColliderRegistry>
-{
- public List<UnitCollider> colliders = new List<UnitCollider>();
- public List<Projectile> projectiles = new List<Projectile>();
-
- public void AddCollider(UnitCollider collider)
- {
- if (!colliders.Contains(collider))
- colliders.Add(collider);
- }
-
- public void RemoveCollider(UnitCollider collider)
- {
- if (colliders.Contains(collider))
- colliders.Remove(collider);
- }
-
-
- public void AddProjectile(Projectile projectile)
- {
- if (!projectiles.Contains(projectile))
- projectiles.Add(projectile);
- }
-
- public void RemoveProjectile(Projectile projectile)
- {
- if (projectiles.Contains(projectile))
- projectiles.Remove(projectile);
- }
-
-} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/Collider/ColliderRegistry.cs.meta b/Assets/Scripts/Unit/Collider/ColliderRegistry.cs.meta
deleted file mode 100644
index 8007287c..00000000
--- a/Assets/Scripts/Unit/Collider/ColliderRegistry.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 7787595f1b3721847aeca526a55446b9
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Collider/CollisionSystem.cs b/Assets/Scripts/Unit/Collider/CollisionSystem.cs
deleted file mode 100644
index 83052073..00000000
--- a/Assets/Scripts/Unit/Collider/CollisionSystem.cs
+++ /dev/null
@@ -1,262 +0,0 @@
-using System;
-using System.Collections.Generic;
-using UnityEngine;
-
-public struct ColliderDescriptor
-{
- public ColliderInfo colliderInfo;
- public UnitCollider unitCollider;
-}
-
-[Serializable]
-public struct Box
-{
- [SerializeField] public Vector3 center;
- [SerializeField] public Vector3 size;
-}
-
-public struct CollisionInfo
-{
- public ColliderDescriptor collider; // 主动
- public ColliderDescriptor collidee; // 从动
- public Box intersection;
- public bool isCollision;
-}
-
-public class CollisionSystem : SingletonMB<CollisionSystem>
-{
- public delegate void StageHandle();
-
- public StageHandle onSolveHit;
-
- [SerializeField]
- private int m_UnitColliderCount;
-
- ColliderRegistry registry { get { return ColliderRegistry.Instance; } }
-
- private void Start()
- {
- }
-
- void Update()
- {
- m_UnitColliderCount = registry.colliders != null ? registry.colliders.Count : 0;
-
- SolveHit();
- SolveProjectile();
- }
-
- // hitbox <-> hurtbox
- void SolveHit()
- {
- // collect all hit box
- List<ColliderDescriptor> hitboxes = ListPool<ColliderDescriptor>.Get();
- foreach (var collider in registry.colliders)
- {
- ColliderInfo[] boxes = collider.GetCurrentBoxesInfoByType(ColliderBox.EColliderType.HitBox);
- if (boxes == null || boxes.Length == 0)
- continue;
- for(int i = 0; i < boxes.Length; ++i)
- {
- ColliderDescriptor descriptor = new ColliderDescriptor();
- descriptor.colliderInfo = boxes[i];
- descriptor.unitCollider = collider;
- hitboxes.Add(descriptor);
- }
- }
- // collect all hurt box
- List<ColliderDescriptor> hurtboxes = ListPool<ColliderDescriptor>.Get();
- foreach (var collider in registry.colliders)
- {
- ColliderInfo[] boxes = collider.GetCurrentBoxesInfoByType(ColliderBox.EColliderType.HurtBox);
- if (boxes == null || boxes.Length == 0)
- continue;
- for (int i = 0; i < boxes.Length; ++i)
- {
- ColliderDescriptor descriptor = new ColliderDescriptor();
- descriptor.colliderInfo = boxes[i];
- descriptor.unitCollider = collider;
- hurtboxes.Add(descriptor);
- }
- }
-
- // solve
- for(int i = 0; i < hitboxes.Count; ++ i)
- {
- ColliderDescriptor hitbox = hitboxes[i];
- for (int j = 0; j < hurtboxes.Count; ++j)
- {
- ColliderDescriptor hurtbox = hurtboxes[j];
- if (hitbox.unitCollider == hurtbox.unitCollider)
- continue;
- if (hitbox.unitCollider.owner.type == hurtbox.unitCollider.owner.type)
- continue;
- CollisionInfo collision = ColliderUtility.GetCollision(hitbox, hurtbox);
- if (!collision.isCollision)
- continue;
- if (!hitbox.unitCollider.CanCollide(hitbox.colliderInfo.colliderHash, hurtbox.unitCollider.owner.GetHashCode()))
- continue;
- hitbox.unitCollider.RecordCollision(hitbox.colliderInfo.colliderHash, hurtbox.unitCollider.owner.GetHashCode());
- hitbox.unitCollider.owner.OnHit(collision);
- hurtbox.unitCollider.owner.OnGetHit(collision);
- }
- }
-
- ListPool<ColliderDescriptor>.Release(hitboxes);
- ListPool<ColliderDescriptor>.Release(hurtboxes);
- }
-
- void SolveProjectile()
- {
- // collect all hurt box
- List<ColliderDescriptor> hurtboxes = ListPool<ColliderDescriptor>.Get();
- foreach (var collider in registry.colliders)
- {
- ColliderInfo[] boxes = collider.GetCurrentBoxesInfoByType(ColliderBox.EColliderType.HurtBox);
- if (boxes == null || boxes.Length == 0)
- continue;
- for (int i = 0; i < boxes.Length; ++i)
- {
- ColliderDescriptor descriptor = new ColliderDescriptor();
- descriptor.colliderInfo = boxes[i];
- descriptor.unitCollider = collider;
- hurtboxes.Add(descriptor);
- }
- }
-
- foreach (var projectile in registry.projectiles)
- {
- if (projectile == null)
- continue;
- for(int i = 0; i < hurtboxes.Count; ++i)
- {
- ColliderDescriptor hurtCollider = hurtboxes[i];
- if (hurtCollider.unitCollider == null)
- continue;
- if (projectile.owner == null || hurtCollider.unitCollider.owner == null || projectile.owner.type == hurtCollider.unitCollider.owner.type)
- continue;
- Box hurtbox = ColliderUtility.GetColliderInWorldSpace(hurtCollider);
- foreach (var itor in projectile.GetCollidersInWorldSpace())
- {
- Box box = (Box)itor;
- Box intersection = ColliderUtility.GetIntersection(box, hurtbox);
- if (intersection.size.magnitude == 0)
- continue;
- if (!projectile.CanHit(hurtCollider.unitCollider.owner.GetHashCode()))
- continue;
- projectile.RecordTarget(hurtCollider.unitCollider.owner.GetHashCode());
-
- CollisionInfo collision = new CollisionInfo();
- collision.isCollision = true;
- collision.intersection = intersection;
- collision.collidee = hurtCollider;
- hurtCollider.unitCollider.owner.OnGetShot(collision);
- projectile.OnShot(collision);
-
- goto next;
- }
- }
- next:;
- }
- }
-
- // throwbox <-> hurtbox
- void SolveThrow()
- {
-
- }
-
- // defendbox <-> hurtbox
- void SolveDefend()
- {
-
- }
-
- // blockbox <-> hitbox
- void SolveBlock()
- {
-
- }
-
- private void OnDrawGizmos()
- {
- }
-
-}
-
-public static class ColliderUtility
-{
- public static CollisionInfo GetCollision(ColliderDescriptor collider, ColliderDescriptor collidee)
- {
- CollisionInfo collision = new CollisionInfo();
- collision.collider = collider;
- collision.collidee = collidee;
- Box colliderBox = GetColliderInWorldSpace(collider);
- Box collideeBox = GetColliderInWorldSpace(collidee);
- Box intersection = GetIntersection(colliderBox, collideeBox);
- collision.intersection = intersection;
- collision.isCollision = intersection.size.magnitude != 0;
- return collision;
- }
-
- public static Box GetColliderInWorldSpace(ColliderDescriptor collider)
- {
- Box box = new Box();
- Vector3 fac = new Vector3(1, 1, collider.unitCollider.owner.transform.forward.normalized == Vector3.forward ? 1 : -1);
- Vector3 unitPos = collider.unitCollider.owner.transform.position;
- Vector3 pos = Vector3.zero; // gizmo位置
- Vector3 localPos = collider.unitCollider.owner.transform.rotation * collider.colliderInfo.position;
- Vector3 localSize = collider.colliderInfo.size;
- var pivot = collider.colliderInfo.pivot;
- switch (pivot)
- {
- case ColliderBox.Pivot.MiddleBottom:
- localPos.y += localSize.y / 2;
- break;
- }
- pos = unitPos + Vector3.Scale(localPos, fac);
- box.center = pos;
- box.size = localSize;
- return box;
- }
-
- public static Box GetIntersection(Box b1, Box b2)
- {
- bool isIntersection = true;
-
- float l1 = b1.center.x - b1.size.x / 2;
- float r1 = b1.center.x + b1.size.x / 2;
- float l2 = b2.center.x - b2.size.x / 2;
- float r2 = b2.center.x + b2.size.x / 2;
- isIntersection &= r1 >= l2 && l1 <= r2;
-
- float o1 = b1.center.y - b1.size.y / 2;
- float t1 = b1.center.y + b1.size.y / 2;
- float o2 = b2.center.y - b2.size.y / 2;
- float t2 = b2.center.y + b2.size.y / 2;
- isIntersection &= t1 >= o2 && o1 <= t2;
-
- float c1 = b1.center.z - b1.size.z / 2;
- float f1 = b1.center.z + b1.size.z / 2;
- float c2 = b2.center.z - b2.size.z / 2;
- float f2 = b2.center.z + b2.size.z / 2;
- isIntersection &= f1 >= c2 && c1 <= f2;
-
- if(!isIntersection)
- {
- return new Box();
- }
-
- Box box = new Box();
- float l = Mathf.Max(l1, l2);
- float r = Mathf.Min(r1, r2);
- float b = Mathf.Max(o1, o2);
- float t = Mathf.Min(t1, t2);
- float c = Mathf.Max(c1, c2);
- float f = Mathf.Max(f1, f2);
- box.center = new Vector3((l + r) / 2, (b + t) / 2, (c + f) / 2 );
- box.size = new Vector3(r - l, t - b, f - c);
- return box;
- }
-
-} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/Collider/CollisionSystem.cs.meta b/Assets/Scripts/Unit/Collider/CollisionSystem.cs.meta
deleted file mode 100644
index 948c0ac7..00000000
--- a/Assets/Scripts/Unit/Collider/CollisionSystem.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: dc2cc9a83ab4066478ac795935406ee2
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant: