forked from bbepis/XUnity.AutoTranslator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollViewState.cs
More file actions
99 lines (83 loc) · 2.07 KB
/
ScrollViewState.cs
File metadata and controls
99 lines (83 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
namespace UnityEngine
{
internal class ScrollViewState
{
public Rect position;
public Rect visibleRect;
public Rect viewRect;
public Vector2 scrollPosition;
public bool apply;
public ScrollViewState()
{
}
public void ScrollTo( Rect pos )
{
ScrollTowards( pos, float.PositiveInfinity );
}
public bool ScrollTowards( Rect pos, float maxDelta )
{
Vector2 vector = ScrollNeeded( pos );
if( vector.sqrMagnitude < 0.0001f )
{
return false;
}
if( maxDelta == 0f )
{
return true;
}
if( vector.magnitude > maxDelta )
{
vector = vector.normalized * maxDelta;
}
scrollPosition += vector;
apply = true;
return true;
}
private Vector2 ScrollNeeded( Rect pos )
{
Rect rect = visibleRect;
rect.x += scrollPosition.x;
rect.y += scrollPosition.y;
float num = pos.width - visibleRect.width;
if( num > 0f )
{
pos.width -= num;
pos.x += num * 0.5f;
}
num = pos.height - visibleRect.height;
if( num > 0f )
{
pos.height -= num;
pos.y += num * 0.5f;
}
Vector2 zero = Vector2.zero;
if( pos.xMax > rect.xMax )
{
zero.x += pos.xMax - rect.xMax;
}
else if( pos.xMin < rect.xMin )
{
zero.x -= rect.xMin - pos.xMin;
}
if( pos.yMax > rect.yMax )
{
zero.y += pos.yMax - rect.yMax;
}
else if( pos.yMin < rect.yMin )
{
zero.y -= rect.yMin - pos.yMin;
}
Rect rect2 = viewRect;
return zero;
}
}
}