This is an old revision of the document!
Table of Contents
Class Diagram
Class Explanation
Search System Controller
Full Script
using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using System.Linq; using TMPro; #region Code Information /* This script is used for System Controller First of all we need bangunanList -> ScriptableObject List menuList -> Menu Prefabs contentGameObject -> to make the prefab as child instantiatedGameObject List to take notes of instantiated gameobject to destroy it later. */ #endregion public class SearchSystemController : MonoBehaviour { public List<Bangunan> bangunanList; public GameObject menuList; public GameObject contentGameObject; private List<GameObject> InstantiatedGameObject; public TMP_InputField textInput; private void Start() { InstantiatedGameObject = new List<GameObject>(); ShowList(bangunanList); RefreshList(); } private void Update() { if(Input.anyKeyDown && !textInput.Equals("")) { if (Input.GetKey(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse1)) { return; } else { DeleteList(); Search(); } } } public void Search() // Search by using C# contains { List<Bangunan> searchedBangunan = new List<Bangunan>(); foreach (var item in bangunanList) { string nameList = (item.namaBangunan + item.namaPenuhBangunan + item.maklumatKedua + item.maklumatPertama).ToLower(); string searchText = textInput.text.ToLower(); if (nameList.Contains(searchText) == true) { searchedBangunan.Add(item); } } ShowList(searchedBangunan); } // ------------------------------------------------------ SHOW & DELETE SYSTEM -------------------------------------------------- private void ShowList(List<Bangunan> bangunanChoosen) { foreach (var item in bangunanChoosen) { GameObject newList; newList = Instantiate(menuList, new Vector3(323.265f, -319.235f, 0), Quaternion.identity); newList.transform.SetParent(contentGameObject.transform); newList.transform.Find("Label_Ribbon01_Group/Label_Ribbon01/Building Name").gameObject.GetComponent<TextMeshProUGUI>().SetText(item.namaBangunan, 3.5f); newList.transform.Find("Building Full Name").gameObject.GetComponent<TextMeshProUGUI>().SetText(item.namaPenuhBangunan, 3.5f); newList.transform.Find("Course/Course List").gameObject.GetComponent<TextMeshProUGUI>().SetText(item.maklumatPertama, 3.5f); newList.transform.Find("Class/Class List").gameObject.GetComponent<TextMeshProUGUI>().SetText(item.maklumatKedua, 3.5f); newList.GetComponent<ButtonLerpToBuilding>().bangunan = item; InstantiatedGameObject.Add(newList); } } public void DeleteList() { if (InstantiatedGameObject.Count == 0) return; foreach (var item in InstantiatedGameObject) { Destroy(item); } } [Button("RefreshList")] public void RefreshList() { DeleteList(); ShowList(bangunanList); } }
EVERY METHOD EXPLAINATION
— Hilmi 2022/07/25 11:51