-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapterChoosing.cs
More file actions
47 lines (41 loc) · 1.25 KB
/
Copy pathChapterChoosing.cs
File metadata and controls
47 lines (41 loc) · 1.25 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.EventSystems;
using System;
public class ChapterChoosing : MonoBehaviour , IBeginDragHandler , IEndDragHandler
{
private ScrollRect scrollrect;
private float[] pagearray = new float[] { 0, 0.07733f, 0.15466f};//, 0.23199f, 0.30932f
// Start is called before the first frame update
void Start()
{
scrollrect = GetComponent<ScrollRect>();
}
// Update is called once per frame
void Update()
{
}
public void OnBeginDrag(PointerEventData eventData)
{
}
public void OnEndDrag(PointerEventData eventData)
{
float temp = scrollrect.horizontalNormalizedPosition;//拖曳結果座標
int index = 0;
float offset = Math.Abs(pagearray[index] - temp);
for (int i = 1; i < pagearray.Length; i++)
{
float offsetTemp = Math.Abs(pagearray[i] - temp);
if (offsetTemp < offset)
{
index = i;
offset = offsetTemp;
}
scrollrect.horizontalNormalizedPosition = pagearray[index];
}
print(temp);
}
}