Welcome to GEMENTAR TOUR PUO V2 Development Documentation. Enjoy your stay!

This is an old revision of the document!


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

Public Void Search()

 
This method is used to search certain keyword that contains in building list string text, It will detect all of building name, description. 
we use C# .Contains() method to check if any keyword contains in string.

Public Void Delete()

 
This method is used to destroy instantiated item, since we instantiate the UI GameObject to make it dynamically update, we need to handle the deletion every time it's update.

Public Void RefreshList()

 
Refresh method calls Delete() and ShowsList(), this come in handy when want to refresh those list.

BuildingInteract

Full Script

using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
 
public class BuildingInteract : MonoBehaviour
{
    public enum SenaraiBangunan
    {
        _1_pusat_islam = 0,
        _2_anjung_premier = 1,
        _3_cisec = 2,
        _4_dewan_jka = 3,
        _5_hep = 4,
        _6_JKM_D_JKA = 5,
        _7_PEJABAT_PENTADBIRAN = 6,
        _8_JMSK = 7,
        _9_DEWAN_WARISAN = 8,
        _10_STUDENT_CENTRE = 9,
        _11_GALERI_PUO = 10,
        _12_FUTSAL_CAMPUS_A = 11,
        _13_BENGKEL_MEKANIKAL = 12,
        _14_BENGKEL_AWAM = 13,
        _15_PERPUSTAKAAN = 14,
        _16_DEWAN_JUBLI = 15,
        _17_JMSK_D_JKM = 16,
        _18_BENGKKEL_AKM = 17,
        _19_JKP = 18,
        _20_CAFE_JKE = 19,
        _21_JTMK = 20,
        _22_JKE = 21
    }
 
    [Title("TEXT INPUT")]
    public TMP_InputField tmp;
    [Title("HOLO MATERIAL")]
    public Material holoMaterial;
    public GameObject bangunanChild;
    [SerializeField]
    [EnumToggleButtons]
    [Title("SENARAI BANGUNAN")]
    private SenaraiBangunan senaraiBangunan;
 
    private Bangunan bangunan;
    private List<Bangunan> bangunanList;
 
 
    private void Start()
    {
        bangunan = new Bangunan();
        bangunanChild = new GameObject();
        bangunanList = GameObject.Find("Building List Control").GetComponent<SearchSystemController>().bangunanList;
        bangunan = bangunanList[(int)senaraiBangunan];
 
 
        Debug.Log("Bangunan " + bangunan.namaBangunan);
 
        instantiateNewHologram();
        setActiveHide(false);
    }
 
    public void openSearch()
    {
        var button = GameObject.Find("Button_Building_List").GetComponent<OpenCloseUI>();
        button.openObjet();
 
        tmp.text = bangunan.namaBangunan;
        GameObject.Find("Building List Control").GetComponent<SearchSystemController>().DeleteList();
        GameObject.Find("Building List Control").GetComponent<SearchSystemController>().Search();
        GameObject.Find("Camera Rig").GetComponent<CameraController>().gotToVector3(bangunan.xLocation,bangunan.zLocation);
    }
 
 
    private void instantiateNewHologram()
    {
        var newItem = Instantiate(this, this.transform.position, this.transform.rotation);
        bangunanChild = newItem.gameObject;
        bangunanChild.transform.localScale += new Vector3(0.01f, 0.01f, 0.01f);
        bangunanChild.transform.SetParent(this.transform);
        Destroy(bangunanChild.GetComponent<BuildingInteract>());
        bangunanChild.layer = LayerMask.NameToLayer("Default");
        bangunanChild.GetComponent<Renderer>().material = holoMaterial;
 
    }
 
    public void setActiveHide(bool x)
    {
        bangunanChild.SetActive(x);
    }
}

Hilmi 2022/07/25 11:51


QR Code
QR Code wiki:class_diagram (generated for current page)
Hello World!
DokuWiki with monobook... rules!