Tanoda
pb_WindowResizer.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
4using System.Collections;
5
6namespace GILES.Interface
7{
11 public class pb_WindowResizer : MonoBehaviour, IBeginDragHandler, IDragHandler
12 {
13 public RectTransform window;
14
15 private Rect screenRect = new Rect(0,0,0,0);
16
17 public Vector2 minSize = new Vector2(100, 100);
18 public Vector2 maxSize = new Vector2(10000,10000);
19
20 private void Start()
21 {
22 if (window.rect.width < minSize.x)
23 {
24 Vector2 size = window.sizeDelta;
25 var temp = Screen.width + size.x;
26 temp -= minSize.x;
27 size.x -= temp;
28 window.sizeDelta = size;
29 }
30 }
31
32 public void OnBeginDrag(PointerEventData eventData)
33 {
34 screenRect.width = Screen.width;
35 screenRect.height = Screen.height;
36 }
37
38 public void OnDrag(PointerEventData eventData)
39 {
40 if(window == null)
41 {
42 Debug.LogWarning("Window parent is null, cannot drag a null window.");
43 return;
44 }
45
46 window.position += (Vector3) eventData.delta * .5f;
47
48 Vector2 flip = new Vector2(eventData.delta.x, -eventData.delta.y);
49
50 window.sizeDelta += flip;
51
52 Rect r = pb_GUIUtility.GetScreenRect(window);
53
54 float w = window.rect.width, h = window.rect.height;
55
56 if( w < minSize.x || w > maxSize.x || (r.x + r.width > screenRect.width) )
57 {
58 Vector2 size = window.sizeDelta;
59 size.x -= flip.x;
60 window.sizeDelta = size;
61
62 Vector3 pos = window.position;
63 pos.x -= eventData.delta.x * .5f;
64 window.position = pos;
65 }
66
67 if( h < minSize.y || h > maxSize.y || (r.y - r.height < 0) )
68 {
69 Vector2 size = window.sizeDelta;
70 size.y -= flip.y;
71 window.sizeDelta = size;
72
73 Vector3 pos = window.position;
74 pos.y -= eventData.delta.y * .5f;
75 window.position = pos;
76 }
77
78 foreach(pb_IOnResizeHandler handler in window.transform.GetComponentsInChildren<pb_IOnResizeHandler>())
79 handler.OnResize();
80 }
81 }
82}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void OnBeginDrag(PointerEventData eventData)
void OnDrag(PointerEventData eventData)