游戏蛮牛学习群(纯技术交流,不闲聊):159852603
游戏蛮牛 手机端
开启辅助访问
 找回密码
 注册帐号

扫一扫,访问微社区

首页   >   博客   >   18803836360

unity小地图

个人分类: 代码篇 | 2018-10-9 17:39

[code]csharpcode:

using UnityEngine;
using System.Collections;
 
public class PictureinPicture : MonoBehaviour {
 
	//定义枚举类型
	public enum HorizontalAlignment {left, center, right};
	public enum VerticalAlignment{top, middle, bottom};
	public enum ScreenDimensions{pixels, screen_percentage};
 
	//定义枚举类型的变量
	public HorizontalAlignment horizontalAlignment = HorizontalAlignment.left;
	public VerticalAlignment verticalAlignment = VerticalAlignment.top;
	public ScreenDimensions dimensions = ScreenDimensions.pixels;
 
	public int width = 50;
	public int height = 50;
	public float xOffset = 0.0f;
	public float yOffset = 0.0f;
	public bool update = true;
 
	private int hSize, vSize, hLoc, vLoc;
 
	void Start()
	{
		AdjustCamera();
	}
 
	//游戏运行时,每一帧都调用此函数
	void Update()
	{
		AdjustCamera();
	}
 
	//游戏对象初始化时,调用此函数
	void AdjustCamera()
	{
		if (dimensions == ScreenDimensions.screen_percentage)            //调节视图为指定百分比大小
		{
			hSize = (int)(width * 0.01f * Screen.width);
			vSize = (int)(height * 0.01f * Screen.height);
		}
		else       							 //调节视图为指定像素大小
		{
			hSize = height;
			vSize = width;
		}
 
		if (horizontalAlignment == HorizontalAlignment.left)               //水平方向上是左对齐
		{
			hLoc = (int)(xOffset * 0.01f * Screen.width);
		}
		else if(horizontalAlignment == HorizontalAlignment.right)         //水平方向上是右对齐
		{
			hLoc = (int)((Screen.width - hSize) - (xOffset * 0.01f * Screen.width));
		}
		else                                                             //水平方向上是居中
		{
			hLoc = (int)((Screen.width - hSize) * 0.5f - (xOffset * 0.01f * Screen.width));
		}
 
		if (verticalAlignment == VerticalAlignment.top)                     //垂直方向为顶端
		{
			vLoc = (int)((Screen.height - vSize) - (yOffset * 0.01f * Screen.height));
		}
		else if (verticalAlignment == VerticalAlignment.bottom)             //垂直方向为底端
		{
			vLoc = (int)(yOffset * 0.01f * Screen.height);
		}
		else								  //垂直方向为居中
		{
			vLoc = (int)((Screen.height - vSize) * 0.5f - (yOffset * 0.01f * Screen.height));
		}
 
		this.GetComponent<Camera>().pixelRect = new Rect(hLoc, vLoc, hSize, vSize);
	}
}


0 0

作者的其他最新博客

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册帐号

个人分类

标签

阅读排行

评论排行

推荐博客

最新博客

返回顶部