- 最后登录
- 2014-3-25
- 注册时间
- 2014-3-25
- 阅读权限
- 10
- 积分
- 25
- 纳金币
- 5
- 精华
- 0
|
using UnityEngine;
using System.Collections;
public class MiniMap : MonoBehaviour {
//当地缓存设置
Transform m_transform;
//绘制迷你地图和动态主角变量设置
public Texture2D m_miniMap = null;
private const float m_widthMap = 128f;
private const float m_heightMap = 128f;
public Texture2D m_playerICON = null;
private const float m_widthPlayer = 8f;
private const float m_heightPlayer = 8f;
private float m_miniPosX;
private float m_miniPosY;
//实际场景尺寸
public GameObject m_groundObj = null;
private float m_widthGD;//实际宽度
private float m_heightGD;//实际高度/长度
//显示的迷你地图与实际场景的宽高比
private float m_scaleWidth;
private float m_scaleHeight;
void Start()
{
m_transform = this.transform;
if (m_groundObj != null)
{
m_widthGD = m_groundObj.transform.localScale.x * m_groundObj.GetComponent<MeshFilter>().mesh.bounds.size.x;//计算实际宽
m_heightGD = m_groundObj.transform.localScale.z * m_groundObj.GetComponent<MeshFilter>().mesh.bounds.size.z;//计算实际高
m_scaleWidth = m_widthMap / m_widthGD;//计算宽相对比例
m_scaleHeight = m_heightMap / m_heightGD;//计算高相对比例
}
}
//更新主角在迷你地图上的坐标
void UpdateMiniMap()
{
m_miniPosX = m_widthMap / 2 + (m_transform.position.x * m_scaleWidth) - m_widthPlayer / 2;
m_miniPosY = m_heightMap /2 - (m_transform.position.z * m_scaleHeight) - m_heightPlayer / 2;
}
void OnGUI()
{
UpdateMiniMap();
GUI.DrawTexture(new Rect(0f, 0f, m_widthMap, m_heightMap), m_miniMap);//迷你地图绘制
GUI.DrawTexture(new Rect(m_miniPosX, m_miniPosY, m_widthPlayer, m_heightPlayer), m_playerICON);//主角标识绘制
}
}
|
|