예제 #1
0
        /// <summary>
        /// 衝突判定を実施します。
        /// </summary>
        internal void Update()
        {
            if (Count == 1)
            {
                preCollisionInfo = null;
                foreach (var pair in collection)
                {
                    foreach (var node in pair.Value)
                    {
                        node.UpdateCollider();
                        return;
                    }
                }
            }
            var dictionary = new Dictionary <ColliderEntry, bool>(preCollisionInfo?.Count ?? collection.Count);

            foreach (var current in this)
            {
                foreach (var comparison in this)
                {
                    if (current == comparison)
                    {
                        continue;
                    }
                    var entry        = new ColliderEntry(current.Collider, comparison.Collider);
                    var nowColliding = entry.IsColliding();
                    if (dictionary.TryAdd(entry, nowColliding))
                    {
                        current.UpdateCollider();
                        comparison.UpdateCollider();

                        var beforeColliding = preCollisionInfo != null && preCollisionInfo.TryGetValue(entry, out var value) && value;
                        InvokeEvents(current, comparison, nowColliding, beforeColliding);
                        InvokeEvents(comparison, current, nowColliding, beforeColliding);
                    }
                }
            }
            preCollisionInfo = dictionary;
        }
예제 #2
0
        /// <summary>
        /// 衝突判定を実施する
        /// </summary>
        internal void Update()
        {
            var dictionary = new Dictionary <ColliderEntry, bool>(preCollisionInfo?.Count ?? collection.Count);

            foreach (var current in this)
            {
                foreach (var comparison in this)
                {
                    if (current == comparison)
                    {
                        continue;
                    }
                    var entry        = new ColliderEntry(current.Collider, comparison.Collider);
                    var nowColliding = entry.IsColliding();
                    if (dictionary.TryAdd(entry, nowColliding))
                    {
                        var beforeColliding = (preCollisionInfo != null && preCollisionInfo.TryGetValue(entry, out var value)) ? value : false;
                        InvokeEvents(current, comparison, nowColliding, beforeColliding);
                        InvokeEvents(comparison, current, nowColliding, beforeColliding);
                    }
                }
            }
            preCollisionInfo = dictionary;
        }