标签:
using System.Collections.Generic; using UnityEngine; public class MiniMap : BaseUI { public Camera cameMiniMap; // 小地图摄像机 public UITexture miniMap; // 小地图图片 public List<UITexture> roleSpts; // 英雄角色图片 public List<UITexture> otherSpts; // 英雄角色图片 private Transform roleSprite; // 战斗主角 private BaseSprite spt; private Vector3 lastRolePosition; //上次主角对象的Position private float lastCheckTime; // 上次检查的时间 private float checkTimeInterval = 0.3f; // 检查的时间周期 private float checkSqrDistanceInterval = 0.25f; private float mapWidth; //大地图的宽度 private float mapHeight;//大地图的高度 bool isStart = false; private float movedX; private float movedY; Texture A1; Texture A2; Texture B1; Texture B2; public void InitMap() { roleSprite = Game.Instance.GetCurScene().Star.transform; spt = Game.Instance.GetCurScene().Star; //原始宽度乘以缩放比例计算出真实宽度 mapWidth = 95.5f; // size_x* scal_x; mapHeight = 159.8f; // size_z* scal_z; lastRolePosition = roleSprite.position; lastCheckTime = Time.time; isStart = true; A1 = Instantiate(Resources.Load("MiniMap/CampA1")) as Texture; A2 = Instantiate(Resources.Load("MiniMap/CampA2")) as Texture; B1 = Instantiate(Resources.Load("MiniMap/CampB1")) as Texture; B2 = Instantiate(Resources.Load("MiniMap/CampB2")) as Texture; } void Update() { if (!isStart) return; if (Time.time - lastCheckTime >= checkTimeInterval) { PKUnionScene scene = Game.Instance.GetCurScene() as PKUnionScene; // 自我阵营 for (int i = 0; i < scene.StarGroupPlayerList.Count; i++) { NGUITools.SetActive(roleSpts[i].gameObject, true); if (scene.StarGroupPlayerList[i].PlayerID != spt.ID) { movedX = miniMap.width / mapWidth * scene.StarGroupPlayerList[i].sprite.transform.position.x; movedY = miniMap.height / mapHeight * scene.StarGroupPlayerList[i].sprite.transform.position.z; if (scene.StarGroupPlayerList[i].Camp == EnumPKCamp.Group1) roleSpts[i].mainTexture = B2; else roleSpts[i].mainTexture = A2; roleSpts[i].transform.localPosition = new Vector3(movedX, movedY, roleSpts[i].transform.localPosition.z); } else { movedX = miniMap.width / mapWidth * roleSprite.position.x; movedY = miniMap.height / mapHeight * roleSprite.position.z; if (scene.StarGroupPlayerList[i].Camp == EnumPKCamp.Group1) roleSpts[i].mainTexture = B1; else roleSpts[i].mainTexture = A1; // 设置自己的位置 cameMiniMap.transform.localPosition = new Vector3(movedX, movedY, cameMiniMap.transform.localPosition.z); // 设置自己的方向 roleSpts[i].transform.eulerAngles = new Vector3(0, 0, -(roleSprite.eulerAngles.y)); } } // 敌对阵营 for (int i = 0; i < scene.OtherGrouPlayerList.Count; i++) { NGUITools.SetActive(otherSpts[i].gameObject, true); movedX = miniMap.width / mapWidth * scene.OtherGrouPlayerList[i].sprite.transform.position.x; movedY = miniMap.height / mapHeight * scene.OtherGrouPlayerList[i].sprite.transform.position.z; if (scene.OtherGrouPlayerList[i].Camp == EnumPKCamp.Group2) otherSpts[i].mainTexture = A2; else otherSpts[i].mainTexture = B2; otherSpts[i].transform.localPosition = new Vector3(movedX, movedY, 0);// -cameMiniMap.transform.localPosition.z); } lastCheckTime = Time.time; } } }
标签:
原文地址:http://www.cnblogs.com/HelloUnity/p/5498767.html