Created
July 7, 2014 00:29
-
-
Save tsubaki/c795291a394f524f22fd to your computer and use it in GitHub Desktop.
想定スクリーンの高さからカメラを拡大・縮小し、想定スクリーンサイズをドット絵の1ドットと一致させるver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Author
tsubaki
commented
Jul 7, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment