private void OnCollisionEnter2D(Collision2D coll) { if (this.isActiveAndEnabled) { // We check if there is an UnbindGameObject action on my gameobject or on my parents. // If not, we have to use FYFY to add InCollision2D in order to keep families synchronized. // If so, we don't add this action because it will be queued after unbind and will not be able to proceed (unknown game object). Transform[] parents = this.gameObject.GetComponentsInParent <Transform>(true); // this.gameobject.transform is include if (!GameObjectManager.containActionFor(typeof(UnbindGameObject), parents)) { // We don't find an unbind action, then we can add PointerOver component with classic Unity function GameObject target = coll.gameObject; if (_targets.ContainsKey(target)) { return; } // We don't want that FYFY treates CollisionSensitive2DTarget component so we add component with classic Unity function. CollisionSensitive2DTarget cst = target.gameObject.AddComponent <CollisionSensitive2DTarget>(); cst._source = this; _collisions.Add(target, coll); _targets.Add(target, cst); if (_inCollision == false) { // This action will be treated after all the collisions // (next preprocess operation is done before the next simulation step). GameObjectManager.addComponent <InCollision2D>(this.gameObject, true); _inCollision = true; } } } }
// Not fired when required components (Collider2D or RigidBody2D) are destroyed or disabled into this GameObject or targets. private void OnCollisionExit2D(Collision2D coll) { if (this.isActiveAndEnabled) { GameObject target = coll.gameObject; if (!_targets.ContainsKey(target)) { return; } CollisionSensitive2DTarget cst = _targets[target]; // Effects in CollisionSensitive2DTarget.OnDestroy Object.Destroy(cst); _collisions.Remove(target); _targets.Remove(target); removeInCollision(); } }