Fix : 옷 변경 최적화 로직 추가
This commit is contained in:
parent
860be78b34
commit
c92b7af0a6
@ -92,22 +92,27 @@ public class AvatarOutfitController : MonoBehaviour, IController
|
|||||||
[Header("Transform Effect (이 의상으로 변경할 때 재생)")]
|
[Header("Transform Effect (이 의상으로 변경할 때 재생)")]
|
||||||
public TransformEffectSettings transformEffect = new TransformEffectSettings();
|
public TransformEffectSettings transformEffect = new TransformEffectSettings();
|
||||||
|
|
||||||
|
// NiloToon renderCharacter 경로는 GameObject 를 Active 로 유지하기 때문에
|
||||||
|
// 하위 MagicaCloth / SkinnedMeshRenderer 가 계속 시뮬+스키닝을 돈다.
|
||||||
|
// 1회 수집 후 Apply/Remove 에서 .enabled 로 함께 토글.
|
||||||
|
[NonSerialized] private SkinnedMeshRenderer[][] _clothingSmrCache;
|
||||||
|
[NonSerialized] private SkinnedMeshRenderer[][] _hideSmrCache;
|
||||||
#if MAGICACLOTH2
|
#if MAGICACLOTH2
|
||||||
// NiloToon renderCharacter 토글 시 GameObject 가 Active 유지되어 MagicaCloth 가 계속 시뮬되는 문제 방지.
|
[NonSerialized] private MagicaCloth[][] _clothingClothCache;
|
||||||
// BuildSimulationCache 로 1회 수집 후 Apply/Remove 에서 cloth.enabled 토글.
|
[NonSerialized] private MagicaCloth[][] _hideClothCache;
|
||||||
[NonSerialized] private MagicaCloth[][] _clothingSimCache;
|
|
||||||
[NonSerialized] private MagicaCloth[][] _hideSimCache;
|
|
||||||
[NonSerialized] private bool _simCacheBuilt;
|
|
||||||
#endif
|
#endif
|
||||||
|
[NonSerialized] private bool _simCacheBuilt;
|
||||||
|
|
||||||
public void BuildSimulationCache()
|
public void BuildSimulationCache()
|
||||||
{
|
{
|
||||||
#if MAGICACLOTH2
|
|
||||||
if (_simCacheBuilt) return;
|
if (_simCacheBuilt) return;
|
||||||
_clothingSimCache = CollectCloths(clothingObjects);
|
_clothingSmrCache = CollectChildren<SkinnedMeshRenderer>(clothingObjects);
|
||||||
_hideSimCache = CollectCloths(hideObjects);
|
_hideSmrCache = CollectChildren<SkinnedMeshRenderer>(hideObjects);
|
||||||
_simCacheBuilt = true;
|
#if MAGICACLOTH2
|
||||||
|
_clothingClothCache = CollectChildren<MagicaCloth>(clothingObjects);
|
||||||
|
_hideClothCache = CollectChildren<MagicaCloth>(hideObjects);
|
||||||
#endif
|
#endif
|
||||||
|
_simCacheBuilt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ApplyOutfit()
|
public void ApplyOutfit()
|
||||||
@ -127,13 +132,18 @@ public class AvatarOutfitController : MonoBehaviour, IController
|
|||||||
void ApplyArrayState(GameObject[] objs, bool value, bool clothingSide)
|
void ApplyArrayState(GameObject[] objs, bool value, bool clothingSide)
|
||||||
{
|
{
|
||||||
if (objs == null) return;
|
if (objs == null) return;
|
||||||
|
var smrCache = clothingSide ? _clothingSmrCache : _hideSmrCache;
|
||||||
|
#if MAGICACLOTH2
|
||||||
|
var clothCache = clothingSide ? _clothingClothCache : _hideClothCache;
|
||||||
|
#endif
|
||||||
for (int i = 0; i < objs.Length; i++)
|
for (int i = 0; i < objs.Length; i++)
|
||||||
{
|
{
|
||||||
SetRenderOrActive(objs[i], value);
|
SetRenderOrActive(objs[i], value);
|
||||||
|
if (smrCache != null && i < smrCache.Length)
|
||||||
|
SetRenderersEnabled(smrCache[i], value);
|
||||||
#if MAGICACLOTH2
|
#if MAGICACLOTH2
|
||||||
var cache = clothingSide ? _clothingSimCache : _hideSimCache;
|
if (clothCache != null && i < clothCache.Length)
|
||||||
if (cache != null && i < cache.Length)
|
SetBehavioursEnabled(clothCache[i], value);
|
||||||
SetClothsEnabled(cache[i], value);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,28 +178,36 @@ public class AvatarOutfitController : MonoBehaviour, IController
|
|||||||
obj.SetActive(value);
|
obj.SetActive(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MAGICACLOTH2
|
static T[][] CollectChildren<T>(GameObject[] objs) where T : Component
|
||||||
static MagicaCloth[][] CollectCloths(GameObject[] objs)
|
|
||||||
{
|
{
|
||||||
if (objs == null) return Array.Empty<MagicaCloth[]>();
|
if (objs == null) return Array.Empty<T[]>();
|
||||||
var arr = new MagicaCloth[objs.Length][];
|
var arr = new T[objs.Length][];
|
||||||
for (int i = 0; i < objs.Length; i++)
|
for (int i = 0; i < objs.Length; i++)
|
||||||
arr[i] = objs[i] != null
|
arr[i] = objs[i] != null
|
||||||
? objs[i].GetComponentsInChildren<MagicaCloth>(true)
|
? objs[i].GetComponentsInChildren<T>(true)
|
||||||
: Array.Empty<MagicaCloth>();
|
: Array.Empty<T>();
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetClothsEnabled(MagicaCloth[] cloths, bool value)
|
static void SetBehavioursEnabled<T>(T[] behaviours, bool value) where T : Behaviour
|
||||||
{
|
{
|
||||||
if (cloths == null) return;
|
if (behaviours == null) return;
|
||||||
foreach (var cloth in cloths)
|
foreach (var b in behaviours)
|
||||||
{
|
{
|
||||||
if (cloth != null && cloth.enabled != value)
|
if (b != null && b.enabled != value)
|
||||||
cloth.enabled = value;
|
b.enabled = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SetRenderersEnabled<T>(T[] renderers, bool value) where T : Renderer
|
||||||
|
{
|
||||||
|
if (renderers == null) return;
|
||||||
|
foreach (var r in renderers)
|
||||||
|
{
|
||||||
|
if (r != null && r.enabled != value)
|
||||||
|
r.enabled = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user