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

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:class_diagram [2022/07/25 14:12] adminwiki:class_diagram [2022/07/27 16:48] (current) admin
Line 1: Line 1:
 + --- //[[admin@puov2.gementar.com|Hilmi]] 2022/07/25 16:42//
 ====== Class Diagram ====== ====== Class Diagram ======
  
Line 125: Line 126:
 </code> </code>
  
-;#; 
-** EVERY METHOD EXPLAINATION ** 
-;#; 
  
  
  
 +<file | 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.
 +</file>
 +
 +<file | 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.
 +</file>
 +
 +<file | Public Void RefreshList() > 
 +Refresh method calls Delete() and ShowsList(), this come in handy when want to refresh those list.
 +</file>
 +
 +===== Building Interact =====
 +
 +<code CSharp | 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);
 +    }
 +}
 +</code>
 +
 +<file | openSearch() > 
 +This method is used to open button game object and start searching when user click the building
 +</file>
 +
 +<file | instantiateNewHologram() > 
 +Create hologram when mouse pointed - it will duplicate object set as child and increase size to 0.01
 +</file>
 +
 +<file | setActiveHide(bool x) > 
 +active and deactive hologram object
 +</file>
 +
 +===== Camera Controller =====
 +
 +<code CSharp | Full Script>
 +using Micosmo.SensorToolkit;
 +using System;
 +using System.Collections;
 +using System.Collections.Generic;
 +using UnityEngine;
 +
 +#region Code Information
 +/*
 +    This script is for cammeracontroller
 +    prettymuch self explainatory
 +    
 +    OPENCLOSEUI.UIOPENED IS USED TO DETERMINE IF THERE'S ANY UI OPEN
 +
 +    gotovector3() <-- called to set location elsewhere.
 +
 + */
 +#endregion
 +
 +public class CameraController : MonoBehaviour
 +{
 +
 +    public float movementSpeed;
 +    public float movementTime;
 +    public float rotationSpeed;
 +    public Vector3 scrollSpeed;
 +    
 +    public Transform AttachedCamera;
 +
 +    public Vector3 newPosition;
 +    public Vector3 newCameraPosition;
 +
 +    public Quaternion newRotation;
 +
 +    private RaySensor sensor;
 +
 +    // Start is called before the first frame update
 +    void Start()
 +    {
 +        
 +        sensor = GetComponentInChildren<RaySensor>();
 +        buildingSelected = new GameObject();
 +
 +        newPosition = transform.position;
 +        newRotation = transform.rotation;
 +        newCameraPosition = AttachedCamera.localPosition;
 +    }
 +
 +    private void FixedUpdate()
 +    {
 +        HandleMouseMovementInput();
 +        HandleMovementInput();
 +    }
 +
 +    public void gotToVector3(float x, float z)
 +    {
 +        newPosition = new Vector3(x, this.transform.position.y, z);
 +    }
 +
 +    void HandleMovementInput()
 +    {
 +        if (OpenCloseUI.UIopened != true)//DETERMINE IF THERE'S ANY UI OPEN
 +        {
 +            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
 +            {
 +                newPosition += (transform.forward * movementSpeed);
 +            }
 +
 +            if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
 +            {
 +                newPosition += (transform.forward * -movementSpeed);
 +            }
 +
 +            if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
 +            {
 +                newPosition += (transform.right * -movementSpeed);
 +            }
 +
 +            if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
 +            {
 +                newPosition += (transform.right * movementSpeed);
 +            }
 +
 +            if (Input.GetKey(KeyCode.Q))
 +            {
 +                newRotation *= Quaternion.Euler(Vector3.up * -rotationSpeed);
 +            }
 +
 +            if (Input.GetKey(KeyCode.E))
 +            {
 +                newRotation *= Quaternion.Euler(Vector3.up * rotationSpeed);
 +            }
 +
 +            if (Input.GetAxis("Mouse ScrollWheel") > 0f || Input.GetKey(KeyCode.Z)) // forward
 +            {
 +                if (newCameraPosition.y > 20) newCameraPosition += scrollSpeed;
 +            }
 +
 +            if (Input.GetAxis("Mouse ScrollWheel") < 0f || Input.GetKey(KeyCode.X)) // backwards
 +            {
 +                if (newCameraPosition.y < 60) newCameraPosition -= scrollSpeed;
 +            }
 +        }
 +
 +        AttachedCamera.localPosition = Vector3.Lerp(AttachedCamera.localPosition, newCameraPosition, Time.fixedDeltaTime * movementTime);
 +        transform.rotation = Quaternion.Lerp(transform.rotation, newRotation, Time.fixedDeltaTime * movementTime);
 +        transform.position = Vector3.Lerp(transform.position, newPosition, Time.fixedDeltaTime * movementTime);
 +
 +    }
 +
 +    void HandleMouseMovementInput()
 +    {
 +        var ray = GetComponentInChildren<Camera>().ScreenPointToRay(Input.mousePosition).direction;
 +        sensor.Direction = ray;
 +
 +        if (OpenCloseUI.UIopened != true)//DETERMINE IF THERE'S ANY UI OPEN
 +        {
 +
 +            if (Input.GetKey(KeyCode.Mouse0))
 +            {
 +                if (detected == true)
 +                {
 +                    buildingSelected.GetComponent<BuildingInteract>().openSearch();
 +                }
 +            }
 +        }
 +    }
 +
 +    bool detected;
 +    public GameObject buildingSelected;
 +    public void DetectBuilding()
 +    {
 +        var detectedItem = sensor.GetDetectionsByDistance();
 +
 +            buildingSelected = detectedItem[0];
 +            buildingSelected.GetComponent<BuildingInteract>().setActiveHide(true);
 +            detected = true;
 +    }
 +
 +    public void DetectLostBuilding()
 +    {
 +        buildingSelected.GetComponent<BuildingInteract>().setActiveHide(false);
 +        detected = false;
 +    }
 +}
 +
 +</code>
 +
 +<file | goToVector3(float x, float z);> 
 +This method for outside of class to manipulate camera rig position
 +</file>
 +
 +<file | HandleMovementInput();> 
 +This method will be call by fixed update to handle WASD camera movement.
 +</file>
 +
 +<file | HandleMouseMovementInput()> 
 +This method is to handle mouse movement input by using raycast. This is how we detect building to select it.
 +</file>
 +
 +<file | DetectBuilding()> 
 +This method will be called by Ray EVENT gameobject, it will fireup this method when it detect building.
 +</file>
 +
 +<file | DetectLostBuilding()> 
 +This method will be called by Ray EVENT gameobject, it will fireup this method when it lost detect the selected building
 +</file>
 +
 +
 +
 +===== Bangunan (SCRIPTABLE OBJECT) =====
 +
 +<code CSharp | Full Script>
 +using System.Collections;
 +using System.Collections.Generic;
 +using UnityEngine;
 +using Sirenix.OdinInspector;
 +
 +#region Code Information
 +/*
 +   This is a scriptable object. make sure to put x/z location to the pivot of camera Rig
 + */
 +#endregion
 +
 +[CreateAssetMenu(fileName = "DataBangunan", menuName ="Data Bangunan")]
 +public class Bangunan : ScriptableObject
 +{
 +    [BoxGroup("Informasi Bangunan")]
 +    public string namaBangunan;
 +    [BoxGroup("Informasi Bangunan")]
 +    [TextArea]
 +    public string namaPenuhBangunan;
 +    [BoxGroup("Informasi Bangunan")]
 +    [TextArea(15, 50)]
 +    public string maklumatPertama;
 +    [BoxGroup("Informasi Bangunan")]
 +    [TextArea(15, 50)]
 +    public string maklumatKedua;
 +
 +    public float xLocation;
 +    public float zLocation;
 +}
 +
 +</code>
 +
 +
 +===== Button Lerp To Building =====
 +
 +<code CSharp | Full Script>
 +using System.Collections;
 +using System.Collections.Generic;
 +using UnityEngine;
 +using TMPro;
 +using System;
 +
 +#region Code Information
 +/*
 +    This script is for button lerp to building.
 +    So we will get ScriptableObject Bangunan from SearchSystemController iteration
 +    and use building location values to lerp into the preferred location
 + */
 +#endregion
 +
 +public class ButtonLerpToBuilding : MonoBehaviour
 +{
 +    public Bangunan bangunan;
 +
 +    public void LerpToBuilding()
 +    {
 +        FindObjectOfType<CameraController>().gameObject.GetComponent<CameraController>().gotToVector3(bangunan.xLocation, bangunan.zLocation);
 +    }
 +}
 +
 +</code>
 +
 +<file | LerpToBuilding() > 
 +When this method called it will lerp to the destination given (axis x and z)
 +</file>
  
  
- --- //[[admin@puov2.gementar.com|Hilmi]] 2022/07/25 11:51// 

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