diff --git a/Role/Bullet.cs b/Role/Bullet.cs index aa4e279..100da7d 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -369,4 +369,23 @@ public class Bullet : MonoBehaviour Destroy(this.gameObject); } + void OnDestroy() + { + // 清理动态加载资源 + if (transform.GetComponent() != null) + { + var material = transform.GetComponent().material; + if (material != null) Destroy(material); + + var texture = material.mainTexture; + if (texture != null) Destroy(texture); + } + + // 停止协程 + StopAllCoroutines(); + + + // 清理未使用的资源 + Resources.UnloadUnusedAssets(); + } } diff --git a/Role/Role.cs b/Role/Role.cs index a39e5d4..e17dc8b 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -7,6 +7,7 @@ using UnityEngine.UI; using DG.Tweening; using TMPro; using Debug = UnityEngine.Debug; +using UnityEngine.EventSystems; public enum Camp {/// @@ -735,8 +736,27 @@ public class Role : Fun return relation; } + + void OnDestroy() { this.AnimationTree = null; + + // 娓呯悊鍔ㄦ佸姞杞借祫婧 + if (transform.GetComponent() != null) + { + var material = transform.GetComponent().material; + if (material != null) Destroy(material); + + var texture = material.mainTexture; + if (texture != null) Destroy(texture); + } + + // 鍋滄鍗忕▼ + StopAllCoroutines(); + + + // 娓呯悊鏈娇鐢ㄧ殑璧勬簮 + Resources.UnloadUnusedAssets(); } }