bad-piggies-0.1.3-porting/Assets/Scripts/Assembly-CSharp/CameraSpaceTransform.cs
2024-02-24 22:40:44 -05:00

46 lines
1.5 KiB
C#

using UnityEngine;
public class CameraSpaceTransform : MonoBehaviour
{
private const float SizeCorrectionFactor = 0.1f;
private Camera sourceCamera;
private Camera targetCamera;
private Transform proxyTransform;
private Transform targetTransform;
public void Start()
{
if ((bool)GameObject.Find("3dPropsCamera"))
{
sourceCamera = GameObject.Find("GameCamera").camera;
targetCamera = GameObject.Find("3dPropsCamera").camera;
Assert.IsValid(sourceCamera, "sourceCamera");
Assert.IsValid(targetCamera, "targetCamera");
proxyTransform = base.transform;
targetTransform = base.transform.FindChild("RotatingMap").transform;
if ((bool)targetTransform && (bool)targetTransform.gameObject && (bool)targetTransform.gameObject.GetComponentInChildren<MeshRenderer>())
{
proxyTransform.gameObject.GetComponentInChildren<MeshRenderer>().enabled = false;
targetTransform.gameObject.GetComponentInChildren<MeshRenderer>().enabled = true;
}
}
else
{
Debug.LogWarning("3dPropsCamera is not enabled, camera space transfrom is not used!");
Object.Destroy(base.gameObject);
}
}
private void LateUpdate()
{
Start();
targetTransform.position = targetCamera.ScreenToWorldPoint(sourceCamera.WorldToScreenPoint(proxyTransform.position));
Vector3 b = targetCamera.ScreenToWorldPoint(sourceCamera.WorldToScreenPoint(proxyTransform.position + Vector3.right));
float num = Vector3.Distance(targetTransform.position, b) * 0.1f;
targetTransform.localScale = new Vector3(num, num, num);
}
}