diff --git a/Assets/Scripts/Animation List.meta b/Assets/Scripts/Animation List.meta new file mode 100644 index 0000000..406c05e --- /dev/null +++ b/Assets/Scripts/Animation List.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: a0aae9ae5f300ca4a8dd350f31041c7a +folderAsset: yes +timeCreated: 1453154556 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Animation List/ListManager.cs b/Assets/Scripts/Animation List/ListManager.cs new file mode 100644 index 0000000..ec4e341 --- /dev/null +++ b/Assets/Scripts/Animation List/ListManager.cs @@ -0,0 +1,137 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System.IO; +using System.Collections; +using System.Collections.Generic; + +// https://unity3d.com/pt/learn/tutorials/modules/beginner/live-training-archive/creating-scroll-lists-at-run-time + +[System.Serializable] +public class ItemData { + + public string animationName; + public Button.ButtonClickedEvent thingToDo; + +} + +public class ListManager : MonoBehaviour { + + public GameObject sampleItemObject; + public GameObject sampleLoadingItemObject; + + public string[] itemList; + private int index = 0; + private const int OFFSET = 20; + private int size = 0; + + public GameObject listBlock; + public GameObject bar; + + public Transform contentPanel; + public ScrollRect scrollView; + public InputField input; + + private bool isLoading = false; + private GameObject loadingItem; + + TrieST trie; + + void Start() + { + this.scrollView.onValueChanged.AddListener(checkScrollPosition); + this.input.onValueChange.AddListener(inputChanged); + + // Load TrieST + { + this.trie = new TrieST(); + + StreamReader s = new StreamReader(Application.dataPath + "/sinais.txt"); + + if (!s.EndOfStream) s.ReadLine(); + + while (!s.EndOfStream) + { + string temp = s.ReadLine(); + this.trie.put(temp, temp); + } + } + + this.itemList = getNamesByPrefix(""); + this.index = 0; + this.size = itemList.Length; + + this.loadingItem = Instantiate (sampleLoadingItemObject) as GameObject; + + StartCoroutine("populateList"); + } + + public void checkScrollPosition(Vector2 scrollPosition) + { + if (scrollPosition.y <= 0F && ! this.isLoading) + StartCoroutine("populateList"); + } + + public void inputChanged(string text) + { + this.itemList = getNamesByPrefix(text.ToUpper()); + this.index = 0; + this.size = itemList.Length; + + this.contentPanel.DetachChildren(); + foreach(GameObject go in GameObject.FindGameObjectsWithTag("clone")) + Destroy(go); + + StartCoroutine("populateList"); + } + + private IEnumerator populateList() + { + changeLoadingState(true); + yield return new WaitForSeconds(0); + + int last = this.index + OFFSET; + if (last > size) last = this.size; + + for (int i = index; i < last; i++) + { + string item = itemList[i]; + + GameObject newButton = Instantiate (sampleItemObject) as GameObject; + SampleItem sampleItem = newButton.GetComponent(); + sampleItem.title.text = item; + + sampleItem.GetComponent