修复侧边栏UI的布局计算bug(当有子菜单存在时,任意菜单项发生visible变化重新布局的位置计算错误)

This commit is contained in:
ALIENJACK\alien 2025-08-20 10:49:49 +08:00
parent 09407468c2
commit 31ca1b9571
2 changed files with 31 additions and 31 deletions

View File

@ -92,27 +92,18 @@ namespace AxibugEmuOnline.Client
{ {
Canvas.ForceUpdateCanvases(); Canvas.ForceUpdateCanvases();
var topParent = FindTopOptionUI();
var totalWidth = GetTotalWidth(topParent);
Vector2 end = new Vector2(-totalWidth, MenuRoot.anchoredPosition.y);
if (m_popTween != null) if (m_popTween != null)
{ {
Vector2 end = new Vector2(-MenuRoot.rect.width, MenuRoot.anchoredPosition.y);
m_popTween.ChangeEndValue(end, false); m_popTween.ChangeEndValue(end, false);
} }
else else
{ {
Vector2 end = new Vector2(-MenuRoot.rect.width, MenuRoot.anchoredPosition.y); topParent.MenuRoot.anchoredPosition = end;
var topParent = m_parent;
while (topParent != null && topParent.m_parent != null)
{
topParent = topParent.m_parent;
}
if (topParent != null)
{
topParent.MenuRoot.anchoredPosition = end;
}
else
{
MenuRoot.anchoredPosition = end;
}
} }
RebuildSelectIndex(); RebuildSelectIndex();
} }
@ -223,7 +214,6 @@ namespace AxibugEmuOnline.Client
if (!m_bPoped) if (!m_bPoped)
{ {
m_bPoped = true; m_bPoped = true;
Vector2 start = new Vector2(0, MenuRoot.anchoredPosition.y); Vector2 start = new Vector2(0, MenuRoot.anchoredPosition.y);
Vector2 end = new Vector2(-MenuRoot.rect.width, MenuRoot.anchoredPosition.y); Vector2 end = new Vector2(-MenuRoot.rect.width, MenuRoot.anchoredPosition.y);
@ -234,19 +224,8 @@ namespace AxibugEmuOnline.Client
var moveDelta = value - start; var moveDelta = value - start;
start = value; start = value;
var topParent = m_parent; var topParent = FindTopOptionUI();
while (topParent != null && topParent.m_parent != null) topParent.MenuRoot.anchoredPosition += moveDelta;
{
topParent = topParent.m_parent;
}
if (topParent != null)
{
topParent.MenuRoot.anchoredPosition += moveDelta;
}
else
{
MenuRoot.anchoredPosition += moveDelta;
}
}, },
end, end,
0.3f 0.3f
@ -256,7 +235,30 @@ namespace AxibugEmuOnline.Client
m_lastCS = CommandDispatcher.Instance.Mode; m_lastCS = CommandDispatcher.Instance.Mode;
CommandDispatcher.Instance.Mode = CommandListener.ScheduleType.Normal; CommandDispatcher.Instance.Mode = CommandListener.ScheduleType.Normal;
} }
}
OptionUI FindTopOptionUI()
{
if (m_parent == null) return this;
var topParent = m_parent;
while (topParent != null && topParent.m_parent != null)
{
topParent = topParent.m_parent;
}
return topParent;
}
static float GetTotalWidth(OptionUI root)
{
float totalWidth = root.MenuRoot.rect.width;
if (root.m_child != null)
{
totalWidth += GetTotalWidth(root.m_child);
}
return totalWidth;
} }
/// <summary> /// <summary>

View File

@ -21,8 +21,6 @@ namespace AxibugEmuOnline.Client
get => m_target; get => m_target;
set set
{ {
if (m_target == value) return;
m_target = value; m_target = value;
if (m_target == null) if (m_target == null)
{ {