Пример #1
0
    public void ReloadScene(DataStream datastream)
    {
        Debug.Log("ReloadScene");

        LevelOption me = null;

        List <GameObject> delarr = new List <GameObject>();

        foreach (GameObject sceneObject in Object.FindObjectsOfType(typeof(GameObject)))
        {
            if (sceneObject.name == "MapEditor")
            {
                me = sceneObject.GetComponent <LevelOption>();
                me.deserialize(datastream);
                GameCommon.GAME_DATA_VERSION = me.version;
                continue;
            }
            else if (sceneObject.name != "Main Camera" && sceneObject.name != "Directional Light")
            {
                delarr.Add(sceneObject);
            }
        }

        //创建关卡配置物体
        if (me == null)
        {
            GameObject tGO = new GameObject("MapEditor");
            me = tGO.AddComponent <LevelOption>();
            me.deserialize(datastream);

            MapEditor me1 = tGO.AddComponent <MapEditor>();
            me1.lo = me;
        }

        Debug.Log(me.levelName + " / " + me.version);

        foreach (GameObject obj in delarr)
        {
            DestroyImmediate(obj);
        }
        int objcount = datastream.ReadSInt32();

        Debug.Log("objcount : " + objcount);
        Dictionary <int, InGameBaseObj> dic = new Dictionary <int, InGameBaseObj>();
        MapObjConfManager mapObjConfManager = ConfigManager.GetEditorMapObjConfManager();

        for (int i = 0; i < objcount; i++)
        {
            //MSBaseObject.CreateObj(datastream);
            //从字节流中获取id

            int   confid = 0;
            float x = 0, y = 0, sx = 1, sy = 1;

            MapObjConf    conf = null;
            GameObject    go = null, tempObj;
            InGameBaseObj baseObj = null;
            int           dataid  = datastream.ReadByte();
            while (dataid != 0)
            {
                switch (dataid)
                {
                case 1:
                    confid  = datastream.ReadSInt32();
                    conf    = mapObjConfManager.map[confid];
                    tempObj = Resources.Load(conf.path) as GameObject;
                    if (tempObj == null)
                    {
                        Debug.Log(confid + " is null!");
                    }
                    go      = (GameObject)Instantiate(tempObj);
                    baseObj = go.GetComponent <InGameBaseObj>();
                    break;

                case 2: x = datastream.ReadSInt32() / 1000f; break;

                case 3: y = datastream.ReadSInt32() / 1000f; break;

                case 4:
                    int parentid = datastream.ReadSInt32();
                    if (dic.ContainsKey(parentid))
                    {
                        go.transform.parent = dic[parentid].transform;
                    }
                    else
                    {
                        go.transform.parent = me.transform;
                    }
                    break;

                case 5:
                    int instanceid = datastream.ReadSInt32();
                    dic.Add(instanceid, baseObj);
                    break;

                case 7: go.name = datastream.ReadString16(); break;

                case 8: sx = datastream.ReadSInt32() / 1000f; break;

                case 9: sy = datastream.ReadSInt32() / 1000f; break;

                case 6: baseObj.Deserialize(datastream); break;
                }
                dataid = datastream.ReadByte();
            }

            go.transform.position   = new Vector3(x, y);
            go.transform.localScale = new Vector3(sx, sy, 1);
            GameCommon.SetObjZIndex(go, conf.depth);
        }
    }
Пример #2
0
    protected void InsertGroup(Vector2 pos, int groupid)
    {
        Debug.Log(groupid);
        int          x = (int)pos.x, y = (int)pos.y;
        MapGroupConf conf = ConfigManager.mapGroupConfManager.dataMap[groupid];

        if (conf == null)
        {
            return;
        }
        TextAsset text = Resources.Load(conf.path) as TextAsset;

        byte[]     data       = GameCommon.UnGZip(text.bytes);
        DataStream datastream = new DataStream(data, true);

        //配置LevelOption
        GameObject logo = new GameObject(conf.path);

        //logo.transform.parent = this.mapObj.transform;
        logo.transform.position = GameCommon.GetWorldPos(pos);
        LevelOption me = logo.AddComponent <LevelOption>();

        me.deserialize(datastream);

        //生成物体
        int objcount = datastream.ReadSInt32();

        for (int i = 0; i < objcount; i++)
        {
            //MSBaseObject.CreateObj(datastream);
            //从字节流中获取id
            //int confid = datastream.ReadSInt32();
            //float objx = datastream.ReadSInt32() / 1000f;
            //float objy = datastream.ReadSInt32() / 1000f;
            int        confid = 0;
            float      objx = 0, objy = 0, objsx = 0, objsy = 0;
            MapObjConf objconf = null;
            GameObject column  = null;
            int        dataid  = datastream.ReadByte();
            string     goname  = "";
            while (dataid != 0)
            {
                switch (dataid)
                {
                case 1:
                    confid  = datastream.ReadSInt32();
                    objconf = ConfigManager.mapObjConfManager.map[confid];
                    break;

                case 2: objx = datastream.ReadSInt32() / 1000f; break;

                case 3: objy = datastream.ReadSInt32() / 1000f; break;

                case 4:
                    int parentid = datastream.ReadSInt32();
                    break;

                case 5:
                    int instanceid = datastream.ReadSInt32();
                    break;

                case 7: goname = datastream.ReadString16(); break;

                case 8:
                    objsx = datastream.ReadSInt32() / 1000f;
                    break;

                case 9:
                    objsy = datastream.ReadSInt32() / 1000f;
                    break;

                case 6:
                    if (objconf.isstatic == 1)
                    {
                        column = (GameObject)Resources.Load(objconf.path);
                        column = MonoBehaviour.Instantiate(column);
                        column.transform.parent   = mapObj.transform;
                        column.transform.position = GameCommon.GetWorldPos(pos) + new Vector2(objx, objy);
                        InGameBaseObj point = column.GetComponent <InGameBaseObj>();
                        point.Deserialize(datastream);
                        GameCommon.SetObjZIndex(column, objconf.depth);
                    }

                    break;
                }
                dataid = datastream.ReadByte();
            }

            if (confid == 4000002)
            {
                startPointList.Add(pos + GameCommon.GetMapPos(new Vector2(objx, objy)));
                continue;
            }
            if (objconf.isstatic == 1)
            {
                SetWayProperty(pos + GameCommon.GetMapPos(new Vector2(objx, objy)), objconf);
                column.transform.localScale = new Vector3(objsx, objsy, 1);
                continue;
            }

            SetGroupPoint(pos + GameCommon.GetMapPos(new Vector2(objx, objy)), objconf, new Vector3(objsx, objsy, 1));
        }
    }