public override void Dispose() { if (this.IsDisposed) { return; } base.Dispose(); if (OnCollisionEnterHandler != null) { var enterDelegates = OnCollisionEnterHandler.GetInvocationList(); for (int i = 0; i < enterDelegates.Length; i++) { OnCollisionEnterHandler -= enterDelegates[i] as Action <Unit, Vector3>; } } if (OnCollisionExitHandler != null) { var exitDelegates = OnCollisionExitHandler.GetInvocationList(); for (int i = 0; i < exitDelegates.Length; i++) { OnCollisionExitHandler -= exitDelegates[i] as Action <Unit, Vector3>; } } if (OnCollisionStayHandler != null) { var stayDelegates = OnCollisionStayHandler.GetInvocationList(); for (int i = 0; i < stayDelegates.Length; i++) { OnCollisionStayHandler -= stayDelegates[i] as Action <Unit>; } } }
void OnDestroy() { if (OnTriggerEnterHandler != null) { foreach (System.Delegate d in OnTriggerEnterHandler.GetInvocationList()) { OnTriggerEnterHandler -= (System.Action <GameObject, Collider>)d; } } if (OnTriggerExitHandler != null) { foreach (System.Delegate d in OnTriggerExitHandler.GetInvocationList()) { OnTriggerExitHandler -= (System.Action <GameObject, Collider>)d; } } if (OnCollisionEnterHandler != null) { foreach (System.Delegate d in OnCollisionEnterHandler.GetInvocationList()) { OnCollisionEnterHandler -= (System.Action <GameObject, Collision>)d; } } if (OnCollisionExitHandler != null) { foreach (System.Delegate d in OnCollisionExitHandler.GetInvocationList()) { OnCollisionExitHandler -= (System.Action <GameObject, Collision>)d; } } if (OnControllerColliderHitHandler != null) { foreach (System.Delegate d in OnControllerColliderHitHandler.GetInvocationList()) { OnControllerColliderHitHandler -= (System.Action <GameObject, ControllerColliderHit>)d; } } }