Пример #1
0
    ///// <summary>
    /////
    ///// </summary>
    ///// <param name="fileName">相对于 Application.streamingAssetsPath 的路径  (/Scene/Scene_1_1.json)</param>
    ///// <returns></returns>
    //public string LoadJson(string fileName) {
    //    string path = Application.streamingAssetsPath + fileName;
    //    if (!File.Exists(path)) {
    //        Debug.LogError("文件不存在:" + path);
    //    }

    //    //加载配置文件
    //    return File.ReadAllText(path);
    //}

    /// <summary>
    /// 加载场景
    /// </summary>
    /// <param name="sceneName">例如: Scene_1_1 酱紫 </param>
    public GameObject LoadScene(string sceneName)
    {
        string    json       = IOTool.LoadJson("Scene/" + sceneName + ".json");
        SceneConf conf_scene = JsonMapper.ToObject <SceneConf>(json);

        if (conf_scene == null)
        {
            Debug.LogError("Load Json ERROR!");
            return(null);
        }
        if (conf_scene.Bounds == null)
        {
            Debug.LogError("Load Json Bounds NULL!");
            LoadScene(conf_scene);
            return(null);
        }
        // 应该在外部工具存储的时候转为世界坐标存储
        GameObject scene  = LoadScene(conf_scene);
        Transform  parent = scene.transform.FindChild("Map/Bounds");

        foreach (var item in conf_scene.Bounds)
        {
            // 相对坐标转世界坐标
            _cur_scene_bounds.Add(parent.localToWorldMatrix.MultiplyPoint(item.GetPosition()));
        }
        return(scene);
    }