public void Load() { datas.Clear(); dataMap.Clear(); dataGroupMap.Clear(); datas = ConfigManager.Load <MapGroupConf>(); for (int i = 0; i < datas.Count; i++) { MapGroupConf conf = datas[i]; dataMap.Add(conf.id, datas[i]); if (!dataGroupMap.ContainsKey(conf.group)) { dataGroupMap.Add(conf.group, new List <MapGroupConf>()); } dataGroupMap[conf.group].Add(conf); if (!dataWayGroupMap.ContainsKey(conf.group)) { dataWayGroupMap.Add(conf.group, new Dictionary <string, List <MapGroupConf> >()); } if (!dataWayGroupMap[conf.group].ContainsKey(conf.way)) { dataWayGroupMap[conf.group].Add(conf.way, new List <MapGroupConf>()); } dataWayGroupMap[conf.group][conf.way].Add(conf); } }
void GenerateGroup(MapTree tree) { string waystring = ""; if (tree.treetype == MapTree.MapTreeType.start) { waystring = "-1"; } else { waystring = GetTreeWayString(tree); } Dictionary <string, List <MapGroupConf> > conflist = ConfigManager.mapGroupConfManager.dataWayGroupMap[this.mapGroup]; if (!conflist.ContainsKey(waystring)) { Debug.Log(" no group : " + waystring); return; } List <MapGroupConf> mapList = conflist[waystring]; if (mapList.Count <= 0) { Debug.Log(" no group : " + waystring); return; } MapGroupConf conf = mapList[Random.Range(0, mapList.Count)]; InsertGroup(new Vector2(tree.pos.x * GameConst.RANDOM_GROUP_SIZE, tree.pos.y * GameConst.RANDOM_GROUP_SIZE), conf.id); for (int i = 0; i < tree.children.Count; i++) { this.GenerateGroup(tree.children[i]); } }
void SetObjPos(MapGroupConf conf) { int size = conf.size; int count = 0; while (count < row || count < col) { int x = count, y = count; if (count < row) { x = row; } if (count >= col) { y = col; } bool isfind = false; for (int i = 0; i < x; i++) { Vector2 v = new Vector2(i, y); if (haveSpace(v, size)) { SetSpace(v, size, conf.id); isfind = true; break; } } if (isfind) { break; } for (int i = 0; i < y; i++) { Vector2 v = new Vector2(x, i); if (haveSpace(v, size)) { SetSpace(v, size, conf.id); isfind = true; break; } } if (isfind) { break; } count++; } //for (int i = 0; i < row; i++) //{ // for (int j = 0; j < col; j++) // { // Vector2 v = new Vector2(i, j); // if (haveSpace(v, size)) // { // poslist.Add(v); // } // } //} }
public override void InitMap(int group, int row, int col) { base.InitMap(group, row, col); groundArr = new int[row, col]; List <MapGroupConf> conflist = ConfigManager.mapGroupConfManager.dataGroupMap[group]; if (conflist == null && conflist.Count <= 0) { Debug.LogError("no map conf!! group : " + group); return; } //放置group int count = row * col / 100; for (int i = 0; i < count; i++) { MapGroupConf conf = conflist[Random.Range(0, conflist.Count)]; SetObjPos(conf); } List <Vector2> poslist; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (groundArr[i, j] > 0) { InsertGroup(new Vector2(i, j), groundArr[i, j]); } } } //for (int x = 0; x < row; x++) //{ // for (int y = 0; y < col; y++) // { // int sx = x; // int sy = y; // InGameMapPointData data = map[sx, sy]; // if (data == null) // { // continue; // } // for (int i = 0; i < data.objList.Count; i++) // { // if (data.objList[i].obj == null) // { // GameObject obj = GetPoolObj(data.objList[i].conf); // obj.transform.position = GameCommon.GetWorldPos(data.objList[i].pos); // GameCommon.SetObjZIndex(obj, data.objList[i].conf.depth); // data.objList[i].obj = obj; // } // } // lastScreenObj.Add(data); // } //} //string s = ""; //for (int x = 0; x < row; x++) //{ // for (int y = 0; y < col; y++) // { // s += " " + astarArray[x, y]; // } // s += "\n"; //} //Debug.Log(s); if (startPointList.Count > 0) { startPoint = startPointList[Random.Range(0, startPointList.Count)]; } else { startPoint = GetRandomWay(); } }
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)); } }