-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnityObjectDestoyer 改め RuntimeGltfInstance #1021
Changes from 8 commits
6268ec8
3b1f3fb
aa6b826
a17c789
e9d4654
0bdd18c
612a59c
81e02c8
ac7e4cd
4db1711
423889c
89276c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using VRMShaders; | ||
|
||
namespace UniGLTF | ||
{ | ||
/// <summary> | ||
/// Mesh, Material, Texture などを抱えておいて確実に破棄できるようにする | ||
/// </summary> | ||
public class UnityObjectManager : MonoBehaviour, IResponsibilityForDestroyObjects | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 存在はいい!が名前が…う~ん… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ユーザの期待としては There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. インスタンスの変数名も |
||
{ | ||
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 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"); | ||
foreach (var (key, x) in m_resources) | ||
{ | ||
UnityObjectDestoyer.DestroyRuntimeOrEditor(x); | ||
} | ||
} | ||
|
||
public void TransferOwnership(TakeResponsibilityForDestroyObjectFunc take) | ||
{ | ||
foreach (var (key, x) in m_resources.ToArray()) | ||
{ | ||
take(key, x); | ||
m_resources.Remove((key, x)); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
UnityObjectDestoyer.DestroyRuntimeOrEditor(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. たしかに! |
||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yosasou