Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:class_diagram [2022/07/25 15:54] – admin | wiki:class_diagram [2022/07/27 16:48] (current) – admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | --- // | ||
| ====== Class Diagram ====== | ====== Class Diagram ====== | ||
| Line 125: | Line 126: | ||
| </ | </ | ||
| - | ;#; | + | |
| - | ** EVERY METHOD EXPLAINATION ** | + | |
| Line 141: | Line 141: | ||
| Refresh method calls Delete() and ShowsList(), | Refresh method calls Delete() and ShowsList(), | ||
| </ | </ | ||
| - | ;#; | ||
| ===== Building Interact ===== | ===== Building Interact ===== | ||
| Line 239: | Line 238: | ||
| </ | </ | ||
| + | <file | openSearch() > | ||
| + | This method is used to open button game object and start searching when user click the building | ||
| + | </ | ||
| - | --- // | + | <file | instantiateNewHologram() > |
| + | Create hologram when mouse pointed | ||
| + | </file> | ||
| + | <file | setActiveHide(bool x) > | ||
| + | active and deactive hologram object | ||
| + | </ | ||
| + | ===== 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' | ||
| + | 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< | ||
| + | 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, | ||
| + | } | ||
| + | void HandleMovementInput() | ||
| + | { | ||
| + | if (OpenCloseUI.UIopened != true)// | ||
| + | { | ||
| + | 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(" | ||
| + | { | ||
| + | if (newCameraPosition.y > 20) newCameraPosition += scrollSpeed; | ||
| + | } | ||
| + | |||
| + | if (Input.GetAxis(" | ||
| + | { | ||
| + | if (newCameraPosition.y < 60) newCameraPosition -= scrollSpeed; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | AttachedCamera.localPosition = Vector3.Lerp(AttachedCamera.localPosition, | ||
| + | transform.rotation = Quaternion.Lerp(transform.rotation, | ||
| + | transform.position = Vector3.Lerp(transform.position, | ||
| + | |||
| + | } | ||
| + | |||
| + | void HandleMouseMovementInput() | ||
| + | { | ||
| + | var ray = GetComponentInChildren< | ||
| + | sensor.Direction = ray; | ||
| + | |||
| + | if (OpenCloseUI.UIopened != true)// | ||
| + | { | ||
| + | |||
| + | if (Input.GetKey(KeyCode.Mouse0)) | ||
| + | { | ||
| + | if (detected == true) | ||
| + | { | ||
| + | buildingSelected.GetComponent< | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | bool detected; | ||
| + | public GameObject buildingSelected; | ||
| + | public void DetectBuilding() | ||
| + | { | ||
| + | var detectedItem = sensor.GetDetectionsByDistance(); | ||
| + | |||
| + | buildingSelected = detectedItem[0]; | ||
| + | buildingSelected.GetComponent< | ||
| + | detected = true; | ||
| + | } | ||
| + | |||
| + | public void DetectLostBuilding() | ||
| + | { | ||
| + | buildingSelected.GetComponent< | ||
| + | detected = false; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | <file | goToVector3(float x, float z);> | ||
| + | This method for outside of class to manipulate camera rig position | ||
| + | </ | ||
| + | |||
| + | <file | HandleMovementInput();> | ||
| + | This method will be call by fixed update to handle WASD camera movement. | ||
| + | </ | ||
| + | |||
| + | <file | HandleMouseMovementInput()> | ||
| + | This method is to handle mouse movement input by using raycast. This is how we detect building to select it. | ||
| + | </ | ||
| + | |||
| + | <file | DetectBuilding()> | ||
| + | This method will be called by Ray EVENT gameobject, it will fireup this method when it detect building. | ||
| + | </ | ||
| + | |||
| + | <file | DetectLostBuilding()> | ||
| + | This method will be called by Ray EVENT gameobject, it will fireup this method when it lost detect the selected building | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ===== 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 = " | ||
| + | public class Bangunan : ScriptableObject | ||
| + | { | ||
| + | [BoxGroup(" | ||
| + | public string namaBangunan; | ||
| + | [BoxGroup(" | ||
| + | [TextArea] | ||
| + | public string namaPenuhBangunan; | ||
| + | [BoxGroup(" | ||
| + | [TextArea(15, | ||
| + | public string maklumatPertama; | ||
| + | [BoxGroup(" | ||
| + | [TextArea(15, | ||
| + | public string maklumatKedua; | ||
| + | |||
| + | public float xLocation; | ||
| + | public float zLocation; | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | ===== 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< | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | <file | LerpToBuilding() > | ||
| + | When this method called it will lerp to the destination given (axis x and z) | ||
| + | </ | ||