| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class BIWFloorLoading : MonoBehaviour |
| | 6 | | { |
| | 7 | | private Camera builderCamera = null; |
| | 8 | |
|
| | 9 | | private const float RELATIVE_SCALE_RATIO = 0.032f; |
| | 10 | |
|
| 0 | 11 | | public void Initialize(Camera camera) { builderCamera = camera; } |
| | 12 | |
|
| | 13 | | private void LateUpdate() |
| | 14 | | { |
| 2 | 15 | | if ( builderCamera == null ) |
| 0 | 16 | | return; |
| | 17 | |
|
| 2 | 18 | | Transform cameraTransform = builderCamera.transform; |
| 2 | 19 | | Quaternion cameraRotation = cameraTransform.rotation; |
| 2 | 20 | | Vector3 position = transform.position; |
| | 21 | |
|
| 2 | 22 | | transform.LookAt(position + cameraRotation * Vector3.forward, |
| | 23 | | cameraRotation * Vector3.up); |
| | 24 | |
|
| 2 | 25 | | float dist = GetCameraPlaneDistance(builderCamera, position); |
| 2 | 26 | | transform.localScale = new Vector3(RELATIVE_SCALE_RATIO * dist, RELATIVE_SCALE_RATIO * dist, RELATIVE_SCALE_RATI |
| 2 | 27 | | } |
| | 28 | |
|
| | 29 | | private static float GetCameraPlaneDistance(Camera camera, Vector3 objectPosition) |
| | 30 | | { |
| 2 | 31 | | Plane plane = new Plane(camera.transform.forward, camera.transform.position); |
| 2 | 32 | | return plane.GetDistanceToPoint(objectPosition); |
| | 33 | | } |
| | 34 | | } |