Skip to content

Commit cc8e6ee

Browse files
Merge pull request #279 from KisaragiEffective/refactor/object-instantiate
2 parents 564b3cb + 27cb6cc commit cc8e6ee

9 files changed

+34
-41
lines changed

Editor/Transform/AvatarTransformService.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,22 @@ private static GameObject Expand(
5050
bool runNDMF
5151
)
5252
{
53-
// TODO: IPlatformExpanderではない
54-
// TODO: 最初にInstantiateするならはじめっからinstantiateしておいて、modifiableRootを取るようにしたほうがI/F的にはきれいなのでは?
55-
GameObject modifiableRoot = PerformEnvironmentDependantShallowCopy(new Environment.AAO.DisableMeshMerge(), unmodifiableRoot);
53+
var modifiableRoot = Object.Instantiate(unmodifiableRoot);
54+
modifiableRoot = PerformPreprocessor(new Environment.AAO.DisableMeshMerge(), modifiableRoot);
5655

5756
if (runVRCSDKPipeline)
5857
{
59-
modifiableRoot = PerformEnvironmentDependantShallowCopy(new Environment.VRChat.VRChatBuildPipelineExpander(), modifiableRoot);
58+
modifiableRoot = PerformPreprocessor(new Environment.VRChat.VRChatBuildPipelinePreprocessor(), modifiableRoot);
6059
}
6160
else if (runNDMF)
6261
{
63-
modifiableRoot = PerformEnvironmentDependantShallowCopy(new Environment.NDMF.StandaloneNDMFExpander(), modifiableRoot);
64-
}
65-
else
66-
{
67-
modifiableRoot = Object.Instantiate(modifiableRoot);
62+
modifiableRoot = PerformPreprocessor(new Environment.NDMF.StandaloneNDMFPreprocessor(), modifiableRoot);
6863
}
6964

7065
return modifiableRoot;
7166

72-
GameObject PerformEnvironmentDependantShallowCopy(IPlatformExpander handler, GameObject localUnmodifiableRoot) =>
73-
handler.PerformEnvironmentDependantShallowCopy(localUnmodifiableRoot);
67+
GameObject PerformPreprocessor(IPlatformDependantPreprocessor handler, GameObject localUnmodifiableRoot) =>
68+
handler.Preprocess(localUnmodifiableRoot);
7469
}
7570

7671
private static MultipleUnorderedDictionary<LoweredRenderMode, Material>

Editor/Transform/Environment/AAO/DisableMeshMerge.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ namespace KisaragiMarine.ResoniteImportHelper.Transform.Environment.AAO
88
/// <summary>
99
/// UniGLTF に AAO MergeMesh したアバターを食わせるとメッシュが大幅に壊れる現象を回避するためのパス
1010
/// </summary>
11-
public sealed class DisableMeshMerge : IPlatformExpander
11+
public sealed class DisableMeshMerge : IPlatformDependantPreprocessor
1212
{
13-
public GameObject PerformEnvironmentDependantShallowCopy(GameObject unmodifiableRoot)
13+
public GameObject Preprocess(GameObject modifiableRoot)
1414
{
15-
var root = Object.Instantiate(unmodifiableRoot);
16-
17-
var traceAndOptimizeComponents = root.GetComponents<Anatawa12.AvatarOptimizer.TraceAndOptimize>();
15+
var traceAndOptimizeComponents = modifiableRoot.GetComponents<Anatawa12.AvatarOptimizer.TraceAndOptimize>();
1816

1917
foreach (var tao in traceAndOptimizeComponents)
2018
{
@@ -23,12 +21,12 @@ public GameObject PerformEnvironmentDependantShallowCopy(GameObject unmodifiable
2321
handle.ApplyModifiedPropertiesWithoutUndo();
2422
}
2523

26-
foreach (var mergeComponent in root.GetComponents<Anatawa12.AvatarOptimizer.MergeSkinnedMesh>())
24+
foreach (var mergeComponent in modifiableRoot.GetComponents<Anatawa12.AvatarOptimizer.MergeSkinnedMesh>())
2725
{
2826
Object.DestroyImmediate(mergeComponent);
2927
}
3028

31-
return root;
29+
return modifiableRoot;
3230
// var mergeComponents = root.GetComponents<>();
3331
}
3432
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#nullable enable
2+
using UnityEngine;
3+
4+
namespace KisaragiMarine.ResoniteImportHelper.Transform.Environment.Common
5+
{
6+
/// <summary>
7+
/// プラットフォーム依存の方法で<see cref="GameObject"/>に対して変更を加える。
8+
/// </summary>
9+
public interface IPlatformDependantPreprocessor
10+
{
11+
/// <see cref="GameObject.Instantiate(Object)"/> を呼び出すときは必ず適切な後始末をしなければならない。
12+
/// <returns>変更が適用された<see cref="GameObject"/></returns>
13+
public GameObject Preprocess(GameObject modifiableRoot);
14+
}
15+
}

Editor/Transform/Environment/Common/IPlatformExpander.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

Editor/Transform/Environment/NDMF/StandaloneNDMFExpander.cs renamed to Editor/Transform/Environment/NDMF/StandaloneNDMFPreprocessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
namespace KisaragiMarine.ResoniteImportHelper.Transform.Environment.NDMF
99
{
1010
// ReSharper disable once InconsistentNaming
11-
internal class StandaloneNDMFExpander: IPlatformExpander
11+
internal class StandaloneNDMFPreprocessor: IPlatformDependantPreprocessor
1212
{
1313

14-
public GameObject PerformEnvironmentDependantShallowCopy(GameObject unmodifiableRoot)
14+
public GameObject Preprocess(GameObject modifiableRoot)
1515
{
1616
#if RIH_HAS_NDMF
17-
return AvatarProcessor.ProcessAvatarUI(unmodifiableRoot);
17+
return AvatarProcessor.ProcessAvatarUI(modifiableRoot);
1818
#else
1919
throw new ResoniteImportHelper.Transform.Environment.Common.NonEnabledPlatformException();
2020
#endif

Editor/Transform/Environment/VRChat/VRChatBuildPipelineExpander.cs renamed to Editor/Transform/Environment/VRChat/VRChatBuildPipelinePreprocessor.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@
1010

1111
namespace KisaragiMarine.ResoniteImportHelper.Transform.Environment.VRChat
1212
{
13-
internal class VRChatBuildPipelineExpander : IPlatformExpander
13+
internal class VRChatBuildPipelinePreprocessor : IPlatformDependantPreprocessor
1414
{
15-
public GameObject PerformEnvironmentDependantShallowCopy(GameObject unmodifiableRoot)
15+
public GameObject Preprocess(GameObject modifiableRoot)
1616
{
1717
#if RIH_HAS_VRCSDK3A
18-
if (!unmodifiableRoot.TryGetComponent<VRCAvatarDescriptor>(out _))
18+
if (!modifiableRoot.TryGetComponent<VRCAvatarDescriptor>(out _))
1919
{
2020
throw new Exception("specified object does not have VRChat Avatar Descriptor.");
2121
}
2222

23-
var cloned = Object.Instantiate(unmodifiableRoot);
24-
25-
VRCBuildPipelineCallbacks.OnPreprocessAvatar(cloned);
26-
return cloned;
23+
VRCBuildPipelineCallbacks.OnPreprocessAvatar(modifiableRoot);
24+
return modifiableRoot;
2725
#else
2826
throw new ResoniteImportHelper.Transform.Environment.Common.NonEnabledPlatformException();
2927
#endif

0 commit comments

Comments
 (0)