mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-16 00:07:52 +08:00
Cleanup, use Time.realTimeSinceStartup instead of Time.time, add some stuff
This commit is contained in:
@ -54,10 +54,10 @@ namespace UnityExplorer.UI.Panels
|
||||
if (value.Length == UIManager.MAX_INPUTFIELD_CHARS)
|
||||
ExplorerCore.LogWarning($"Reached maximum InputField character length! ({UIManager.MAX_INPUTFIELD_CHARS})");
|
||||
|
||||
if (Time.time <= m_timeOfLastInputInvoke)
|
||||
if (m_timeOfLastInputInvoke.OccuredEarlierThanDefault())
|
||||
return;
|
||||
|
||||
m_timeOfLastInputInvoke = Time.time;
|
||||
m_timeOfLastInputInvoke = Time.realtimeSinceStartup;
|
||||
OnInputChanged?.Invoke(value);
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ namespace UnityExplorer.UI.Panels
|
||||
public override void SetDefaultPosAndAnchors()
|
||||
{
|
||||
mainPanelRect.localPosition = Vector2.zero;
|
||||
mainPanelRect.pivot = new Vector2(0.5f, 0.5f);
|
||||
mainPanelRect.pivot = new Vector2(0f, 1f);
|
||||
mainPanelRect.anchorMin = new Vector2(0.5f, 0);
|
||||
mainPanelRect.anchorMax = new Vector2(0.5f, 1);
|
||||
mainPanelRect.offsetMin = new Vector2(mainPanelRect.offsetMin.x, 100); // bottom
|
||||
|
@ -29,6 +29,7 @@ namespace UnityExplorer.UI.Panels
|
||||
public RectTransform ContentRect;
|
||||
|
||||
public static float CurrentPanelWidth => Instance.mainPanelRect.rect.width;
|
||||
public static float CurrentPanelHeight => Instance.mainPanelRect.rect.height;
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
@ -57,9 +58,9 @@ namespace UnityExplorer.UI.Panels
|
||||
public override void SetDefaultPosAndAnchors()
|
||||
{
|
||||
mainPanelRect.localPosition = Vector2.zero;
|
||||
mainPanelRect.pivot = new Vector2(0.5f, 0.5f);
|
||||
mainPanelRect.anchorMin = new Vector2(0.5f, 0);
|
||||
mainPanelRect.anchorMax = new Vector2(0.5f, 1);
|
||||
mainPanelRect.pivot = new Vector2(0f, 1f);
|
||||
mainPanelRect.anchorMin = new Vector2(0.1f, 0.15f);
|
||||
mainPanelRect.anchorMax = new Vector2(0.1f, 0.95f);
|
||||
mainPanelRect.offsetMin = new Vector2(mainPanelRect.offsetMin.x, 100); // bottom
|
||||
mainPanelRect.offsetMax = new Vector2(mainPanelRect.offsetMax.x, -50); // top
|
||||
mainPanelRect.sizeDelta = new Vector2(700f, mainPanelRect.sizeDelta.y);
|
||||
|
@ -98,13 +98,17 @@ namespace UnityExplorer.UI.Panels
|
||||
public override void SetDefaultPosAndAnchors()
|
||||
{
|
||||
mainPanelRect.localPosition = Vector2.zero;
|
||||
mainPanelRect.anchorMin = Vector3.zero;
|
||||
mainPanelRect.anchorMax = new Vector2(0, 1);
|
||||
mainPanelRect.sizeDelta = new Vector2(320f, mainPanelRect.sizeDelta.y);
|
||||
mainPanelRect.anchoredPosition = new Vector2(200, 0);
|
||||
mainPanelRect.offsetMin = new Vector2(mainPanelRect.offsetMin.x, 100); // bottom
|
||||
mainPanelRect.offsetMax = new Vector2(mainPanelRect.offsetMax.x, -50); // top
|
||||
mainPanelRect.pivot = new Vector2(0.5f, 0.5f);
|
||||
mainPanelRect.pivot = new Vector2(0f, 1f);
|
||||
mainPanelRect.anchorMin = new Vector2(0.1f, 0.2f);
|
||||
mainPanelRect.anchorMax = new Vector2(0.25f, 0.9f);
|
||||
|
||||
|
||||
//mainPanelRect.anchorMin = Vector3.zero;
|
||||
//mainPanelRect.anchorMax = new Vector2(0, 1);
|
||||
//mainPanelRect.sizeDelta = new Vector2(320f, mainPanelRect.sizeDelta.y);
|
||||
//mainPanelRect.anchoredPosition = new Vector2(200, 0);
|
||||
//mainPanelRect.offsetMin = new Vector2(mainPanelRect.offsetMin.x, 100); // bottom
|
||||
//mainPanelRect.offsetMax = new Vector2(mainPanelRect.offsetMax.x, -50); // top
|
||||
}
|
||||
|
||||
public override void ConstructPanelContent()
|
||||
|
@ -15,6 +15,8 @@ namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
#region Static
|
||||
|
||||
public static bool Resizing { get; private set; }
|
||||
|
||||
internal static List<PanelDragger> Instances = new List<PanelDragger>();
|
||||
|
||||
static PanelDragger()
|
||||
@ -86,7 +88,7 @@ namespace UnityExplorer.UI.Panels
|
||||
// Dragging
|
||||
public RectTransform DragableArea { get; set; }
|
||||
public bool WasDragging { get; set; }
|
||||
private Vector3 m_lastDragPosition;
|
||||
private Vector2 m_lastDragPosition;
|
||||
|
||||
// Resizing
|
||||
private const int RESIZE_THICKNESS = 10;
|
||||
@ -132,7 +134,8 @@ namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
ResizeTypes type;
|
||||
Vector3 resizePos = Panel.InverseTransformPoint(rawMousePos);
|
||||
bool inResizePos = MouseInResizeArea(resizePos);
|
||||
bool inResizePos = !UIManager.NavBarRect.rect.Contains(UIManager.NavBarRect.InverseTransformPoint(rawMousePos))
|
||||
&& MouseInResizeArea(resizePos);
|
||||
|
||||
Vector3 dragPos = DragableArea.InverseTransformPoint(rawMousePos);
|
||||
bool inDragPos = DragableArea.rect.Contains(dragPos);
|
||||
@ -218,15 +221,25 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
public void OnDrag()
|
||||
{
|
||||
Vector3 diff = InputManager.MousePosition - m_lastDragPosition;
|
||||
Vector2 diff = (Vector2)InputManager.MousePosition - m_lastDragPosition;
|
||||
m_lastDragPosition = InputManager.MousePosition;
|
||||
|
||||
// update position while preserving the z value
|
||||
Vector3 pos = Panel.localPosition;
|
||||
float z = pos.z;
|
||||
pos += diff;
|
||||
pos.z = z;
|
||||
pos += (Vector3)diff;
|
||||
Panel.localPosition = pos;
|
||||
|
||||
// TODO prevent dragging the navbar outside the window completely.
|
||||
// this was not that, but should do that.
|
||||
|
||||
//var halfHeight = Panel.rect.height * 0.5f;
|
||||
//var halfWidth = Panel.rect.width * 0.5f;
|
||||
//if (Panel.MinY() - halfHeight + 25 < 0
|
||||
// || Panel.MinX() - halfWidth + 25 < 0
|
||||
// || Panel.MaxY() + halfWidth - 25 > Screen.height
|
||||
// || Panel.MinX() + halfWidth - 25 > Screen.width)
|
||||
//{
|
||||
// Panel.localPosition -= (Vector3)diff;
|
||||
//}
|
||||
}
|
||||
|
||||
public void OnEndDrag()
|
||||
@ -382,6 +395,7 @@ namespace UnityExplorer.UI.Panels
|
||||
m_currentResizeType = resizeType;
|
||||
m_lastResizePos = InputManager.MousePosition;
|
||||
WasResizing = true;
|
||||
Resizing = true;
|
||||
}
|
||||
|
||||
public void OnResize()
|
||||
@ -431,6 +445,7 @@ namespace UnityExplorer.UI.Panels
|
||||
public void OnEndResize()
|
||||
{
|
||||
WasResizing = false;
|
||||
Resizing = false;
|
||||
try { OnHoverResizeEnd(); } catch { }
|
||||
UpdateResizeCache();
|
||||
OnFinishResize?.Invoke(Panel);
|
||||
|
@ -134,7 +134,7 @@ namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
// create navbar button
|
||||
|
||||
NavButton = UIFactory.CreateButton(UIManager.navbarButtonHolder, $"Button_{PanelType}", Name);
|
||||
NavButton = UIFactory.CreateButton(UIManager.NavbarButtonHolder, $"Button_{PanelType}", Name);
|
||||
UIFactory.SetLayoutElement(NavButton.Button.gameObject, minWidth: 118, flexibleWidth: 0);
|
||||
RuntimeProvider.Instance.SetColorBlock(NavButton.Button, UIManager.navButtonDisabledColor, UIManager.navButtonDisabledColor * 1.2f);
|
||||
NavButton.OnClick += () =>
|
||||
|
Reference in New Issue
Block a user