垃圾清理
This commit is contained in:
parent
a187c6ecc7
commit
8334325200
@ -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();
|
||||
}
|
||||
}
|
||||
|
20
Role/Role.cs
20
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
|
||||
{/// <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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user