Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed Sep 22, 2024
1 parent 7c3165b commit bf69f1b
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion Editor/Configurator/Cabinet/OneConfConfigurableOutfit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
*/

using System.Collections.Generic;
using System.Collections.ObjectModel;
using Chocopoi.DressingFramework.Components;
using Chocopoi.DressingFramework.Detail.DK;
using Chocopoi.DressingTools.Components.OneConf;
using Chocopoi.DressingTools.Configurator.Modules;
using Chocopoi.DressingTools.Dynamics;
using Chocopoi.DressingTools.OneConf;
using Chocopoi.DressingTools.OneConf.Serialization;
using Chocopoi.DressingTools.OneConf.Wearable.Modules;
using Chocopoi.DressingTools.OneConf.Wearable.Modules.BuiltIn;
using Chocopoi.DressingTools.UI.Views;
using UnityEngine;
Expand Down Expand Up @@ -82,7 +87,60 @@ public List<IModule> GetModules()

public void Preview(GameObject previewAvatarGameObject, GameObject previewOutfitGameObject)
{
// throw new System.NotImplementedException();
if (previewAvatarGameObject == null || previewOutfitGameObject == null)
{
return;
}

var cabinet = OneConfUtils.GetAvatarCabinet(previewAvatarGameObject);
if (cabinet == null)
{
return;
}

if (!CabinetConfigUtility.TryDeserialize(cabinet.ConfigJson, out var cabinetConfig))
{
Debug.LogError("[DressingTools] Unable to deserialize cabinet config for preview");
return;
}

if (!WearableConfigUtility.TryDeserialize(_wearableComp.ConfigJson, out var wearableConfig))
{
Debug.LogError("[DressingTools] Unable to deserialize OneConf wearable config for preview");
return;
}

var dkCtx = new DKNativeContext(previewAvatarGameObject);
var cabCtx = new CabinetContext
{
dkCtx = dkCtx,
cabinetConfig = cabinetConfig
};

var wearCtx = new WearableContext
{
wearableConfig = wearableConfig,
wearableGameObject = previewOutfitGameObject,
wearableDynamics = DynamicsUtils.ScanDynamics(previewOutfitGameObject)
};

var providers = ModuleManager.Instance.GetAllWearableModuleProviders();

foreach (var provider in providers)
{
if (!provider.Invoke(cabCtx, wearCtx, new ReadOnlyCollection<WearableModule>(wearableConfig.FindModules(provider.Identifier)), true))
{
Debug.LogError("[DressingTools] Error applying wearable in preview!");
break;
}
}

// remove all DK components
var dkComps = previewAvatarGameObject.GetComponentsInChildren<DKBaseComponent>();
foreach (var comp in dkComps)
{
Object.DestroyImmediate(comp);
}
}
}
}

0 comments on commit bf69f1b

Please sign in to comment.