質問編集履歴
2
説明追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
ご教授の程、お願い致します。
|
8
8
|
また、足りない情報等ありましたら、お知らせ願います。
|
9
9
|
|
10
|
+
※容量を小さくしたGif画像を、何故か本投稿へ貼り付けできなかったため、横スワイプの実行結果確認いただく際は、以下URLよりご確認願います。
|
11
|
+
https://d.kuku.lu/823499bbf5
|
10
12
|
|
11
13
|
### 該当のソースコード
|
12
14
|
|
1
誤字修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -79,83 +79,4 @@
|
|
79
79
|
|
80
80
|
### 補足情報(FW/ツールのバージョンなど)
|
81
81
|
|
82
|
-
ここにより詳細な情報を記載してください。
|
83
|
-
### 前提・実現したいこと
|
84
|
-
|
85
|
-
unityで、縦にスワイプできるパネルを作成です。
|
86
|
-
下記にあります、該当のソースコードでは、パネルを横にスワイプできるようになっております。
|
87
|
-
あらかじめページ数をpublicで宣言し、そのページ数をオーバーしたスワイプはできないようにしております。
|
88
|
-
|
89
|
-
|
90
|
-
### 該当のソースコード
|
91
|
-
|
92
|
-
```C#
|
93
|
-
using System.Collections;
|
94
|
-
using System.Collections.Generic;
|
95
|
-
using UnityEngine;
|
96
|
-
using UnityEngine.EventSystems;
|
97
|
-
|
98
|
-
public class PageSwiper : MonoBehaviour, IDragHandler, IEndDragHandler
|
99
|
-
{
|
100
|
-
private Vector3 panelLocation;
|
101
|
-
public float percentThreshold = 0.2f;
|
102
|
-
public float easing = 0.5f;
|
103
|
-
public float totalPages = 1;
|
104
|
-
private int currentPage = 1;
|
105
|
-
|
106
|
-
// Start is called before the first frame update
|
107
|
-
void Start()
|
108
|
-
{
|
109
|
-
panelLocation = transform.position;
|
110
|
-
}
|
111
|
-
public void OnDrag(PointerEventData data)
|
112
|
-
{
|
113
|
-
float difference = data.pressPosition.x - data.position.x;
|
114
|
-
transform.position = panelLocation - new Vector3(difference, 0, 0);
|
115
|
-
}
|
116
|
-
public void OnEndDrag(PointerEventData data)
|
117
|
-
{
|
118
|
-
float percentage = (data.pressPosition.x - data.position.x) / Screen.width;
|
119
|
-
if (Mathf.Abs(percentage) >= percentThreshold)
|
120
|
-
{
|
121
|
-
Vector3 newLocation = panelLocation;
|
122
|
-
if (percentage > 0 && currentPage < totalPages)
|
123
|
-
{
|
124
|
-
currentPage++;
|
125
|
-
newLocation += new Vector3(-Screen.width, 0, 0);
|
126
|
-
}
|
127
|
-
else if (percentage < 0 && currentPage > 1)
|
128
|
-
{
|
129
|
-
currentPage--;
|
130
|
-
newLocation += new Vector3(Screen.width, 0, 0);
|
131
|
-
}
|
132
|
-
StartCoroutine(SmoothMove(transform.position, newLocation, easing));
|
133
|
-
panelLocation = newLocation;
|
134
|
-
}
|
135
|
-
else
|
136
|
-
{
|
137
|
-
StartCoroutine(SmoothMove(transform.position, panelLocation, easing));
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
IEnumerator SmoothMove(Vector3 startpos, Vector3 endpos, float seconds)
|
142
|
-
{
|
143
|
-
float t = 0f;
|
144
|
-
|
82
|
+
環境:Unity 2020.1.2f1
|
145
|
-
{
|
146
|
-
t += Time.deltaTime / seconds;
|
147
|
-
transform.position = Vector3.Lerp(startpos, endpos, Mathf.SmoothStep(0f, 1f, t));
|
148
|
-
yield return null;
|
149
|
-
}
|
150
|
-
}
|
151
|
-
}
|
152
|
-
|
153
|
-
```
|
154
|
-
|
155
|
-
### 試したこと
|
156
|
-
|
157
|
-
コード内のposition.xをyにしたり、Vector3()内の値をxとyで入れ替えたりと、色々試しましたが実現できませんでした。
|
158
|
-
|
159
|
-
### 補足情報(FW/ツールのバージョンなど)
|
160
|
-
|
161
|
-
ここにより詳細な情報を記載してください。
|