mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-01 02:57:06 -05:00
65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using VRMShaders;
|
|
|
|
namespace UniGLTF
|
|
{
|
|
/// <summary>
|
|
/// Mesh, Material, Texture などを抱えておいて確実に破棄できるようにする
|
|
/// </summary>
|
|
public class UnityObjectManager : MonoBehaviour, IResponsibilityForDestroyObjects
|
|
{
|
|
List<(SubAssetKey, UnityEngine.Object)> m_resources = new List<(SubAssetKey, UnityEngine.Object)>();
|
|
|
|
public static UnityObjectManager AttachTo(GameObject go, ImporterContext context)
|
|
{
|
|
var loaded = go.AddComponent<UnityObjectManager>();
|
|
context.TransferOwnership((k, o) =>
|
|
{
|
|
loaded.m_resources.Add((k, o));
|
|
return true;
|
|
});
|
|
return loaded;
|
|
}
|
|
|
|
public void ShowMeshes()
|
|
{
|
|
foreach (var r in GetComponentsInChildren<Renderer>())
|
|
{
|
|
r.enabled = true;
|
|
}
|
|
}
|
|
|
|
public void EnableUpdateWhenOffscreen()
|
|
{
|
|
foreach (var smr in GetComponentsInChildren<SkinnedMeshRenderer>())
|
|
{
|
|
smr.updateWhenOffscreen = true;
|
|
}
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Debug.Log("UnityResourceDestroyer.OnDestroy");
|
|
Dispose();
|
|
}
|
|
|
|
public void TransferOwnership(TakeResponsibilityForDestroyObjectFunc take)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
foreach (var (key, x) in m_resources)
|
|
{
|
|
#if VRM_DEVELOP
|
|
// Debug.Log($"Destroy: {x}");
|
|
#endif
|
|
UnityObjectDestoyer.DestroyRuntimeOrEditor(x);
|
|
}
|
|
}
|
|
}
|
|
}
|