Story排版
This commit is contained in:
@@ -38,6 +38,8 @@ namespace Ichni.Story.UI
|
||||
|
||||
Vector2 startPosition = GetLocalPoint(startBlock.outPort, selfRect, uiCamera);
|
||||
Vector2 endPosition = GetLocalPoint(endBlock.inPort, selfRect, uiCamera);
|
||||
Vector2 startBlockCenter = GetLocalRectCenter(startBlock.blockRect, selfRect, uiCamera);
|
||||
Vector2 endBlockCenter = GetLocalRectCenter(endBlock.blockRect, selfRect, uiCamera);
|
||||
|
||||
if (Vector2.Distance(startPosition, endPosition) < DegenerateDistanceThreshold)
|
||||
{
|
||||
@@ -47,7 +49,10 @@ namespace Ichni.Story.UI
|
||||
}
|
||||
|
||||
// 两个控制点构成 S 形:先水平离开起点,再水平进入终点。
|
||||
float midX = (startPosition.x + endPosition.x) / 2f;
|
||||
// 转折列取两个 Block 的逻辑中心中点,而不是两个端口的中点。
|
||||
// 这样当目标 Block 的宽度不同(例如 Important 与 Secondary)但位于同一列时,
|
||||
// 连接线仍会在同一条竖线转折;尺寸差异只影响端口到转折列的水平线长度。
|
||||
float midX = (startBlockCenter.x + endBlockCenter.x) * 0.5f;
|
||||
Vector2 mid1 = new Vector2(midX, startPosition.y);
|
||||
Vector2 mid2 = new Vector2(midX, endPosition.y);
|
||||
|
||||
@@ -66,6 +71,19 @@ namespace Ichni.Story.UI
|
||||
return localPoint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将任意 RectTransform 的视觉中心转换为连接线容器的局部坐标。
|
||||
/// 使用 rect.center 而非 transform.position,因此不依赖 Block Prefab 自身的 Pivot 配置;
|
||||
/// StoryBlockView 运行时统一为中心 Pivot 后,仍可安全用于未来的任意尺寸 Block。
|
||||
/// </summary>
|
||||
private static Vector2 GetLocalRectCenter(RectTransform rect, RectTransform space, Camera uiCamera)
|
||||
{
|
||||
Vector3 worldCenter = rect.TransformPoint(rect.rect.center);
|
||||
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(uiCamera, worldCenter);
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(space, screenPoint, uiCamera, out Vector2 localPoint);
|
||||
return localPoint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析用于坐标转换的相机:Overlay 画布返回 null,其余(ScreenSpaceCamera / WorldSpace)返回画布相机。
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user