Exemplo n.º 1
0
    //地图分为3个层次:
    //1,整个地图map
    //2,地图块MapItem,组成map的元素,移动以及旋转以mapItem为单位
    //3,瓷砖tile,组成mapItem的元素,方块

    /// <summary>
    /// 根据配置文件动态创建地图
    /// </summary>
    /// <param name="mapPath"></param>
    public void ReadJsonAndInit(string mapPath)
    {
        string   jsonText = ResourcesManager.Instance.LoadAssetByFullName <TextAsset>(mapPath).text;
        JsonData rootData = JsonMapper.ToObject(jsonText);

        tileWidth = (float)(double)rootData["Width"];
        jumpWidth = PlayerModel.Instance.Speed * PlayerModel.Instance.StandJumpTime;

        //用来控制地图生成的位置与方向
        mapCreatePoint          = new GameObject("MapCreatePoint").transform;
        mapCreatePoint.position = new Vector3(0, -0.18f, 0);
        mapCreatePoint.forward  = Vector3.forward;
        //地图元素的父物体
        mapParent          = new GameObject("MapParent").transform;
        mapParent.position = mapCreatePoint.position;

        JsonData maps = rootData["Map"];

        foreach (JsonData map in maps)
        {
            MapItem mapItem = new MapItem();
            mapItem.Init(this);
            mapItem.CreateMapItem(map);
            mapItems.Add(mapItem);
        }
    }