MOD!
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Continentis.MainGame.UI
|
||||
{
|
||||
public class InformationBox : UIElementBase
|
||||
{
|
||||
public RectTransform mainBox;
|
||||
public Image titleBackground, contentBackground;
|
||||
public TMP_Text titleText, contentText;
|
||||
|
||||
@@ -16,7 +17,6 @@ namespace Continentis.MainGame.UI
|
||||
{
|
||||
titleText.text = title;
|
||||
contentText.text = content;
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
|
||||
SetBackground();
|
||||
}
|
||||
|
||||
@@ -27,21 +27,24 @@ namespace Continentis.MainGame.UI
|
||||
{
|
||||
titleText.text = title;
|
||||
contentText.text = content;
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
|
||||
|
||||
SetBackground();
|
||||
SetPosition(basePosition);
|
||||
}
|
||||
|
||||
private void SetBackground()
|
||||
{
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(mainBox);
|
||||
titleBackground.rectTransform.sizeDelta = new Vector2(0, titleText.preferredHeight + 10);
|
||||
contentBackground.rectTransform.sizeDelta = new Vector2(0, contentText.preferredHeight + 10);
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(mainBox);
|
||||
rectTransform.sizeDelta = mainBox.sizeDelta;
|
||||
}
|
||||
|
||||
private void SetPosition(Vector2 basePosition)
|
||||
{
|
||||
float xOffset = basePosition.x < Screen.width / 2f ? -rectTransform.rect.width / 2 : rectTransform.rect.width / 2;
|
||||
float yOffset = basePosition.y < Screen.height / 2f ? rectTransform.rect.height / 2 : -rectTransform.rect.height / 2;
|
||||
float xOffset = basePosition.x < 0 ? rectTransform.sizeDelta.x / 2 : -rectTransform.sizeDelta.x / 2;
|
||||
float yOffset = basePosition.y < Screen.height * 0.25f ? rectTransform.sizeDelta.y / 2 : -rectTransform.sizeDelta.y / 2;
|
||||
rectTransform.anchoredPosition = new Vector2(basePosition.x + xOffset, basePosition.y + yOffset);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user