-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
awake and on destroy methods to destroy all avatar components
- Loading branch information
Showing
1 changed file
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,43 @@ | ||
using UnityEngine; | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace ReadyPlayerMe.Core | ||
{ | ||
public class AvatarData : MonoBehaviour | ||
{ | ||
public string AvatarId; | ||
public AvatarMetadata AvatarMetadata; | ||
|
||
private SkinnedMeshRenderer[] meshes; | ||
|
||
private void Awake() | ||
{ | ||
meshes = GetComponentsInChildren<SkinnedMeshRenderer>(); | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
foreach (var mesh in meshes) | ||
{ | ||
var materials = mesh.sharedMaterials; | ||
|
||
foreach (var material in materials) | ||
{ | ||
if(material == null) continue; | ||
|
||
foreach (var property in material.GetTexturePropertyNames()) | ||
{ | ||
Texture texture = material.GetTexture(property); | ||
|
||
if(texture == null) continue; | ||
|
||
Destroy(texture); | ||
} | ||
Destroy(material); | ||
} | ||
|
||
Destroy(mesh.sharedMesh); | ||
} | ||
} | ||
} | ||
} |