Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed Oct 18, 2024
1 parent f4dbabd commit 228d6a9
Show file tree
Hide file tree
Showing 95 changed files with 2,122 additions and 2,920 deletions.
8 changes: 8 additions & 0 deletions Editor/Configurator.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/Configurator/Avatar.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions Editor/Configurator/Avatar/AvatarUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2024 chocopoi
*
* This file is part of DressingTools.
*
* DressingTools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* DressingTools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DressingFramework. If not, see <https://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using Chocopoi.DressingFramework;
using Chocopoi.DressingTools.Components.Cabinet;
using Chocopoi.DressingTools.Components.OneConf;
using Chocopoi.DressingTools.Configurator.Cabinet;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Chocopoi.DressingTools.Configurator.Avatar
{
internal static class AvatarUtils
{
public static List<GameObject> FindSceneAvatars(Scene scene)
{
return DKRuntimeUtils.FindSceneAvatars(scene);
}

public static GameObject GetAvatarRoot(GameObject gameObject)
{
return DKRuntimeUtils.GetAvatarRoot(gameObject);
}

public static IAvatarSettings GetAvatarSettings(GameObject avatarGameObject)
{
if (avatarGameObject == null)
{
return null;
}

if (avatarGameObject.TryGetComponent<DTCabinet>(out _))
{
return new OneConfAvatarSettings(avatarGameObject);
}
// TODO: standalone avatar settings component
return null;
}

public static IWardrobeProvider GetWardrobeProvider(GameObject avatarGameObject)
{
if (avatarGameObject == null)
{
return null;
}

if (avatarGameObject.TryGetComponent<DTCabinet>(out _))
{
return new OneConfCabinetProvider(avatarGameObject);
}
// if (avatarGameObject.TryGetComponent<DTWardrobe>(out _))
// {
// return new DTWardrobeProvider(avatarGameObject);
// }
return null;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Editor/Configurator/Avatar/IAvatarSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 chocopoi
*
* This file is part of DressingTools.
*
* DressingTools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* DressingTools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DressingFramework. If not, see <https://www.gnu.org/licenses/>.
*/

using UnityEngine;

namespace Chocopoi.DressingTools.Configurator.Avatar
{
internal enum WriteDefaultsModes
{
Auto = 0,
On = 1,
Off = 2
}

internal interface IAvatarSettings
{
WriteDefaultsModes WriteDefaultsMode { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions Editor/Configurator/Avatar/OneConfAvatarSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2024 chocopoi
*
* This file is part of DressingTools.
*
* DressingTools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* DressingTools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DressingFramework. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using Chocopoi.DressingTools.Components.OneConf;
using Chocopoi.DressingTools.OneConf.Cabinet;
using Chocopoi.DressingTools.OneConf.Serialization;
using UnityEngine;

namespace Chocopoi.DressingTools.Configurator.Avatar
{
internal class OneConfAvatarSettings : IAvatarSettings
{
public WriteDefaultsModes WriteDefaultsMode
{
get
{
ReadCabinetConfig(out _, out var config);
// TODO: should explicit convert them one by one
return (WriteDefaultsModes)config.animationWriteDefaultsMode;
}
set
{
WriteCabinetConfig((comp, config) =>
{
// TODO: should explicit convert them one by one
config.animationWriteDefaultsMode = (CabinetConfig.WriteDefaultsMode)value;
});
}
}

private readonly GameObject _avatarGameObject;

public OneConfAvatarSettings(GameObject avatarGameObject)
{
_avatarGameObject = avatarGameObject;
}

private void ReadCabinetConfig(out DTCabinet comp, out CabinetConfig config)
{
if (_avatarGameObject.TryGetComponent(out comp))
{
if (!CabinetConfigUtility.TryDeserialize(comp.ConfigJson, out config))
{
config = new CabinetConfig();
}
}
else
{
comp = null;
config = new CabinetConfig();
}
}

private void WriteCabinetConfig(Action<DTCabinet, CabinetConfig> func)
{
CabinetConfig config;
if (_avatarGameObject.TryGetComponent<DTCabinet>(out var cabinetComp))
{
if (!CabinetConfigUtility.TryDeserialize(cabinetComp.ConfigJson, out config))
{
config = new CabinetConfig();
}
}
else
{
cabinetComp = _avatarGameObject.AddComponent<DTCabinet>();
config = new CabinetConfig();
}
func?.Invoke(cabinetComp, config);
cabinetComp.ConfigJson = CabinetConfigUtility.Serialize(config);
}
}
}
11 changes: 11 additions & 0 deletions Editor/Configurator/Avatar/OneConfAvatarSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions Editor/Configurator/AvatarPreviewUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2024 chocopoi
*
* This file is part of DressingTools.
*
* DressingTools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* DressingTools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DressingFramework. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using Chocopoi.DressingFramework;
using Chocopoi.DressingTools.Configurator.Cabinet;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Chocopoi.DressingTools.Configurator
{
internal static class AvatarPreviewUtility
{
#if UNITY_2020_1_OR_NEWER
private class AvatarPreviewStage : PreviewSceneStage
{
public GameObject avatarGameObject;
public IConfigurableOutfit outfit;

private GameObject _previewAvatarGameObject;
private GameObject _previewOutfitGameObject;

protected override GUIContent CreateHeaderContent()
{
return new GUIContent("DressingTools Preview");
}

private void PrepareAvatarPreview()
{
var lighting = new GameObject("Lighting");
lighting.AddComponent<Light>().type = LightType.Directional;
SceneManager.MoveGameObjectToScene(lighting, scene);

_previewAvatarGameObject = Instantiate(avatarGameObject);
_previewAvatarGameObject.name = avatarGameObject.name;
if (DKEditorUtils.IsGrandParent(_previewAvatarGameObject.transform, outfit.RootTransform))
{
// if it's inside, reuse it
var path = DKEditorUtils.GetRelativePath(outfit.RootTransform, _previewAvatarGameObject.transform);
_previewOutfitGameObject = _previewAvatarGameObject.transform.Find(path).gameObject;
}
else
{
// if it's outside, create a new one and set parent
_previewOutfitGameObject = Instantiate(outfit.RootTransform.gameObject);
_previewOutfitGameObject.name = outfit.RootTransform.name;
_previewOutfitGameObject.transform.SetParent(_previewAvatarGameObject.transform, false);
}
outfit.Preview(_previewAvatarGameObject, _previewOutfitGameObject);
SceneManager.MoveGameObjectToScene(_previewAvatarGameObject, scene);
}

protected override bool OnOpenStage()
{
base.OnOpenStage();
scene = EditorSceneManager.NewPreviewScene();
PrepareAvatarPreview();
return true;
}

protected override void OnCloseStage()
{
foreach (var go in scene.GetRootGameObjects())
{
DestroyImmediate(go);
}
EditorSceneManager.ClosePreviewScene(scene);
base.OnCloseStage();
}
}
#endif

public static void StartAvatarPreview(GameObject avatarGameObject, IConfigurableOutfit outfit, bool legacy = false)
{
#if UNITY_2020_1_OR_NEWER
if (!legacy)
{
var stage = ScriptableObject.CreateInstance<AvatarPreviewStage>();
stage.avatarGameObject = avatarGameObject;
stage.outfit = outfit;
StageUtility.GoToStage(stage, true);
return;
}
#endif
throw new NotImplementedException("Legacy preview is not yet implemented.");
}
}
}
11 changes: 11 additions & 0 deletions Editor/Configurator/AvatarPreviewUtility.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/Configurator/Cabinet.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Editor/Configurator/Cabinet/IConfigurableOutfit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 chocopoi
*
* This file is part of DressingTools.
*
* DressingTools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* DressingTools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DressingFramework. If not, see <https://www.gnu.org/licenses/>.
*/

// using System.Collections.Generic;
// using Chocopoi.DressingTools.Configurator.Modules;
using UnityEngine;
using UnityEngine.UIElements;

namespace Chocopoi.DressingTools.Configurator.Cabinet
{
internal interface IConfigurableOutfit
{
Transform RootTransform { get; }
string Name { get; }
Texture2D Icon { get; }

// List<IModule> GetModules();
VisualElement CreateView();
void Preview(GameObject previewAvatarGameObject, GameObject previewOutfitGameObject);
}
}
11 changes: 11 additions & 0 deletions Editor/Configurator/Cabinet/IConfigurableOutfit.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 228d6a9

Please sign in to comment.