From 833432520044afdb4bf6566e25b8c31cf3635e53 Mon Sep 17 00:00:00 2001 From: wulongxiao <2545507770@qq.com> Date: Thu, 9 Jan 2025 13:30:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9E=83=E5=9C=BE=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Bullet.cs | 19 +++++++++++++++++++ Role/Role.cs | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) 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(); } }