Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created July 7, 2014 00:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/c795291a394f524f22fd to your computer and use it in GitHub Desktop.
Save tsubaki/c795291a394f524f22fd to your computer and use it in GitHub Desktop.
想定スクリーンの高さからカメラを拡大・縮小し、想定スクリーンサイズをドット絵の1ドットと一致させるver
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class PixelBase : MonoBehaviour {
void LateUpdate ()
{
Vector3 cashPosition, cashScale;
cashPosition = transform.localPosition;
cashScale = transform.localScale;
transform.localPosition = new Vector3(
Mathf.RoundToInt( cashPosition.x),
Mathf.RoundToInt( cashPosition.y),
Mathf.RoundToInt( cashPosition.z));
transform.localScale = new Vector3(
Mathf.RoundToInt( cashScale.x),
Mathf.RoundToInt( cashScale.y),
Mathf.RoundToInt( cashScale.z));
}
}
using UnityEngine;
using System.Collections;
public class ResizeByPixel : MonoBehaviour
{
public int pixelSize;
public float defaultSize = 1;
public int screenHeight = 1920;
void OnValidate()
{
float orthographicSize = screenHeight / pixelSize * 0.5f;
Camera.main.orthographicSize = orthographicSize;
defaultSize = Mathf.Max(0.0001f, defaultSize);
if( pixelSize < 1 )
return;
float rate = defaultSize / pixelSize;
transform.localScale = new Vector3(rate, rate, rate);
}
}
@tsubaki
Copy link
Author

tsubaki commented Jul 7, 2014

likepixelperfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment