载具养成-科技树生成规则修改 修复科技树生成错位
parent
17842a4869
commit
e50f5959fd
|
|
@ -187,6 +187,11 @@ public class VehicleTreeManager : TreeEditorManager
|
|||
var _tree = GetSampleTree(list);
|
||||
TreeHelpers<Node>.CalculateNodePositions(_tree);
|
||||
PrintPos(_tree);
|
||||
|
||||
if (treeContent == TreeContent.Vehicle)
|
||||
{
|
||||
AdjustVehicleTreePosition(treeGameObject);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -205,6 +210,33 @@ public class VehicleTreeManager : TreeEditorManager
|
|||
root.tile.SetActive(false);
|
||||
DrawLine<GameObject>(m_shownTree);
|
||||
}
|
||||
|
||||
private void AdjustVehicleTreePosition(GameObject treeGameObject)
|
||||
{
|
||||
var maxY = nodes.Values.
|
||||
Where(p => p.tile != null && !ReferenceEquals(p, root)).
|
||||
Max(p => p.tile.GetComponent<RectTransform>().anchoredPosition.y);
|
||||
var minY = nodes.Values.
|
||||
Where(p => p.tile != null && !ReferenceEquals(p, root)).
|
||||
Min(p => p.tile.GetComponent<RectTransform>().anchoredPosition.y);
|
||||
var minX = nodes.Values.
|
||||
Where(p => p.tile != null && !ReferenceEquals(p, root)).
|
||||
Min(p => p.tile.GetComponent<RectTransform>().anchoredPosition.x);
|
||||
|
||||
// 计算偏移量
|
||||
Vector2 offset = new Vector2(273f - minX, -462 - 0.5f * (minY + maxY));
|
||||
|
||||
// 移动所有节点
|
||||
foreach (var node in nodes.Values)
|
||||
{
|
||||
if (node.tile != null)
|
||||
{
|
||||
RectTransform rectTransform = node.tile.GetComponent<RectTransform>();
|
||||
rectTransform.anchoredPosition += offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调整组件树位置,使根节点位于指定位置
|
||||
/// </summary>
|
||||
|
|
@ -873,13 +905,44 @@ public class VehicleTreeManager : TreeEditorManager
|
|||
lineRenderer.SetPoints(points);
|
||||
DebugUtil.Log("Drawing lines. Points count: " + points.Count);
|
||||
|
||||
// 计算树的总尺寸以适配视图
|
||||
var maxY = nodes.Values.Where(p => p.tile != null).Max(p => p.tile.GetComponent<RectTransform>().anchoredPosition.y + p.tile.GetComponent<RectTransform>().sizeDelta.y);
|
||||
var minY = nodes.Values.Where(p => p.tile != null).Min(p => p.tile.GetComponent<RectTransform>().anchoredPosition.y - p.tile.GetComponent<RectTransform>().sizeDelta.y);
|
||||
height = maxY - minY;
|
||||
var maxX = nodes.Values.Where(p => p.tile != null).Max(p => p.tile.GetComponent<RectTransform>().anchoredPosition.x + p.tile.GetComponent<RectTransform>().sizeDelta.x);
|
||||
var minX = nodes.Values.Where(p => p.tile != null).Min(p => p.tile.GetComponent<RectTransform>().anchoredPosition.x - p.tile.GetComponent<RectTransform>().sizeDelta.x);
|
||||
width = maxX - minX;
|
||||
if (treeContent == TreeContent.Component)
|
||||
{
|
||||
// 计算树的总尺寸以适配视图
|
||||
var maxY = nodes.Values.
|
||||
Where(p => p.tile != null).
|
||||
Max(p => p.tile.GetComponent<RectTransform>().anchoredPosition.y + p.tile.GetComponent<RectTransform>().sizeDelta.y);
|
||||
var minY = nodes.Values.
|
||||
Where(p => p.tile != null).
|
||||
Min(p => p.tile.GetComponent<RectTransform>().anchoredPosition.y - p.tile.GetComponent<RectTransform>().sizeDelta.y);
|
||||
var maxX = nodes.Values.
|
||||
Where(p => p.tile != null).
|
||||
Max(p => p.tile.GetComponent<RectTransform>().anchoredPosition.x + p.tile.GetComponent<RectTransform>().sizeDelta.x);
|
||||
var minX = nodes.Values.
|
||||
Where(p => p.tile != null).
|
||||
Min(p => p.tile.GetComponent<RectTransform>().anchoredPosition.x - p.tile.GetComponent<RectTransform>().sizeDelta.x);
|
||||
|
||||
height = maxY - minY;
|
||||
width = maxX - minX;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 计算树的总尺寸以适配视图
|
||||
var maxY = nodes.Values.
|
||||
Where(p => p.tile != null && !ReferenceEquals(p, root)).
|
||||
Max(p => p.tile.GetComponent<RectTransform>().anchoredPosition.y + 0.5f * p.tile.GetComponent<RectTransform>().sizeDelta.y);
|
||||
var minY = nodes.Values.
|
||||
Where(p => p.tile != null &&!ReferenceEquals(p, root)).
|
||||
Min(p => p.tile.GetComponent<RectTransform>().anchoredPosition.y - 0.5f * p.tile.GetComponent<RectTransform>().sizeDelta.y);
|
||||
var maxX = nodes.Values.
|
||||
Where(p => p.tile != null && !ReferenceEquals(p, root)).
|
||||
Max(p => p.tile.GetComponent<RectTransform>().anchoredPosition.x + 0.5f * p.tile.GetComponent<RectTransform>().sizeDelta.x);
|
||||
var minX = nodes.Values.
|
||||
Where(p => p.tile != null && !ReferenceEquals(p, root)).
|
||||
Min(p => p.tile.GetComponent<RectTransform>().anchoredPosition.x - 0.5f * p.tile.GetComponent<RectTransform>().sizeDelta.x);
|
||||
|
||||
height = maxY - minY;
|
||||
width = maxX - minX + 30f;
|
||||
}
|
||||
|
||||
m_shownTree.GetComponent<RectTransform>().sizeDelta = new Vector2(width + 100, height + 100);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue