Made the moving windows move

This commit is contained in:
2026-01-14 19:43:20 +00:00
parent 0c43fc1112
commit f10d0bf7ca
7 changed files with 95 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
using System;
using UnityEngine;
namespace InterfaceOff
@@ -6,6 +7,8 @@ namespace InterfaceOff
{
public WindowInteractions Interactions { get; set; }
public WindowComponents Components { get; set; }
protected Vector2 Velocity;
public void InstantiateWindowBase()
{
@@ -14,6 +17,42 @@ namespace InterfaceOff
OnWindowInstantiation();
}
protected void LateUpdate()
{
/* Moves the component and calculates new position and half size(s) */
Components.RectTransform.anchoredPosition += Velocity * Time.deltaTime;
Vector2 position = Components.RectTransform.anchoredPosition;
Vector2 hCanvasSize = CanvasManager.Instance.CanvasRect.sizeDelta * 0.5f;
Vector2 hSize = Components.RectTransform.sizeDelta * 0.5f;
/* Calculates outcome of a horizontal bounce (if there is one) */
if (position.x + hSize.x > hCanvasSize.x || position.x - hSize.x < -hCanvasSize.x)
{
Velocity.x *= -1f; // Inverts X velocity
position.x = Math.Clamp
(
position.x,
0 - hCanvasSize.x + hSize.x,
0 + hCanvasSize.x - hSize.x
);
}
/* Calculates outcome of vertical bounce (if there is one) */
if (position.y + hSize.y > hCanvasSize.y || position.y - hSize.y < -hCanvasSize.y)
{
Velocity.y *= -1f; // Inverts Y velocity
position.y = Math.Clamp
(
position.y,
0 - hCanvasSize.y + hSize.y,
0 + hCanvasSize.y - hSize.y
);
}
Components.RectTransform.anchoredPosition = position; // Updates position if it is supposed to] change
}
public virtual void OnWindowInstantiation() { }
public virtual void OnWindowClicked() { }
}