namespace PixelCamera
{
using UnityEngine;
///
/// Adjusts the transform of this game object to a grid that ensures constant sampling by the camera.
///
[ExecuteInEditMode]
public class VoxelGridAdjuster : MonoBehaviour
{
///
/// Allows for full control of a transform while still locking an object to the camera grid.
///
public Transform FollowedTransform;
///
/// The pixel camera manager which decides the grid.
///
PixelCameraManager pixelCameraManager;
void OnEnable()
{
this.Initialize();
}
void LateUpdate()
{
this.transform.position = this.pixelCameraManager.PositionToGrid(this.FollowedTransform.position);
}
///
/// Initializes the adjuster.
///
void Initialize()
{
if (this.pixelCameraManager == null)
{
this.pixelCameraManager = FindAnyObjectByType(typeof(PixelCameraManager)) as PixelCameraManager;
if (this.pixelCameraManager == null)
{
Debug.LogError("pixelCameraManager is null. Set it in editor!");
}
}
}
}
}