垃圾清理

This commit is contained in:
wulongxiao 2025-01-09 13:30:13 +08:00
parent a187c6ecc7
commit 8334325200
2 changed files with 39 additions and 0 deletions

View File

@ -369,4 +369,23 @@ public class Bullet : MonoBehaviour
Destroy(this.gameObject);
}
void OnDestroy()
{
// 清理动态加载资源
if (transform.GetComponent<Renderer>() != null)
{
var material = transform.GetComponent<Renderer>().material;
if (material != null) Destroy(material);
var texture = material.mainTexture;
if (texture != null) Destroy(texture);
}
// 停止协程
StopAllCoroutines();
// 清理未使用的资源
Resources.UnloadUnusedAssets();
}
}

View File

@ -7,6 +7,7 @@ using UnityEngine.UI;
using DG.Tweening;
using TMPro;
using Debug = UnityEngine.Debug;
using UnityEngine.EventSystems;
public enum Camp
{/// <summary>
@ -735,8 +736,27 @@ public class Role : Fun
return relation;
}
void OnDestroy()
{
this.AnimationTree = null;
// 清理动态加载资源
if (transform.GetComponent<Renderer>() != null)
{
var material = transform.GetComponent<Renderer>().material;
if (material != null) Destroy(material);
var texture = material.mainTexture;
if (texture != null) Destroy(texture);
}
// 停止协程
StopAllCoroutines();
// 清理未使用的资源
Resources.UnloadUnusedAssets();
}
}