質問編集履歴

3

書式の改善

2022/05/08 12:54

投稿

Cyifon
Cyifon

スコア2

test CHANGED
File without changes
test CHANGED
@@ -171,6 +171,7 @@
171
171
  https://uni.gas.mixh.jp/unity/canvas-text-image.html
172
172
  この記事を参考に、配列(?)index(?)でジャケット画像をリストにして、サークルの真ん中にどのボタンあるのかを取得してテクスチャを張り替えるのが一番実装しやすいのかな...とも思いましたが、どのようにサークルの真ん中に来ているボタンを取得するのか分かりません...
173
173
  どのような方針で実装すれば良いのかアドバイスがいただきたいです...!
174
+
174
175
 
175
176
  ![理想の実装](https://ddjkaamml8q8x.cloudfront.net/questions/2022-05-08/aaa55b0a-cf53-4f5f-b927-b1972b0c1a4d.png)
176
177
 

2

記載忘れ

2022/05/08 07:13

投稿

Cyifon
Cyifon

スコア2

test CHANGED
File without changes
test CHANGED
@@ -5,7 +5,7 @@
5
5
  https://gyazo.com/5b89e3b8295b0f0d070efb33938d8214
6
6
 
7
7
  このGifの用に、ドラッグすることにより曲名の書かれたボタンがくるくると回転して摩擦によりある程度回転したら「かくっ」と回転が止まります。
8
- これは以下の「SimpleCircleLayoutGroup」「SimpleCircleInterface」の二つのコードで実装しています。
8
+ これは以下の「SimpleCircleLayoutGroup」「SimpleCircleInterface」の二つのコードと追記したコードで実装しています。
9
9
 
10
10
  ```C#
11
11
  using UnityEngine;

1

記載忘れ

2022/05/08 07:11

投稿

Cyifon
Cyifon

スコア2

test CHANGED
File without changes
test CHANGED
@@ -175,3 +175,70 @@
175
175
  ![理想の実装](https://ddjkaamml8q8x.cloudfront.net/questions/2022-05-08/aaa55b0a-cf53-4f5f-b927-b1972b0c1a4d.png)
176
176
 
177
177
 
178
+ 追記です。
179
+
180
+ 円形の選択の実装は
181
+ https://tsubakit1.hateblo.jp/entry/2016/04/11/070637
182
+ こちらの記事を参考に↓こういった実装がしてあります。
183
+ ```C#
184
+ using UnityEngine;
185
+ using UnityEngine.UI;
186
+
187
+ public class RadialLayout : LayoutGroup
188
+ {
189
+ public float fDistance;
190
+ [Range(0f, 360f)]
191
+ public float MinAngle, MaxAngle, StartAngle;
192
+ protected override void OnEnable() { base.OnEnable(); CalculateRadial(); }
193
+ public override void SetLayoutHorizontal()
194
+ {
195
+ }
196
+ public override void SetLayoutVertical()
197
+ {
198
+ }
199
+ public override void CalculateLayoutInputVertical()
200
+ {
201
+ CalculateRadial();
202
+ }
203
+ public override void CalculateLayoutInputHorizontal()
204
+ {
205
+ CalculateRadial();
206
+ }
207
+ #if UNITY_EDITOR
208
+ protected override void OnValidate()
209
+ {
210
+ base.OnValidate();
211
+ CalculateRadial();
212
+ }
213
+ #endif
214
+ void CalculateRadial()
215
+ {
216
+ m_Tracker.Clear();
217
+ if (transform.childCount == 0)
218
+ return;
219
+ float fOffsetAngle = ((MaxAngle - MinAngle)) / (transform.childCount - 1);
220
+
221
+ float fAngle = StartAngle;
222
+ for (int i = 0; i < transform.childCount; i++)
223
+ {
224
+ RectTransform child = (RectTransform)transform.GetChild(i);
225
+ if (child != null)
226
+ {
227
+ //Adding the elements to the tracker stops the user from modifiying their positions via the editor.
228
+ m_Tracker.Add(this, child,
229
+ DrivenTransformProperties.Anchors |
230
+ DrivenTransformProperties.AnchoredPosition |
231
+ DrivenTransformProperties.Pivot);
232
+ Vector3 vPos = new Vector3(Mathf.Cos(fAngle * Mathf.Deg2Rad), Mathf.Sin(fAngle * Mathf.Deg2Rad), 0);
233
+ child.localPosition = vPos * fDistance;
234
+ //Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points.
235
+ child.anchorMin = child.anchorMax = child.pivot = new Vector2(0.5f, 0.5f);
236
+ fAngle += fOffsetAngle;
237
+ }
238
+ }
239
+
240
+ }
241
+ }
242
+ ```
243
+
244
+