示例#1
0
        public void ResolveCollision(CustomCollider2D collider, Vector2 normal, float penetration)
        {
            if (!isTrigger && !collider.isTrigger)
            {
                float massRatio       = collider.Mass / collider.Mass;
                float penetrationMult = 1f / (1f + massRatio);

                transform.Translate(normal * penetration * penetrationMult);

                onCollision.Invoke(collider, normal, penetration);
            }
            else
            {
                onTrigger.Invoke(collider);
            }
        }
        public void RegisterCollider2D(LayerMask layer, CustomCollider2D collider)
        {
            LayerKey[] keys = new LayerKey[colliders.Keys.Count];
            colliders.Keys.CopyTo(keys, 0);

            LayerKey layerKey = Array.Find(keys, k => k.layer == layer);

            if (!colliders.ContainsKey(layerKey))
            {
                int nextIndex = keys.GetLength(0);
                layerKey = new LayerKey(layer, nextIndex);
                List <CustomCollider2D> colliderList = new List <CustomCollider2D>();

                colliders.Add(layerKey, colliderList);
            }

            colliders[layerKey].Add(collider);
        }