private void OnCollisionEnter(Collision 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 InCollision3D 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 = coll.gameObject; if (_targets.ContainsKey(target)) { return; } // We don't want that FYFY treates CollisionSensitive3DTarget component so we add component with classic Unity function. CollisionSensitive3DTarget cst = target.gameObject.AddComponent <CollisionSensitive3DTarget>(); cst._source = this; _collisions.Add(target, coll); _targets.Add(target, cst); if (_inCollision == false) { // This action will be treated immediatly after all the collisions // (next preprocess operation is done before the next simulation step). GameObjectManager.addComponent <InCollision3D>(this.gameObject, true); _inCollision = true; } } } }
// Not fired when this GameObject or the target is destroyed. private void OnCollisionExit(Collision coll) { if (this.isActiveAndEnabled) { GameObject target = coll.gameObject; if (!_targets.ContainsKey(target)) { return; } CollisionSensitive3DTarget cst = _targets[target]; // Effects in CollisionSensitive3DTarget.OnDestroy Object.Destroy(cst); _collisions.Remove(target); _targets.Remove(target); removeInCollision(); } }