Merge pull request 'fix reset camera show face when logout' (#415) from feature/UpdateAvatar into develop

Reviewed-on: https://git.pthub.vn/Unity/perfect-world-unity/pulls/415
This commit is contained in:
cuongnv
2026-05-07 10:30:08 +00:00
3 changed files with 44 additions and 0 deletions
@@ -74,6 +74,7 @@ namespace BrewMonster
private readonly List<Material> _portraitMaterialInstances = new();
private readonly List<RendererSharedMaterialsSnapshot> _previewMaterialRestore = new();
private readonly List<TransformLayerSnapshot> _previewLayerRestore = new();
// Stored while waiting for async model load; -1 means no pending request
private int _pendingRoleId = -1;
@@ -84,6 +85,12 @@ namespace BrewMonster
public Material[] SharedMaterials;
}
private struct TransformLayerSnapshot
{
public Transform Transform;
public int Layer;
}
public RenderTexture OutputTexture => outputTexture;
// ──────────────────────────────────────────────────────────────────────────────
@@ -122,6 +129,7 @@ namespace BrewMonster
{
UnsubscribeModelReady();
RestorePreviewMaterials();
RestorePreviewLayers();
DetachCamera();
if (PlayerModelPreview.Instance == null)
@@ -144,6 +152,7 @@ namespace BrewMonster
public void SetHostPlayer(Transform hostPlayerRoot)
{
RestorePreviewMaterials();
RestorePreviewLayers();
DetachCamera();
if (hostPlayerRoot == null) return;
_modelTransform = hostPlayerRoot;
@@ -158,6 +167,7 @@ namespace BrewMonster
{
UnsubscribeModelReady();
RestorePreviewMaterials();
RestorePreviewLayers();
DetachCamera();
_modelTransform = null;
_headBone = null;
@@ -258,6 +268,7 @@ namespace BrewMonster
}
// Move model to portrait layer so the dedicated camera can render it
CaptureLayersForRestore(_modelTransform.gameObject);
PortraitCaptureUtils.SetLayerRecursive(_modelTransform.gameObject, portraitLayer);
// Find head bone — primary target for camera attachment
@@ -312,6 +323,30 @@ namespace BrewMonster
}
}
private void CaptureLayersForRestore(GameObject root)
{
if (root == null) return;
var transforms = root.GetComponentsInChildren<Transform>(true);
for (int i = 0; i < transforms.Length; i++)
{
var t = transforms[i];
if (t == null) continue;
_previewLayerRestore.Add(new TransformLayerSnapshot { Transform = t, Layer = t.gameObject.layer });
}
}
private void RestorePreviewLayers()
{
for (int i = 0; i < _previewLayerRestore.Count; i++)
{
var snap = _previewLayerRestore[i];
if (snap.Transform != null)
snap.Transform.gameObject.layer = snap.Layer;
}
_previewLayerRestore.Clear();
}
/// <summary>
/// Parents the portrait camera to "Bip01 Head" and sets its initial position
/// directly in front of the face.
@@ -56,6 +56,7 @@ namespace BrewMonster.UI
{
Tech3CSDKWrapper.Instance.SetLoginCallback(OnLoginCallback);
Tech3CSDKWrapper.Instance.SetLogoutCallback(OnLogoutCallback);
HostPlayerPortraitCapture.Instance?.ClearPortrait();
if(PlayerModelPreview.Instance != null)
{
+8
View File
@@ -53,6 +53,13 @@ namespace BrewMonster.UI
private void OnDisable()
{
_btnEnterGame.onClick.RemoveListener(OnClickedEnterGame);
if (_showModelReadyCoroutine != null)
{
StopCoroutine(_showModelReadyCoroutine);
_showModelReadyCoroutine = null;
}
_pendingShowModelRoleId = -1;
HostPlayerPortraitCapture.Instance?.ClearPortrait();
_selectingCharacterItemUI = null;
}
@@ -242,6 +249,7 @@ namespace BrewMonster.UI
private void OnClickedExit()
{
HostPlayerPortraitCapture.Instance?.ClearPortrait();
_onExit?.Invoke();
gameObject.SetActive(false);