-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
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.
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); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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."); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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.Cabinet | ||
{ | ||
internal class DTBaseOutfitProvider : IBaseOutfitProvider | ||
{ | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.