Single Tech Games

Tutorial de Unity 2.5D VIII – Transiciones, Autoresolución y multilenguaje

Hola gente! Esta semana demore un poco en traerles el nuevo vídeo por la falta de tiempo, es un poco difícil llevar cursos, aprender un nuevo idioma y avanzar con mis juegos, pero aquí estamos, les cuento que voy a darle un pequeño break a los tutoriales de Unity 2.5D, llegaré hasta la manipulación del inventario, algo bastante pedido por muchos, para pasar a otra serie que ya no va tener que ver con Unity específicamente.

Código
BotonJugarScript

using UnityEngine;
using System.Collections;
public class BotonJugarScript : MonoBehaviour {
	private BoxCollider2D presionar;
	public FuncionesComunesScript funcionesGlobales;
	// Use this for initialization
	void Start () {
		presionar = this.gameObject.GetComponent<BoxCollider2D>();
	}
	// Update is called once per frame
	void Update () {
		tocandoPantalla ();
	}
	private void tocandoPantalla()
	{
		bool presiono = funcionesGlobales.contactoCaja (presionar);
		if (presiono) {
			Application.LoadLevel("escenaJuego");
		}
	}
}

FuncionesComunesScript

using UnityEngine;
using System.Collections;
public class FuncionesComunesScript : MonoBehaviour {
	public bool contactoCaja(BoxCollider2D presionar)
	{
		if (Input.GetMouseButtonDown (0)) {
			Vector3 posicionTap = Camera.main.ScreenToWorldPoint(Input.mousePosition);
			Vector2 posicionTap2D = new Vector2(posicionTap.x,posicionTap.y);
			return presionar.OverlapPoint(posicionTap2D);
		}else
			return false;
	}
}

ResolucionPantalla

// Más información sobre este archivo y su uso:
// http://wiki.unity3d.com/index.php?title=AspectRatioEnforcer
using UnityEngine;
public class ResolucionPantalla : MonoBehaviour {
	public float _wantedAspectRatio = 1.7777778f;
	static float wantedAspectRatio;
	static Camera cam;
	static Camera backgroundCam;
	void Awake () {
		cam = camera;
		if (!cam) {
			cam = Camera.main;
		}
		if (!cam) {
			Debug.LogError ("No camera available");
			return;
		}
		wantedAspectRatio = _wantedAspectRatio;
		SetCamera();
	}
	public static void SetCamera () {
		float currentAspectRatio = (float)Screen.width / Screen.height;
		// If the current aspect ratio is already approximately equal to the desired aspect ratio,
		// use a full-screen Rect (in case it was set to something else previously)
		if ((int)(currentAspectRatio * 100) / 100.0f == (int)(wantedAspectRatio * 100) / 100.0f) {
			cam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
			if (backgroundCam) {
				Destroy(backgroundCam.gameObject);
			}
			return;
		}
		// Pillarbox
		if (currentAspectRatio > wantedAspectRatio) {
			float inset = 1.0f - wantedAspectRatio/currentAspectRatio;
			cam.rect = new Rect(inset/2, 0.0f, 1.0f-inset, 1.0f);
		}
		// Letterbox
		else {
			float inset = 1.0f - currentAspectRatio/wantedAspectRatio;
			cam.rect = new Rect(0.0f, inset/2, 1.0f, 1.0f-inset);
		}
		if (!backgroundCam) {
			// Make a new camera behind the normal camera which displays black; otherwise the unused space is undefined
			backgroundCam = new GameObject("BackgroundCam", typeof(Camera)).camera;
			backgroundCam.depth = int.MinValue;
			backgroundCam.clearFlags = CameraClearFlags.SolidColor;
			backgroundCam.backgroundColor = Color.black;
			backgroundCam.cullingMask = 0;
		}
	}
	public static int screenHeight {
		get {
			return (int)(Screen.height * cam.rect.height);
		}
	}
	public static int screenWidth {
		get {
			return (int)(Screen.width * cam.rect.width);
		}
	}
	public static int xOffset {
		get {
			return (int)(Screen.width * cam.rect.x);
		}
	}
	public static int yOffset {
		get {
			return (int)(Screen.height * cam.rect.y);
		}
	}
	public static Rect screenRect {
		get {
			return new Rect(cam.rect.x * Screen.width, cam.rect.y * Screen.height, cam.rect.width * Screen.width, cam.rect.height * Screen.height);
		}
	}
	public static Vector3 mousePosition {
		get {
			Vector3 mousePos = Input.mousePosition;
			mousePos.y -= (int)(cam.rect.y * Screen.height);
			mousePos.x -= (int)(cam.rect.x * Screen.width);
			return mousePos;
		}
	}
	public static Vector2 guiMousePosition {
		get {
			Vector2 mousePos = Event.current.mousePosition;
			mousePos.y = Mathf.Clamp(mousePos.y, cam.rect.y * Screen.height, cam.rect.y * Screen.height + cam.rect.height * Screen.height);
			mousePos.x = Mathf.Clamp(mousePos.x, cam.rect.x * Screen.width, cam.rect.x * Screen.width + cam.rect.width * Screen.width);
			return mousePos;
		}
	}
}

Imágenes
espanainglesFonts
https://www.google.com/fonts
Vídeo
Parte I – Manejo de Fuentes https://www.youtube.com/watch?v=6iGBePMAyL4#t=2m20s
Parte II – Agregando las nuevas banderas para el multi-lenguaje https://www.youtube.com/watch?v=6iGBePMAyL4#t=6m20s
Parte III – Haciendo transiciones entre escenas, ejecutar el botón play usando funciones comunes https://www.youtube.com/watch?v=6iGBePMAyL4#t=10m08s
Parte IV – Implementar la resolución de pantalla que mantiene el mismo ratio de imágenes https://www.youtube.com/watch?v=6iGBePMAyL4#t=14m07s
Proyecto
 https://www.box.net/shared/8tdbudzev32ijfzabfo6
Suerte!

0 0 votes
Article Rating
Subscribe
Notify of
guest
4 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
David

Hola, cual es es script para que se vea en cualquier pantalla? no el que pone las lineas negras, sino el que ajusta las imágenes al tamaño de pantalla, en el vídeo lo mencionas

Hernan

Hola julio ¡¡
Muy buenos tus tutos. Un genio.
Pregunta por curiosidad, ya q vas a hacer otra serie q no tiene q ver con Unity, se puede saber con que vas a seguir ?
Saludos desde Argentina ¡