You've already forked UniversalViewer
fixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using static UnityEngine.Rendering.VirtualTexturing.Debugging;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IPointerDownHandler, IPointerUpHandler
|
||||
@@ -48,12 +49,12 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
private void Start()
|
||||
{
|
||||
var handle = HandlePosition.GetComponent<RectTransform>();
|
||||
transform.position = new Vector2(
|
||||
Mathf.Clamp(transform.position.x, 0, Screen.width - handle.rect.width),
|
||||
Mathf.Clamp(transform.position.y, handle.sizeDelta.y, Screen.height));
|
||||
if (Proxy == null)
|
||||
{
|
||||
transform.position = RecalculatePosition(transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetProxyMode(UIDraggableProxy proxy)
|
||||
@@ -81,18 +82,19 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
}
|
||||
else
|
||||
{
|
||||
var canvas = ModelViewerInterface.GetInstance().MainCanvas;
|
||||
var proxyRect = Proxy.transform as RectTransform;
|
||||
var handleRect = HandlePosition.transform as RectTransform;
|
||||
var handleOffset = handleRect.sizeDelta.y * Vector3.up;
|
||||
var handleOffset = handleRect.sizeDelta.y * canvas.scaleFactor * Vector3.up;
|
||||
if (Proxy.GetComponentInParent<UIToolbar>().Layout == UIToolbar.LayoutMode.Vertical)
|
||||
{
|
||||
//anchor to top-right of button
|
||||
transform.position = proxyRect.position + proxyRect.sizeDelta.x * Vector3.right + handleOffset;
|
||||
transform.position = proxyRect.position + proxyRect.sizeDelta.x * canvas.scaleFactor * Vector3.right + handleOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
//anchor to bottom-left of button
|
||||
transform.position = proxyRect.position + proxyRect.sizeDelta.y * Vector3.up - handleOffset;
|
||||
transform.position = proxyRect.position + proxyRect.sizeDelta.y * canvas.scaleFactor * Vector3.up - handleOffset;
|
||||
}
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
@@ -126,11 +128,7 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
}
|
||||
case DragAction.Position:
|
||||
{
|
||||
var handle = HandlePosition.GetComponent<RectTransform>();
|
||||
|
||||
transform.position = new Vector2(
|
||||
Mathf.Clamp(Input.mousePosition.x + mouseOffset.x, 0, Screen.width - handle.rect.width),
|
||||
Mathf.Clamp(Input.mousePosition.y + mouseOffset.y, handle.sizeDelta.y, Screen.height));
|
||||
transform.position = RecalculatePosition((Vector2)Input.mousePosition + mouseOffset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -184,4 +182,16 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
{
|
||||
OnEndDrag(null);
|
||||
}
|
||||
|
||||
public Vector2 RecalculatePosition(Vector2 pos)
|
||||
{
|
||||
var handle = HandlePosition.transform as RectTransform;
|
||||
var tsf = transform as RectTransform;
|
||||
var canvas = ModelViewerInterface.GetInstance().MainCanvas;
|
||||
|
||||
var xPos = Mathf.Clamp(pos.x, 0, Screen.width - tsf.sizeDelta.x * canvas.scaleFactor);
|
||||
var yPos = Mathf.Clamp(pos.y, handle.sizeDelta.y * canvas.scaleFactor, Screen.height);
|
||||
|
||||
return new Vector2 (xPos, yPos);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user