private void OnTriggerEnter2D(Collider2D other) { 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 Triggered2D 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)) { GameObject target = other.gameObject; if (_targets.ContainsKey(target)) { return; } // We don't want that FYFY treates TriggerSensitive2DTarget component so we add component with classic Unity function. TriggerSensitive2DTarget tst = target.gameObject.AddComponent <TriggerSensitive2DTarget>(); tst._source = this; _targets.Add(target, tst); if (_inCollision == false) { // This action will be treated after all the collisions // (next preprocess operation is done before the next simulation step). GameObjectManager.addComponent <Triggered2D>(this.gameObject, true); _inCollision = true; } } } }
// Not fired when required components (Collider2D or RigidBody2D) are destroyed or disabled into this GameObject or targets. private void OnTriggerExit2D(Collider2D other) { if (this.isActiveAndEnabled) { GameObject target = other.gameObject; if (!_targets.ContainsKey(target)) { return; } TriggerSensitive2DTarget tst = _targets[target]; // Effects in TriggerSensitive2DTarget.OnDestroy Object.Destroy(tst); _targets.Remove(target); removeTriggered(); } }