mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-25 07:28:51 -05:00
TakeResponsibilityForDestroyObjectFunc の返り値削除
GameObject(prefab root)の移譲の判定にしか使っていなかった。設計変更で不要になった
This commit is contained in:
parent
0bdd18c408
commit
612a59cba7
|
|
@ -54,7 +54,6 @@ namespace UniGLTF
|
|||
loaded.TransferOwnership((k, o) =>
|
||||
{
|
||||
context.AddObjectToAsset(k.Name, o);
|
||||
return true;
|
||||
});
|
||||
|
||||
context.AddObjectToAsset(loaded.name, loaded.gameObject);
|
||||
|
|
|
|||
|
|
@ -313,10 +313,8 @@ namespace UniGLTF
|
|||
{
|
||||
foreach (var mesh in Meshes.ToArray())
|
||||
{
|
||||
if (take(SubAssetKey.Create(mesh.Mesh), mesh.Mesh))
|
||||
{
|
||||
Meshes.Remove(mesh);
|
||||
}
|
||||
take(SubAssetKey.Create(mesh.Mesh), mesh.Mesh);
|
||||
Meshes.Remove(mesh);
|
||||
}
|
||||
|
||||
TextureFactory.TransferOwnership(take);
|
||||
|
|
@ -324,10 +322,8 @@ namespace UniGLTF
|
|||
|
||||
foreach (var (key, animation) in AnimationClips.ToArray())
|
||||
{
|
||||
if (take(key, animation))
|
||||
{
|
||||
AnimationClips.Remove((key, animation));
|
||||
}
|
||||
take(key, animation);
|
||||
AnimationClips.Remove((key, animation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ namespace UniGLTF
|
|||
context.TransferOwnership((k, o) =>
|
||||
{
|
||||
loaded.m_resources.Add((k, o));
|
||||
return true;
|
||||
});
|
||||
return loaded;
|
||||
}
|
||||
|
|
@ -49,10 +48,8 @@ namespace UniGLTF
|
|||
{
|
||||
foreach (var (key, x) in m_resources.ToArray())
|
||||
{
|
||||
if (take(key, x))
|
||||
{
|
||||
m_resources.Remove((key, x));
|
||||
}
|
||||
take(key, x);
|
||||
m_resources.Remove((key, x));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,36 +108,25 @@ namespace VRM
|
|||
TextureExtractor.ExtractTextures(m_context.Parser, m_prefabPath.Parent.Child(dirName), m_context.TextureDescriptorGenerator, subAssets, (_x, _y) => { }, onTextureReloaded);
|
||||
}
|
||||
|
||||
bool SaveAsAsset(SubAssetKey _, UnityEngine.Object o)
|
||||
void SaveAsAsset(SubAssetKey _, UnityEngine.Object o)
|
||||
{
|
||||
if (o is GameObject)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(o)))
|
||||
{
|
||||
// already exists. not dispose
|
||||
#if VRM_DEVELOP
|
||||
Debug.Log($"Loaded. skip: {o}");
|
||||
// 来ない?
|
||||
Debug.LogWarning($"{o} already exists. skip write");
|
||||
#endif
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
var assetPath = GetAssetPath(m_prefabPath, o);
|
||||
if (assetPath.IsNull)
|
||||
if (!assetPath.IsNull)
|
||||
{
|
||||
// not dispose
|
||||
return true;
|
||||
// アセットとして書き込む
|
||||
assetPath.Parent.EnsureFolder();
|
||||
assetPath.CreateAsset(o);
|
||||
m_paths.Add(assetPath);
|
||||
}
|
||||
|
||||
// アセットとして書き込む
|
||||
assetPath.Parent.EnsureFolder();
|
||||
assetPath.CreateAsset(o);
|
||||
m_paths.Add(assetPath);
|
||||
|
||||
// 所有権が移動
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SaveAsAsset(UniGLTF.UnityObjectManager loaded)
|
||||
|
|
@ -157,7 +146,6 @@ namespace VRM
|
|||
Debug.LogFormat("replace prefab: {0}", m_prefabPath);
|
||||
var prefab = m_prefabPath.LoadAsset<GameObject>();
|
||||
PrefabUtility.SaveAsPrefabAssetAndConnect(loaded.gameObject, m_prefabPath.Value, InteractionMode.AutomatedAction);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -322,33 +322,25 @@ namespace VRM
|
|||
// VRM-0 は SubAssetKey を使っていないので default で済ます
|
||||
|
||||
// VRM 固有のリソース(ScriptableObject)
|
||||
if (take(default, HumanoidAvatar))
|
||||
{
|
||||
HumanoidAvatar = null;
|
||||
}
|
||||
take(default, HumanoidAvatar);
|
||||
HumanoidAvatar = null;
|
||||
|
||||
if (take(default, Meta))
|
||||
{
|
||||
Meta = null;
|
||||
}
|
||||
take(default, Meta);
|
||||
Meta = null;
|
||||
|
||||
if (take(default, AvatarDescription))
|
||||
{
|
||||
AvatarDescription = null;
|
||||
}
|
||||
take(default, AvatarDescription);
|
||||
AvatarDescription = null;
|
||||
|
||||
foreach (var x in BlendShapeAvatar.Clips)
|
||||
{
|
||||
if (take(default, x))
|
||||
take(default, x);
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (take(default, BlendShapeAvatar))
|
||||
{
|
||||
BlendShapeAvatar = null;
|
||||
}
|
||||
take(default, BlendShapeAvatar);
|
||||
BlendShapeAvatar = null;
|
||||
|
||||
// GLTF のリソース
|
||||
base.TransferOwnership(take);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ namespace UniVRM10
|
|||
loaded.TransferOwnership((key, o) =>
|
||||
{
|
||||
context.AddObjectToAsset(key.Name, o);
|
||||
return true;
|
||||
});
|
||||
|
||||
context.AddObjectToAsset(loaded.name, loaded.gameObject);
|
||||
|
|
|
|||
|
|
@ -621,25 +621,19 @@ namespace UniVRM10
|
|||
public override void TransferOwnership(TakeResponsibilityForDestroyObjectFunc take)
|
||||
{
|
||||
// VRM 固有のリソース(ScriptableObject)
|
||||
if (take(SubAssetKey.Create(m_humanoid), m_humanoid))
|
||||
{
|
||||
m_humanoid = null;
|
||||
}
|
||||
take(SubAssetKey.Create(m_humanoid), m_humanoid);
|
||||
m_humanoid = null;
|
||||
|
||||
if (m_meta != null)
|
||||
{
|
||||
if (take(VRM10MetaObject.SubAssetKey, m_meta))
|
||||
{
|
||||
m_meta = null;
|
||||
}
|
||||
take(VRM10MetaObject.SubAssetKey, m_meta);
|
||||
m_meta = null;
|
||||
}
|
||||
|
||||
foreach (var x in m_expressions)
|
||||
{
|
||||
if (take(ExpressionKey.CreateFromClip(x).SubAssetKey, x))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
take(ExpressionKey.CreateFromClip(x).SubAssetKey, x);
|
||||
// do nothing
|
||||
}
|
||||
m_expressions.Clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ using System;
|
|||
|
||||
namespace VRMShaders
|
||||
{
|
||||
public delegate bool TakeResponsibilityForDestroyObjectFunc(SubAssetKey key, UnityEngine.Object obj);
|
||||
public delegate void TakeResponsibilityForDestroyObjectFunc(SubAssetKey key, UnityEngine.Object obj);
|
||||
|
||||
/// <summary>
|
||||
/// UnityObjectを破棄する責務。
|
||||
|
|
|
|||
|
|
@ -82,22 +82,15 @@ namespace VRMShaders
|
|||
/// <param name="take"></param>
|
||||
public void TransferOwnership(TakeResponsibilityForDestroyObjectFunc take)
|
||||
{
|
||||
var list = new List<Material>();
|
||||
foreach (var x in m_materials)
|
||||
foreach (var x in m_materials.ToArray())
|
||||
{
|
||||
if (!x.UseExternal)
|
||||
{
|
||||
// 外部の '.asset' からロードしていない
|
||||
if (take(x.Key, x.Asset))
|
||||
{
|
||||
list.Add(x.Asset);
|
||||
}
|
||||
take(x.Key, x.Asset);
|
||||
m_materials.Remove(x);
|
||||
}
|
||||
}
|
||||
foreach (var x in list)
|
||||
{
|
||||
Remove(x);
|
||||
}
|
||||
}
|
||||
|
||||
public Material GetMaterial(int index)
|
||||
|
|
|
|||
|
|
@ -45,18 +45,10 @@ namespace VRMShaders
|
|||
/// <param name="take"></param>
|
||||
public void TransferOwnership(TakeResponsibilityForDestroyObjectFunc take)
|
||||
{
|
||||
var transferredAssets = new HashSet<SubAssetKey>();
|
||||
foreach (var (k, v) in _textureCache)
|
||||
foreach (var (k, v) in _textureCache.ToArray())
|
||||
{
|
||||
if (take(k, v))
|
||||
{
|
||||
transferredAssets.Add(k);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var key in transferredAssets)
|
||||
{
|
||||
_textureCache.Remove(key);
|
||||
take(k, v);
|
||||
_textureCache.Remove(k);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user