示例#1
0
    public static MSBaseObject CreateObj(DataStream datastream)
    {
        //从字节流中获取id
        int    type = datastream.ReadSInt32();
        string id   = datastream.ReadString16();

        //获取配置表文件
        MSBaseObject baseobj = CreateById(id);

        baseobj.Deserialize(datastream);
        baseobj.init();

        return(baseobj);
    }
示例#2
0
    public virtual void Deserialize(DataStream datastream)
    {
        od.deserialize(datastream);

        GameObject  tGO = new GameObject("LevelOption");
        LevelOption me  = tGO.AddComponent <LevelOption>();

        od.SetLevelOption(me);

        GameCommon.LOAD_DATA_VERSION = od.version;

        int objcount = datastream.ReadSInt32();

        for (int i = 0; i < objcount; i++)
        {
            int    type = datastream.ReadSInt32();
            string id   = datastream.ReadString16();

            GameObject go;

            if (type == -1)
            {
                //组物体
                go = new GameObject("LevelOption");
            }
            else
            {
                Object tempObj = Resources.Load("Prefabs/MapObj/" + id) as GameObject;
                if (tempObj == null)
                {
                    Debug.Log(type + "/" + id + " is null!");
                    return;
                }
                go = (GameObject)MonoBehaviour.Instantiate(tempObj);
            }

            MSBaseObject baseobj = go.GetComponent <MSBaseObject>();

            if (baseobj == null)
            {
                baseobj = go.AddComponent <MSBaseObject>();
            }
            //baseobj.itemtype = type;
            baseobj.itemid = id;

            baseobj.Deserialize(datastream);
            baseobj.init();
            baseobj.Init();


            if (dic.ContainsKey(baseobj.parent))
            {
                go.transform.parent = dic[baseobj.parent].transform;
            }
            else
            {
                go.transform.parent = me.transform;
            }

            dic.Add(baseobj.myData.instanceID, baseobj);
        }
    }
示例#3
0
    public void ReloadScene(DataStream datastream)
    {
        Debug.Log("ReloadScene");

        MSLevelOptionDataModel od = new MSLevelOptionDataModel();

        od.deserialize(datastream);
        //od.version = (float)datastream.ReadSInt32() / 10000f;
        //od.levelName = datastream.ReadString16();
        //od.mapWidth = datastream.ReadSInt32();
        //od.mapHeight = datastream.ReadSInt32();


        List <GameObject> delarr = new List <GameObject>();
        LevelOption       me     = null;

        foreach (GameObject sceneObject in Object.FindObjectsOfType(typeof(GameObject)))
        {
            if (sceneObject.name == "LevelOption")
            {
                me = sceneObject.GetComponent <LevelOption>();
                od.SetLevelOption(me);

                GameCommon.LOAD_DATA_VERSION = od.version;
            }
            else if (sceneObject.name != "Main Camera" && sceneObject.name != "Directional light")
            {
                delarr.Add(sceneObject);
            }
        }

        //创建关卡配置物体
        if (me == null)
        {
            GameObject tGO = new GameObject("LevelOption");
            me = tGO.AddComponent <LevelOption>();
            od.SetLevelOption(me);
            GameCommon.LOAD_DATA_VERSION = od.version;
        }

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

        Dictionary <int, MSBaseObject> dic = new Dictionary <int, MSBaseObject>();

        Debug.Log("objcount : " + objcount);
        for (int i = 0; i < objcount; i++)
        {
            //MSBaseObject.CreateObj(datastream);
            //从字节流中获取id
            int    type = datastream.ReadSInt32();
            string id   = datastream.ReadString16();

            GameObject go;

            if (type == -1)
            {
                //组物体
                go = new GameObject("LevelOption");
            }
            else
            {
                Object tempObj = Resources.Load("Prefabs/MapObj/" + id) as GameObject;
                if (tempObj == null)
                {
                    Debug.Log(type + "/" + id + " is null!");
                }
                go = (GameObject)Instantiate(tempObj);
            }

            MSBaseObject baseobj = go.GetComponent <MSBaseObject>();

            if (baseobj == null)
            {
                baseobj = go.AddComponent <MSBaseObject>();
            }
            //baseobj.itemtype = type;
            baseobj.itemid = id;

            baseobj.Deserialize(datastream);
            baseobj.init();


            if (dic.ContainsKey(baseobj.parent))
            {
                go.transform.parent = dic[baseobj.parent].transform;
            }
            else
            {
                go.transform.parent = me.transform;
            }

            dic.Add(baseobj.myData.instanceID, baseobj);
        }
    }