码迷,mamicode.com
首页 > 其他好文 > 详细

小地图

时间:2016-05-16 19:30:26      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!