private void Awake() { InfoText = transform.parent.GetChild(transform.parent.childCount - 1).GetComponentInChildren <Text> (); sampleList = transform.GetChild(0).gameObject; doneButton = sampleList.transform.GetChild(2).GetComponent <Button> (); reOrderableList = sampleList.GetComponentInChildren <ReOrderableList> (); orderControlPanel = sampleList.transform.GetChild(1).gameObject; }
/// <summary>初期化</summary> public void Init() { if (!orderableList) { orderableList = GetComponentInParent <ReOrderableList> (); scrollRect = GetComponentInParent <ScrollRect> (); elementIndex = GetComponentInChildren <ElementIndex> (); buttons = GetComponentsInChildren <Button> (); } }
public void Restart() { if (sampleList) { return; } // デバッグ表示クリア InfoText.text = ""; // 内部リスト項目生成 itemNames = new List<string> { }; for (var i = 0; i < 100; i++) { itemNames.Add (new RandomKey ().Key); } // リスト作成 sampleList = Instantiate (listPrefab, transform); doneButton = sampleList.transform.GetChild (2).GetComponent<Button> (); doneButton.onClick.AddListener (OnPushDoneButton); reOrderableList = sampleList.GetComponentInChildren<ReOrderableList> (); orderControlPanel = sampleList.transform.GetChild (1).gameObject; backButton = orderControlPanel.GetComponentInChildren<Button> (); backButton.onClick.AddListener (() => { reOrderableList.Orderable = false; }); // モード切替コールバック reOrderableList.AddOnChangeModeListener ( (orderable) => { orderControlPanel.SetActive (orderable); // 並べ替え時専用コントロールパネル doneButton.interactable = !orderable; // 完了ボタン foreach (var obj in reOrderableList.GameObjects) { obj.transform.GetChild (3).gameObject.SetActive (orderable); // ドラッグハンドル } } ); // 選択コールバック reOrderableList.AddOnSelectListener ( (index) => { reOrderableList.Interactable = false; printResult (reOrderableList.Indexes, index); Destroy (sampleList); } ); // 並べ替えコールバック int elementIndex = -1; reOrderableList.AddOnBeginOrderListener ( (index) => { elementIndex = index; StartCoroutine (printDelay (() => $"開始: {index}")); } ); reOrderableList.AddOnUpdateOrderListener ( (index) => { StartCoroutine (printDelay (() => $"更新: {elementIndex} ⇒ {index}")); } ); reOrderableList.AddOnEndOrderListener ( (index) => { StartCoroutine (printDelay (() => $"終了: {string.Join (", ", reOrderableList.Indexes.ConvertAll (i => i.ToString ()))}")); } ); // リスト項目作成 for (var i = 0; i < itemNames.Count; i++) { var obj = Instantiate (elementPrefab, transform); var texts = obj.GetComponentsInChildren<Text> (); texts [0].text = i.ToString (); texts [1].text = itemNames [i]; reOrderableList.AddElement (obj); } }