//map-->scene
        public override bool DeSerializeObject(Serializable.Map map)
        {
            LayerMgr.ins.transform = transform;
            LayerMgr.ins.Clear();
            //Transform[] layers = new Transform[LayerMgr.MAX_LAYER_COUNT];
            foreach (var l in map.layers)
            {
                LayerMgr.ins.CreateLayer(l.layerIndex, l.moveFactor);
            }

            foreach (var p in map.objects)
            {
                GameObject obj =//PrefabsMgr.LoadMapObjectWithoutTheme(map.theme.ToString() +"/"+p.prefab);

                                 MapLoader.ins.LoadMapObjectV1(map.theme, p.prefab);
                if (obj == null)
                {
                    Debug.LogError("Can not find map object=" + map.theme + "  " + p.prefab);
                }
                else
                {
                    if ((p.layerIndex > 0) && (p.layerIndex <= LayerMgr.MAX_LAYER_COUNT))
                    {
                        obj = GameObject.Instantiate <GameObject>(obj, LayerMgr.ins.GetLayerByIndex(p.layerIndex));
                        p.Emplace <GameObject>(obj);
                    }
                    else
                    {
                        obj = GameObject.Instantiate <GameObject>(obj, transform);
                        p.Emplace <GameObject>(obj);
                    }
                }
            }
            return(base.DeSerializeObject(map));//default ok
        }
示例#2
0
    public void MergeAndUpdate(Serializable.Map map)
    {
        this.Init();
        //网格化
        this.InitGrid(map);

        //合并
        this.MergeGrid();

        //输出
        this.UpdateObjectsToMap(map);
    }
示例#3
0
 /// <summary>
 /// 如果是老版地图,预制的名字需要转换成对应表的id
 /// </summary>
 /// <param name="name">之前的预制名字</param>
 /// <param name="map">当前地图数据</param>
 public string ConvertPrefabName(string name, Serializable.Map map)
 {
     //已经是新地图,不做转换
     if (this.IsNewMapVersion(map.version))
     {
         return(name);
     }
     else
     {
         string key = map.theme.ToString() + "/" + name;
         return(GameConfig.instance.GetComponentIdByName(key).ToString());
     }
 }
示例#4
0
        public string ToJson(MapObjectRoot root)
        {
            Serializable.Map map = new Serializable.Map();
            map.theme   = MapEditorConfig.CurrentSelectTheme;
            map.creator = (ulong)StaticData.luuid;
            map.uuid    = 0; //(ulong)id;
            var serializes = this.transform.GetComponentsInChildren <EditorSerializeBase>();

            foreach (var p in serializes)
            {
                p.SerializeObject(map);
            }
            //填充额外信息
            //因为只能编辑一个地图 因此 除了新建地图 name brief 只读写 不清空

            //填充额外信息

            map.name  = MapEditorStroageData.current_map_name;   //root.map_name;
            map.brief = MapEditorStroageData.current_map_brief;  // root.map_brief;

            //地图的模式
            map.MapInfoMode = (int)MapEditorConfig.CurrentMapGameMode;

            if (MapEditorConfig.CurrentMapGameMode == MapGameMode.Share)
            {
                map.map_expansion = new Serializable.MapExpansion();
                map.map_expansion.SetEdgeBox(MapEditorStroageData.edgebox_left, MapEditorStroageData.edgebox_right, MapEditorStroageData.edgebox_up, MapEditorStroageData.edgebox_down);
                map.map_expansion.bigMap = 1;
            }

            if (MapEditorConfig.CurrentMapGameMode == MapGameMode.Parkour)
            {//酷跑模式
             //     map.map_parkour = new Serializable.MapParkour();
             //关于地图编辑器的模式 先case by case 待需求明确后 重构一下

                map.map_parkour = new Serializable.MapParkour();

                map.map_parkour.edgebox_left  = MapEditorStroageData.edgebox_left;
                map.map_parkour.edgebox_right = MapEditorStroageData.edgebox_right;
                map.map_parkour.edgebox_down  = MapEditorStroageData.edgebox_down;
                map.map_parkour.edgebox_up    = MapEditorStroageData.edgebox_up;
            }

            //用新版本地图
            map.version = "1.1";

            var str = map.ToJson();

            return(str);
        }
示例#5
0
        //info 是因为要传递 额外的数据 到MapInfo里面
        public void Load(long customs = 0)
        {
            if (loaded)
            {
                return;
            }
            loaded = true;
            string file = "";

            if (customs > 0)
            {
                file = customs.ToString() + ".json";
            }
            else
            {
                Debug.LogError("can not find curstom id=" + customs);
            }
            var str = Serializable.LoadFromFile(file);

            Serializable.Map map = null;
            try
            {
                map = Serializable.ToObject <Serializable.Map>(str);
            }
            catch (System.Exception e)
            {
            }
            if (map == null)
            {
                //TODO BUGLY 出现了  https://bugly.qq.com/v2/crash-reporting/errors/f4a2f0d471/17667?pid=1
#if UNITY_EDITOR
                Debug.LogError(" de-serialize map error  " + customs);
#endif
                return;
            }
            var serializes = this.transform.GetComponentsInChildren <EditorSerializeBase>();
            foreach (var p in serializes)
            {
                p.DeSerializeObject(map);
            }
            this.CurrentSerializeMap = map;

            LoadBackGround(map.theme);

#if UNITY_EDITOR
            //       Debug.Log(str);
#endif
        }
示例#6
0
        public override bool DeSerializeObject(Serializable.Map map)
        {
            var points            = map.spawn;
            List <Transform> list = new List <Transform>();

            if (points.points.Count != transform.childCount || points.points.Count != 4)
            {
                return(false);
            }
            for (int i = 0; i < points.points.Count; i++)
            {
                var child = transform.GetChild(i);
                list.Add(child);
            }
            map.spawn.Emplace <List <Transform> >(list);

            return(base.DeSerializeObject(map));//default ok
        }
示例#7
0
        public override bool SerializeObject(Serializable.Map map)
        {
            var p = new Serializable.SpawnPoints();

            if (transform.childCount != 4 || p == null)
            {
                return(false);
            }

            List <Vector3> list = new List <Vector3>();

            list.Add(this.transform.GetChild(0).position);
            list.Add(this.transform.GetChild(1).position);
            list.Add(this.transform.GetChild(2).position);
            list.Add(this.transform.GetChild(3).position);
            p.Fill <List <Vector3> >(list);
            map.spawn = p;
            return(base.SerializeObject(map));//default ok
        }
        public override bool DeSerializeObject(Serializable.Map map)
        {
            var points = map.weapon_spawn_points;
            List <EditorWeaponSpawnPointTag> list = new List <EditorWeaponSpawnPointTag>();

            while (transform.childCount < points.points.Count)
            {
                //实际武器点大于阈值 需要扩容  editor 也要处理这个
                GameObject x = GameObject.Instantiate <GameObject>(transform.GetChild(0).gameObject, transform, false);
                x.name = "p" + (transform.childCount + 1);
            }

            if (points == null || points.points.Count > transform.childCount || points.points.Count <= 0)
            {
                return(false);
            }
            int i = 0;

            for (i = 0; i < points.points.Count; i++)
            {
                var child = transform.GetChild(i);
                var c     = child.FetchComponent <EditorWeaponSpawnPointTag>();
                list.Add(c);
            }
            //emplace
            map.weapon_spawn_points.Emplace <List <EditorWeaponSpawnPointTag> >(list);


            /*   //destroy un-needed
             * List<Transform> need_destroy = new List<Transform>();
             * for (; i < 4; i++)
             * {
             *     need_destroy.Add(transform.GetChild(i));
             * }
             * foreach (var p in need_destroy)
             * {
             *     GameObject.DestroyImmediate(p.gameObject);
             * }
             * need_destroy.Clear();
             */

            return(base.DeSerializeObject(map));//default ok
        }
        public override bool SerializeObject(Serializable.Map map)
        {
            var p = new Serializable.WeaponSpawnPoints();

            if (transform.childCount <= 0 || p == null)
            {
                return(false);
            }

            List <EditorWeaponSpawnPointTag> list = new List <EditorWeaponSpawnPointTag>();

            foreach (var pp in transform.GetComponentsInChildren <EditorWeaponSpawnPointTag>())
            {
                list.Add(pp);
            }
            p.Fill <List <EditorWeaponSpawnPointTag> >(list);
            map.weapon_spawn_points = p;
            return(base.SerializeObject(map));//default ok
        }
示例#10
0
        public void LoadFromJson(string json)
        {
            if (loaded)
            {
                return;
            }
            loaded = true;
#if UNITY_EDITOR
            Debug.Log(json);
#endif
            Serializable.Map map = Serializable.ToObject <Serializable.Map>(json);

            var serializes = this.transform.GetComponentsInChildren <EditorSerializeBase>();
            foreach (var p in serializes)
            {
                p.DeSerializeObject(map);
            }
            this.CurrentSerializeMap = map;
            LoadBackGround(map.theme);
        }
示例#11
0
    private void UpdateObjectsToMap(Serializable.Map map)
    {
        map.objects.Clear();
        if (this.remainMapObjects.Count > 0)
        {
            map.objects.AddRange(this.remainMapObjects);
        }

        for (int i = 0; i < ROW_COUNT; i++)
        {
            for (int j = 0; j < COLUMN_COUNT; j++)
            {
                if (array[i, j] != null)
                {
                    //合并生成的放在collide
                    if ((array[i, j].transform.scale.z > 1.0f) || (array[i, j].transform.scale.y > 1.0f))
                    {
                        //注释掉是因为合并的时候已经加入collideMapObjects中了
                        //this.collideMapObjects.Add(array[i, j]);
                    }
                    else
                    {
                        //没有被合并的单元格
                        map.objects.Add(array[i, j]);
                    }
                }
                ;
            }
        }


        if (this.collideMapObjects.Count > 0)
        {
            map.colliders.AddRange(this.collideMapObjects);
        }

        if (this.terrainMapObjects.Count > 0)
        {
            map.terrain.AddRange(this.terrainMapObjects);
        }
    }
示例#12
0
        public void ReloadJson(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }
            if (!Serializable.Map.IsMapJson(json))
            {
                return;
            }

            Serializable.Map map = Serializable.ToObject <Serializable.Map>(json);
            //通过map 重建 data 主题的话 会在 进入时 加载 这里只管物件
            int theme = map.theme;

            this.map_name     = map.name;
            this.map_brief    = map.brief;
            current_map_brief = this.map_brief;
            current_map_name  = this.map_name;
            if (map.map_expansion != null)
            {
                edgebox_up    = map.map_expansion.edgebox_up;
                edgebox_down  = map.map_expansion.edgebox_down;
                edgebox_left  = map.map_expansion.edgebox_left;
                edgebox_right = map.map_expansion.edgebox_right;
            }
            else
            {
                if (map.MapInfoMode == (int)MapGameMode.Parkour)
                {
                    //跑酷模式
                    edgebox_up    = map.map_parkour.edgebox_up;
                    edgebox_down  = map.map_parkour.edgebox_down;
                    edgebox_left  = map.map_parkour.edgebox_left;
                    edgebox_right = map.map_parkour.edgebox_right;
                }
                else
                {
                    //经典模式
                    ResetEdgeBox();
                }
            }
            {//save map layer
                _layer_objs = new List <MapLayerData>();
                _layer_objs.Clear();


                //没有层的信息,默认创建层1
                if (map.layers.Count == 0)
                {
                    _layer_objs.Add(new MapLayerData
                    {
                        layerIndex  = EditorLayerMgr.TERRAIN_LAYER_INDEX,
                        moveFactorX = 1.0f,
                        moveFactorY = 1.0f,
                    });
                }
                else
                {
                    foreach (var p in map.layers)
                    {
                        _layer_objs.Add(new MapLayerData
                        {
                            layerIndex  = p.layerIndex,
                            moveFactorX = p.moveFactorX,
                            moveFactorY = p.moveFactorY
                        });
                    }
                }
            }
            bool isNewMap = MapEditorMgr.ins.IsNewMapVersion(map.version);
            {//save map object
                _map_objs = new List <MapObjectData>();
                _map_objs.Clear();
                foreach (var p in map.objects)
                {
                    if (isNewMap)
                    {
                        _map_objs.Add(new MapObjectData
                        {
                            prefab        = p.prefab,
                            position      = p.transform.position,
                            localScale    = p.transform.scale,
                            rotation      = p.transform.rotation,
                            layerIndex    = MapEditorMgr.ins.ConvertLayerIndex(p.layerIndex),
                            decorateIndex = p.decorateIndex,
                            //extPropClassIndex = p.extPropClassIndex,
                            //extPropClassName = p.extPropClassName,
                            //extPropJson = p.extPropJson
                        });
                    }
                    else
                    {
                        _map_objs.Add(new MapObjectData
                        {
                            //如果是旧版地图需要映射成新的地图(prefab名字-->地图id)
                            prefab        = MapEditorMgr.ins.ConvertPrefabName(p.prefab, map),
                            position      = p.transform.position,
                            localScale    = MapEditorMgr.ins.CorrentScale(p.prefab, map.theme, p.transform.scale),
                            rotation      = MapEditorMgr.ins.CorrentRotation(p.prefab, map.theme, p.transform.rotation),
                            layerIndex    = MapEditorMgr.ins.ConvertLayerIndex(p.layerIndex),
                            decorateIndex = p.decorateIndex,
                            //extPropClassIndex = p.extPropClassIndex,
                            //extPropClassName = p.extPropClassName,
                            //extPropJson = p.extPropJson
                        });
                    }
                }
            }
            {//save terrain object
                _terrain_objs = new List <MapObjectData>();
                _terrain_objs.Clear();

                foreach (var p in map.terrain)
                {
                    _terrain_objs.Add(new MapObjectData
                    {
                        //prefab = p.prefab,
                        //如果是旧版地图需要映射成新的地图(prefab名字-->地图id)
                        prefab        = MapEditorMgr.ins.ConvertPrefabName(p.prefab, map),
                        position      = p.transform.position,
                        localScale    = p.transform.scale,
                        rotation      = p.transform.rotation,
                        layerIndex    = MapEditorMgr.ins.ConvertLayerIndex(p.layerIndex),
                        decorateIndex = p.decorateIndex,
                        //extPropClassIndex = p.extPropClassIndex,
                        //extPropClassName = p.extPropClassName,
                        //extPropJson = p.extPropJson
                    });
                }
            }
            {//save  spawn point
                _spawn_points = new List <SpawnPointData>();
                _spawn_points.Clear();
                foreach (var p in map.spawn.points)
                {
                    _spawn_points.Add(new SpawnPointData
                    {
                        position = new Vector3(p.x, p.y, p.z)
                    });
                }
            }

            {//save  weapon spawn point
                _weapon_spawn_points = new List <WeaponSpawnPointData>();
                _weapon_spawn_points.Clear();
                int i = 0;
                foreach (var p in map.weapon_spawn_points.points)
                {
                    _weapon_spawn_points.Add(new WeaponSpawnPointData
                    {
                        position = new Vector3(p.x, p.y, p.z),
                        ids      = new List <int>(map.weapon_spawn_points.ids[i].ids)
                    });
                    i++;
                }
            }
        }
        //scene-->map
        public override bool SerializeObject(Serializable.Map map)
        {
            //

            int count = transform.childCount;

            if (count <= 0)
            {
                return(false);
            }

            //是否支持多层
            bool   supportMultiLayer = false;
            string name = transform.GetChild(0).gameObject.name;

            if (name.Contains("layer"))
            {
                supportMultiLayer = true;
            }

            if (!supportMultiLayer)
            {
                for (int i = 0; i < count; i++)
                {
                    Serializable.MapObject obj = new Serializable.MapObject();
                    if (obj == null)
                    {
                        return(false);
                    }
                    var child = transform.GetChild(i);
                    if (child.GetComponent <DontSerializeThisToJson>() != null)
                    {
                        continue;
                    }

                    //如果是隐藏的就不序列化
                    if (!child.gameObject.activeSelf)
                    {
                        continue;
                    }

                    obj.Fill <GameObject>(child.gameObject);

                    map.objects.Add(obj);
                }
            }
            else//多层地图
            {
                for (int i = 0; i < count; i++) //遍历层
                {
                    Serializable.MapLayer layer = new Serializable.MapLayer();
                    if (layer == null)
                    {
                        return(false);
                    }


                    var child = transform.GetChild(i);
                    layer.Fill <GameObject>(child.gameObject);

                    //如果是隐藏的就不序列化
                    if (!child.gameObject.activeSelf)
                    {
                        continue;
                    }

                    int childchildcount = child.childCount;
                    int layerIndex      = 0;
                    int.TryParse(child.gameObject.name.Substring(5), out layerIndex);

                    map.layers.Add(layer);

                    for (int j = 0; j < childchildcount; j++) //遍历层里的物件
                    {
                        Serializable.MapObject obj = new Serializable.MapObject();
                        if (obj == null)
                        {
                            return(false);
                        }
                        var childchild = child.GetChild(j);
                        if (childchild.GetComponent <DontSerializeThisToJson>() != null)
                        {
                            continue;
                        }

                        //如果是隐藏的就不序列化
                        if (!childchild.gameObject.activeSelf)
                        {
                            continue;
                        }

                        obj.Fill <GameObject>(childchild.gameObject);

                        map.objects.Add(obj);
                    }
                }
            }

            if (count != map.objects.Count)
            {
                return(false);
            }
            return(base.SerializeObject(map));//default ok
        }
示例#14
0
    private void InitGrid(Serializable.Map map)
    {
        List <Serializable.MapObject> gridMapObjects = new List <Serializable.MapObject>();
        bool init    = false;
        var  objects = map.objects;

        for (int i = 0; i < objects.Count; i++)
        {
            if (this.CanBeMerge(objects[i]))
            {
                gridMapObjects.Add(objects[i]);
                if (!init)
                {
                    this.maxLeft  = objects[i].transform.position.z;
                    this.maxRight = objects[i].transform.position.z;
                    this.maxDown  = objects[i].transform.position.y;
                    this.maxUp    = objects[i].transform.position.y;

                    init = true;
                }
                else
                {
                    // z<------- maxLeft代表z的正方向
                    if (objects[i].transform.position.z > this.maxLeft)
                    {
                        this.maxLeft = objects[i].transform.position.z;
                    }

                    if (objects[i].transform.position.z < this.maxRight)
                    {
                        this.maxRight = objects[i].transform.position.z;
                    }

                    if (objects[i].transform.position.y < this.maxDown)
                    {
                        this.maxDown = objects[i].transform.position.y;
                    }

                    if (objects[i].transform.position.y > this.maxUp)
                    {
                        this.maxUp = objects[i].transform.position.y;
                    }
                }
            }

            else
            {
                this.remainMapObjects.Add(objects[i]);
            }
        }


        int tmpMaxLeft  = Mathf.FloorToInt(this.maxLeft);
        int tmpMaxRight = Mathf.FloorToInt(this.maxRight);
        int tmpMaxDown  = Mathf.FloorToInt(this.maxDown);
        int tmpMaxUp    = Mathf.FloorToInt(this.maxUp);

        this.maxRow       = tmpMaxUp - tmpMaxDown + 1;
        this.maxColumn    = tmpMaxLeft - tmpMaxRight + 1;
        this.rowOffset    = -tmpMaxDown;
        this.columnOfsset = -tmpMaxRight;

        for (int j = 0; j < gridMapObjects.Count; j++)
        {
            this.AddGridObject(gridMapObjects[j]);
        }
    }
        //map-->scene
        public override bool DeSerializeObject(Serializable.Map map)
        {
            RuntimeLayerMgr.ins.Clear();
            RuntimeLayerMgr.ins.transform = transform;

            foreach (var l in map.layers)
            {
                RuntimeLayerMgr.ins.CreateLayer(l.layerIndex, l.moveFactorX, l.moveFactorY);
            }

            RuntimeLayerMgr.ins.RefreshData();

            //判断版本号
            bool isOldVersion = true;

            if (MapEditorMgr.ins.IsNewMapVersion(map.version))
            {
                isOldVersion = false;
            }

            foreach (var p in map.objects)
            {
                GameObject obj = null;
                if (isOldVersion)
                {
                    obj = MapLoader.ins.LoadMapObjectV1(map.theme, p.prefab);

                    p.transform.rotation = MapEditor.MapEditorMgr.ins.CorrentRotation(p.prefab, map.theme, p.transform.rotation);
                    p.transform.scale    = MapEditor.MapEditorMgr.ins.CorrentScale(p.prefab, map.theme, p.transform.scale);
                }
                else
                {
                    int id = int.Parse(p.prefab);
                    obj = MapLoader.ins.LoadMapObjectById(id);
                }
                if (obj == null)
                {
                    if (map.theme >= 1 && map.theme <= 3 || map.theme == 8 || map.theme == 11)
                    {
                    }
                    else
                    {
                        Debug.LogError("Can not find map object=" + map.theme + "  " + p.prefab);
                    }
                }
                else
                {
                    if ((p.layerIndex > 0) && (p.layerIndex <= RuntimeLayerMgr.MAX_LAYER_COUNT))
                    {
                        obj = GameObject.Instantiate <GameObject>(obj, RuntimeLayerMgr.ins.GetLayerByIndex(p.layerIndex));
                        p.Emplace <GameObject>(obj);
                    }
                    else
                    {
                        obj = GameObject.Instantiate <GameObject>(obj, transform);
                        p.Emplace <GameObject>(obj);
                    }

                    if (p.decorateIndex > 0)
                    {
                        var path = "change/" + p.decorateIndex.ToString();
                        var dec  = obj.transform.Find(path);
                        if (dec != null)
                        {
                            dec.gameObject.SetActive(true);
                        }
                    }
                }
            }

            ////////////////////////////////////////////////////////////////////
            //纯图形
            foreach (var p in map.terrain)
            {
                GameObject obj = null;
                if (isOldVersion)
                {
                    obj = MapLoader.ins.LoadMapObjectV1(map.theme, p.prefab);
                }
                else
                {
                    int id = int.Parse(p.prefab);
                    obj = MapLoader.ins.LoadMapObjectById(id);
                }
                if (obj == null)
                {
                    if (map.theme >= 1 && map.theme <= 3 || map.theme == 8 || map.theme == 11)
                    {
                    }
                    else
                    {
                        Debug.LogError("Can not find map object=" + map.theme + "  " + p.prefab);
                    }
                }
                else
                {
                    if ((p.layerIndex > 0) && (p.layerIndex <= RuntimeLayerMgr.MAX_LAYER_COUNT))
                    {
                        obj = GameObject.Instantiate <GameObject>(obj, RuntimeLayerMgr.ins.GetLayerByIndex(p.layerIndex));
                        p.Emplace <GameObject>(obj);
                    }
                    else
                    {
                        obj = GameObject.Instantiate <GameObject>(obj, transform);
                        p.Emplace <GameObject>(obj);
                    }

                    if (p.decorateIndex > 0)
                    {
                        var path = "change/" + p.decorateIndex.ToString();
                        var dec  = obj.transform.Find(path);
                        if (dec != null)
                        {
                            dec.gameObject.SetActive(true);
                        }
                    }

                    //Terrain禁掉物理
                    var colliders = obj.transform.GetComponentsInChildren <Collider>();
                    for (int i = 0; i < colliders.Length; i++)
                    {
                        colliders[i].enabled = false;
                    }
                }
            }


            ////////////////////////////////////////////////////////////////////
            //纯物理(碰撞)
            foreach (var p in map.colliders)
            {
                GameObject obj = null;
                if (isOldVersion)
                {
                    obj = MapLoader.ins.LoadMapObjectV1(map.theme, p.prefab);
                }
                else
                {
                    int id = int.Parse(p.prefab);
                    obj = MapLoader.ins.LoadMapObjectById(id);
                }
                if (obj == null)
                {
                    if (map.theme >= 1 && map.theme <= 3 || map.theme == 8 || map.theme == 11)
                    {
                    }
                    else
                    {
                        Debug.LogError("Can not find map object=" + map.theme + "  " + p.prefab);
                    }
                }
                else
                {
                    if ((p.layerIndex > 0) && (p.layerIndex <= RuntimeLayerMgr.MAX_LAYER_COUNT))
                    {
                        obj = GameObject.Instantiate <GameObject>(obj, RuntimeLayerMgr.ins.GetLayerByIndex(p.layerIndex));
                        p.Emplace <GameObject>(obj);
                    }
                    else
                    {
                        obj = GameObject.Instantiate <GameObject>(obj, transform);
                        p.Emplace <GameObject>(obj);
                    }

                    //Collide禁掉图形显示
                    var renders = obj.transform.GetComponentsInChildren <MeshRenderer>();
                    for (int i = 0; i < renders.Length; i++)
                    {
                        renders[i].enabled = false;
                    }
                }
            }
            return(base.DeSerializeObject(map));//default ok
        }
示例#16
0
 // map 中的对象 反序列化到 runtime 下的物体
 public virtual bool DeSerializeObject(Serializable.Map map)
 {
     //when ok return true
     return(true);
 }
示例#17
0
        public void ReloadJson(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }
            if (!Serializable.Map.IsMapJson(json))
            {
                return;
            }

            Serializable.Map map = Serializable.ToObject <Serializable.Map>(json);
            //通过map 重建 data 主题的话 会在 进入时 加载 这里只管物件
            int theme = map.theme;

            this.map_name     = map.name;
            this.map_brief    = map.brief;
            current_map_brief = this.map_brief;
            current_map_name  = this.map_name;
            if (map.MapInfoMode == (int)MapGameMode.Parkour)
            {
                //跑酷模式
                edgebox_up    = map.map_parkour.edgebox_up;
                edgebox_down  = map.map_parkour.edgebox_down;
                edgebox_left  = map.map_parkour.edgebox_left;
                edgebox_right = map.map_parkour.edgebox_right;
            }
            else
            {
                //经典模式
                ResetEdgeBox();
            }
            {//save map layer
                _layer_objs = new List <MapLayerData>();
                _layer_objs.Clear();
                foreach (var p in map.layers)
                {
                    _layer_objs.Add(new MapLayerData
                    {
                        layerIndex = p.layerIndex,
                        moveFactor = p.moveFactor
                    });
                }
            }
            {//save map object
                _map_objs = new List <MapObjectData>();
                _map_objs.Clear();
                foreach (var p in map.objects)
                {
                    _map_objs.Add(new MapObjectData
                    {
                        prefab            = p.prefab,
                        position          = p.transform.position,
                        layerIndex        = p.layerIndex,
                        extPropClassIndex = p.extPropClassIndex,
                        extPropClassName  = p.extPropClassName,
                        extPropJson       = p.extPropJson
                    });
                }
            }
            {//save  spawn point
                _spawn_points = new List <SpawnPointData>();
                _spawn_points.Clear();
                foreach (var p in map.spawn.points)
                {
                    _spawn_points.Add(new SpawnPointData
                    {
                        position = new Vector3(p.x, p.y, p.z)
                    });
                }
            }

            {//save  weapon spawn point
                _weapon_spawn_points = new List <WeaponSpawnPointData>();
                _weapon_spawn_points.Clear();
                int i = 0;
                foreach (var p in map.weapon_spawn_points.points)
                {
                    _weapon_spawn_points.Add(new WeaponSpawnPointData
                    {
                        position = new Vector3(p.x, p.y, p.z),
                        ids      = new List <int>(map.weapon_spawn_points.ids[i].ids)
                    });
                    i++;
                }
            }
        }