Created
September 25, 2020 12:52
-
-
Save gamebox777/e8c247e4c6e9c09e37f0a5dc765aa73b to your computer and use it in GitHub Desktop.
スクロールビューの
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.Serialization; | |
| using UnityEngine.UI; | |
| public class ScrollView00 : MonoBehaviour | |
| { | |
| /// <summary> ボタン親子付け用ルート </summary> | |
| public GameObject ContentRoot; | |
| /// <summary> ボタン生成用プレハブ </summary> | |
| public GameObject ContentButton; | |
| /// <summary> スクロールバー </summary> | |
| public Scrollbar ScrollBar; | |
| /// <summary> ボタンの数 </summary> | |
| private int mContentNumber = 100; | |
| // Start is called before the first frame update | |
| void Start() | |
| { | |
| //ボタン生成 | |
| for (int i = 0; i < mContentNumber; i++) { | |
| GameObject tObj = Instantiate(ContentButton, ContentRoot.transform); | |
| Text text = tObj.GetComponentInChildren<Text>(); | |
| if (text != null) { | |
| text.text = i.ToString(); | |
| } | |
| } | |
| } | |
| /// <summary> | |
| /// インプットフィールドの値の編集が完了 | |
| /// </summary> | |
| public void OnEndEdit( string text ) | |
| { | |
| Debug.Log(text); | |
| int no = Convert.ToInt32(text); | |
| if (no >= 0 && no < mContentNumber) { | |
| ScrollViewPositionChange(no); | |
| } | |
| } | |
| /// <summary> | |
| /// インプットフィールドで入力した値の番号の箇所に | |
| /// スクロールビューのポジションを変更する | |
| /// </summary> | |
| /// <param name="no"> インプットフィールドで入力した値 </param> | |
| void ScrollViewPositionChange(int no) | |
| { | |
| // スクロール箇所 | |
| float scrollpos = (float)no / (float)mContentNumber; | |
| ScrollBar.value = 1 - scrollpos; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment