PixelPerfect.cs 836 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using UnityEngine;
  3. public class PixelPerfect : MonoBehaviour
  4. {
  5. private void Awake()
  6. {
  7. this.my_camera_ = base.GetComponent<Camera>();
  8. NDebug.AssertNull(this.TargetMesh != null && this.my_camera_ != null);
  9. }
  10. private void Start()
  11. {
  12. this.my_camera_.orthographic = true;
  13. this.UpdateTargetSize();
  14. }
  15. private void LateUpdate()
  16. {
  17. this.UpdateTargetSize();
  18. }
  19. private void UpdateTargetSize()
  20. {
  21. Vector3 localScale = this.TargetMesh.transform.localScale;
  22. if (this.render_size_.x != localScale.x || this.render_size_.y != localScale.z)
  23. {
  24. this.render_size_.x = localScale.x;
  25. this.render_size_.y = localScale.z;
  26. this.my_camera_.orthographicSize = this.render_size_.y / 2f;
  27. }
  28. }
  29. [SerializeField]
  30. private MeshRenderer TargetMesh;
  31. private Camera my_camera_;
  32. private Vector2 render_size_;
  33. }