Beispiel #1
0
    //获取地图配置文件
    public MapConfigures GetConfigures(int id)
    {
        MapConfigures data = null;

        if (m_MapDict.TryGetValue(id, out data))
        {
            return(data);
        }

        return(null);
    }
Beispiel #2
0
    void LoadPrefab(MapConfigures map)
    {
        GameObject player = resourceService.GetPlayer(Consts.PlayerInCity, true);

        player.transform.position    = map.playerBornPos;
        player.transform.eulerAngles = map.playerBornRot;
        player.transform.localScale  = new Vector3(1.4f, 1.4f, 1.4f);

        playerController = player.GetComponent <PlayerController>();
        playerController.InitCharator();



        Camera.main.transform.transform.position         = map.mainCamPos;
        Camera.main.transform.transform.localEulerAngles = map.mainCamRot;
    }
Beispiel #3
0
    //从文件中加载地图配置文件到内存
    void LoadMapConfigure(string path)
    {
        TextAsset asset = Resources.Load <TextAsset>(path);

        //加载XML文件

        if (asset == null)
        {
            Debug.Log("文件为空");
        }
        else//添加到字典中
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml(asset.text);

            XmlNodeList xmlNodeList = document.SelectSingleNode("root").ChildNodes;
            for (int i = 0; i < xmlNodeList.Count; i++)
            {
                XmlElement element = xmlNodeList[i] as XmlElement;
                if (element.GetAttributeNode("ID") == null)
                {
                    continue;
                }

                var           id     = int.Parse(element.GetAttributeNode("ID").InnerText);
                MapConfigures mapCfg = new MapConfigures();
                mapCfg.ID = id;
                foreach (XmlElement item in xmlNodeList[i].ChildNodes)
                {
                    switch (item.Name)
                    {
                    case "mapName":
                        mapCfg.mapName = item.InnerText;
                        break;

                    case "sceneName":
                        mapCfg.sceneName = item.InnerText;
                        break;

                    case "mainCamPos":
                    {
                        var nums = item.InnerText.Split(',');
                        mapCfg.mainCamPos = new Vector3(float.Parse(nums[0]), float.Parse(nums[1]), float.Parse(nums[2]));
                        break;
                    }

                    case "mainCamRote":
                    {
                        var nums = item.InnerText.Split(',');
                        mapCfg.mainCamRot = new Vector3(float.Parse(nums[0]), float.Parse(nums[1]), float.Parse(nums[2]));
                        break;
                    }

                    case "playerBornPos":
                    {
                        var nums = item.InnerText.Split(',');
                        mapCfg.playerBornPos = new Vector3(float.Parse(nums[0]), float.Parse(nums[1]), float.Parse(nums[2]));
                        break;
                    }

                    case "playerBornRote":
                    {
                        var nums = item.InnerText.Split(',');
                        mapCfg.playerBornRot = new Vector3(float.Parse(nums[0]), float.Parse(nums[1]), float.Parse(nums[2]));
                        break;
                    }

                    default:
                        break;
                    }
                }

                m_MapDict.Add(id, mapCfg);
            }
        }
    }