コード例 #1
0
    public InGameBaseObj AddObj(string id)
    {
        InGameBaseObj objscript = MSBaseObject.CreateById(id) as InGameBaseObj;

        addList.Add(objscript);
        return(objscript);
    }
コード例 #2
0
    public void Start(MapData md)
    {
        this.md = md;

        foreach (KeyValuePair <int, MSBaseObject> pair in md.dic)
        {
            MSBaseObject obj   = pair.Value;
            bool         isadd = false;

            if (obj.itemid == "group")
            {
                continue;
            }
            //obj.gameObject.SetActive(false);
            for (int i = 0; i < objList.Count; i++)
            {
                MSBaseObject _obj = objList[i];
                if (obj.transform.position.y < _obj.transform.position.y)
                {
                    objList.Insert(i, obj);
                    isadd = true;
                    break;
                }
            }

            if (!isadd)
            {
                objList.Add(obj);
            }
        }
    }
コード例 #3
0
ファイル: MSBaseObject.cs プロジェクト: LiuFeng1011/DragOn
    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);
    }
コード例 #4
0
ファイル: MSBaseObject.cs プロジェクト: LiuFeng1011/DragOn
    public static MSBaseObject CreateById(string id)
    {
        //获取配置表文件

        GameObject go      = Resources.Load("Prefabs/MapObj/" + id) as GameObject;
        GameObject tempObj = (GameObject)Instantiate(go);

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

        baseobj.itemid = id;
        if (baseobj == null)
        {
            Debug.LogError(id + " : can`t find MSBaseObject script!");
            baseobj = tempObj.AddComponent <MSBaseObject>();
        }
        return(baseobj);
    }
コード例 #5
0
    public static MSBaseObject CreateById(int type, string id)
    {
        //获取配置表文件

        GameObject go      = Resources.Load("Prefabs/MapObj/" + id) as GameObject;
        GameObject tempObj = (GameObject)Instantiate(go);

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

        baseobj.itemtype = type;
        baseobj.itemid   = id;
        if (baseobj == null)
        {
            baseobj = tempObj.AddComponent <MSBaseObject>();
        }
        return(baseobj);
    }
コード例 #6
0
    static void ForeachObjAndSave(GameObject obj)
    {
        foreach (Transform child in obj.transform)
        {
            MSBaseObject msobj = child.GetComponent <MSBaseObject>();

            if (msobj == null)
            {
                //if(child.childCount <= 0) continue;
                //msobj = child.gameObject.AddComponent<MSBaseObject>();
                //msobj.myData.objID = -1;
                continue;
            }

            msobj.myData.Name = child.name;
            msobj.SaveData();
            msobj.myData.instanceID = child.GetInstanceID();
            msobj.parent            = child.parent.GetInstanceID();
            Debug.Log("obj : " + msobj.itemid);
            msobjlist.Add(msobj);

            ForeachObjAndSave(child.gameObject);
        }
    }
コード例 #7
0
ファイル: MapData.cs プロジェクト: LiuFeng1011/DragOn
    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);
        }
    }
コード例 #8
0
ファイル: MELoadLevelData.cs プロジェクト: LiuFeng1011/DragOn
    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);
        }
    }