public virtual void StartAction(InGameBaseObj target, Vector3 targetPos, int dis) { astarDis = dis; Vector3 _targetMapPos = GameCommon.GetMapPos(targetPos); if (_targetMapPos == targetMapPos) { return; } Vector2 startPos = GameCommon.GetMapPos(parent.transform.position); MazeMapManager gameMap = InGameManager.GetInstance().inGameLevelManager.gameMap; List <Vector2> _path = astar.StratAStar( gameMap.astarArray, startPos, GameCommon.GetMapPos(targetPos), dis); if (_path.Count <= 0) { return; } HandlePath(startPos, _path); path = _path; isaction = true; this.target = target; this.targetPos = targetPos; targetMapPos = _targetMapPos; atkTime = 0; state = ActionState.move; }
public override void HandleEvent(EventData resp) { base.HandleEvent(resp); switch (resp.eid) { case EventID.EVENT_GAME_CHARACTER_BORN: InGameBaseCharacter bornobj = (InGameBaseCharacter)resp.sUserData[0]; EnemyInfo info = new EnemyInfo(); info.character = bornobj; enemyInfoList.Add(info); break; case EventID.EVENT_GAME_CHARACTER_DIE: InGameBaseCharacter dieobj = (InGameBaseCharacter)resp.sUserData[0]; for (int i = 0; i < enemyInfoList.Count; i++) { if (enemyInfoList[i].character.instanceId == dieobj.instanceId) { Vector2 mapPos = GameCommon.GetMapPos(dieobj.transform.position); SetPixel((int)mapPos.x, (int)mapPos.y, dataArray[(int)mapPos.x, (int)mapPos.y]); enemyInfoList.RemoveAt(i); return; } } break; } }
public override void MUpdate() { base.MUpdate(); //更新小地图位置 Vector3 rolePos = InGameManager.GetInstance().inGamePlayerManager.GetRolePos(); Vector2 arrPos = GameCommon.GetMapPos(rolePos); float x = (float)arrPos.x / (float)uitexture.mainTexture.width; float y = (float)arrPos.y / (float)uitexture.mainTexture.height; uitexture.transform.localPosition = -1 * new Vector2(x * uitexture.width, y * uitexture.height); //update life if (Mathf.Abs(lifeTargetVal - lifeLine.fillAmount) > 0.01f) { lifeLine.fillAmount = lifeLine.fillAmount + (lifeTargetVal - lifeLine.fillAmount) * 0.1f; if (Mathf.Abs(lifeTargetVal - lifeLine.fillAmount) <= 0.01f) { lifeLine.fillAmount = lifeTargetVal; } } //update mana //update exp if (Mathf.Abs(expTargetVal - expLine.fillAmount) > 0.01f) { expLine.fillAmount = expLine.fillAmount + (expTargetVal - expLine.fillAmount) * 0.1f; if (Mathf.Abs(expTargetVal - expLine.fillAmount) <= 0.01f) { expLine.fillAmount = expTargetVal; } } }
public static void SetObjPos(GameObject obj, Vector3 pos) { InGameBaseObj ingameobj = obj.GetComponent <InGameBaseObj>(); if (ingameobj == null) { return; } if (ingameobj.GetObjType() != InGameBaseObj.enObjType.map) { return; } Vector2 mappos = GameCommon.GetMapPos(pos); obj.transform.position = GameCommon.GetWorldPos(mappos); MapObjConf conf = ConfigManager.GetEditorMapObjConfManager().map[ingameobj.confid]; if (conf == null) { return; } GameCommon.SetObjZIndex(obj, conf.depth); return; //MapEditor me = GameObject.Find("levelOption").transform.GetComponent<MapEditor>(); //if (me == null) //{ // EditorUtility.DisplayDialog("ERROR", "Cant't find the 'levelOption' !!", "ENTRY"); // return; //} }
void AddRangeEnemy() { if (enemyPointList.Count <= 0) { return; } List <int> objidList = new List <int>(); //将所有敌人随机插入到队列中 for (int i = 0; i < enemyPointList.Count; i++) { MapEnemyPointEnemy point = enemyPointList[i]; int enemycount = Random.Range(point.rangeMinCount, point.rangeMaxCount); for (int j = 0; j < enemycount; j++) { if (objidList.Count <= 0) { objidList.Add(point.rangeObjIdList[Random.Range(0, point.rangeObjIdList.Count)]); } else { objidList.Insert(Random.Range(0, objidList.Count), point.rangeObjIdList[Random.Range(0, point.rangeObjIdList.Count)]); } } } //向周围扩散加入敌人 int count = objidList.Count; int size = 1; Vector2 basepos = GameCommon.GetMapPos(transform.position); while (count >= 0) { for (int i = 0; i < size; i++) { count--; if (count < 0) { break; } Vector2 _pos = basepos + new Vector2(i, size - 1); AddObj(objidList[count], GameCommon.GetWorldPos(_pos)); count--; if (count < 0) { break; } _pos = basepos + new Vector2(size - 1, i); AddObj(objidList[count], GameCommon.GetWorldPos(_pos)); } size++; } }
void UpdateCharacterPos() { bool forceUpdate = updateData; //重置全部enemy位置信息 for (int i = 0; i < enemyInfoList.Count; i++) { EnemyInfo info = enemyInfoList[i]; Vector2 mapPos = GameCommon.GetMapPos(info.character.transform.position); //如果坐标位置没有改变 ,不做任何操作 if (((int)mapPos.x == info.x && (int)mapPos.y == info.y) && !forceUpdate) { info.isupdateInfo = false; } else { //设置更新标记 并 更新位置信息 SetPixel(info.x, info.y, dataArray[info.x, info.y]); info.x = (int)mapPos.x; info.y = (int)mapPos.y; info.isupdateInfo = true; updateData = true; } } //重新绘制enemy位置信息 for (int i = 0; i < enemyInfoList.Count; i++) { EnemyInfo info = enemyInfoList[i]; if (info.isupdateInfo) { if (info.character.camp == enMSCamp.en_camp_enemy) { if (info.character.GetIsElite()) { SetPixel(info.x, info.y, MazeCreate.PointType.enemyelitepoint); } else { SetPixel(info.x, info.y, MazeCreate.PointType.enemypoint); } } else { SetPixel(info.x, info.y, MazeCreate.PointType.rolepoint); } } } }
public InGameBaseEquip OutEquip(GameObject go, int level, float fm) { EquipConf equipConf = ConfigManager.equipConfManager.GetRandomEquip(); GameObject equipobj = (GameObject)Resources.Load(equipConf.prefabpath + equipConf.prefabname); equipobj = MonoBehaviour.Instantiate(equipobj); equipobj.transform.position = GameCommon.GetWorldPos(GameCommon.GetMapPos(go.transform.position)); GameCommon.SetObjZIndex(equipobj, 3.1f); InGameBaseEquip equip = equipobj.GetComponent <InGameBaseEquip>(); equip.Init(-1, equipConf.id, enMSCamp.en_camp_item); equip.level = level; equip.quality = ConfigManager.equipQualityManager.GetEquipQuality(fm); EquipOutAction equipOutAction = equipobj.AddComponent <EquipOutAction>(); equipOutAction.Init(equipobj.transform.position); return(equip); }
public override bool ObjUpdate() { if (source == null) { SetDie(true); return(false); } //Debug.Log("move vec : " + moveVector); transform.position = transform.position + moveVector * Time.deltaTime * 10; GameCommon.SetObjZIndex(gameObject, 3); if (Vector2.Distance(startPos, transform.position) > 20) { SetDie(true); return(false); } Vector3 collisionpos = transform.position - additionPos; //游戏物体碰撞 List <InGameBaseObj> list = InGameManager.GetInstance().inGameObjManager.GetObjListByDistance(collisionpos, 0.5f); for (int i = 0; i < list.Count; i++) { if (HitGameObj(list[i])) { return(false); } } //地图碰撞 Vector2 mapos = GameCommon.GetMapPos(collisionpos); if (InGameManager.GetInstance().inGameLevelManager.gameMap.GetPointType((int)mapos.x, (int)mapos.y) == MazeCreate.PointType.wall) { SetDie(true); return(false); } return(base.ObjUpdate()); }
//从地图中删除一个障碍 public void DelMapObj(Vector3 pos, MapObjConf conf) { Vector2 startMapPos = GameCommon.GetMapPos(pos); int startX = (int)startMapPos.x; int startY = (int)startMapPos.y; InGameMapPointData data = map[startX, startY]; for (int i = 0; i < data.objList.Count; i++) { MapPointObj mapPointObj = data.objList[i]; if (mapPointObj.obj == null) { if (mapPointObj.conf.id == conf.id) { AddPoolObj(conf.id, mapPointObj.obj); data.objList.RemoveAt(i); if (map[startX, startX].type == MazeCreate.PointType.wallfull) { continue; } if (mapPointObj.conf.depth >= 3) { map[startX, startX].type = MazeCreate.PointType.wallfull; astarArray[startX, startX] = 0; } else { map[startX, startX].type = MazeCreate.PointType.way; astarArray[startX, startX] = 1; } } } } }
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)); } }
//动态生成地面 public override void Update() { smallMap.Update(); Vector2 startPos = InGameManager.GetInstance().inGameCameraManager.GetCameraPos(); Vector2 startMapPos = GameCommon.GetMapPos(startPos); int startX = (int)startMapPos.x - UPDATE_MAP_SIZE / 2; int startY = (int)startMapPos.y - UPDATE_MAP_SIZE / 2; for (int i = 0; i < lastScreenObj.Count; i++) { Vector2 pos = lastScreenObj[i].pos; if (pos.x >= startX && pos.x < startX + UPDATE_MAP_SIZE && pos.y >= startY && pos.y < startY + UPDATE_MAP_SIZE) { continue; } List <MapPointObj> _list = lastScreenObj[i].objList; for (int j = 0; j < _list.Count; j++) { if (_list[j].obj == null) { continue; } AddPoolObj(_list[j].conf.id, _list[j].obj); _list[j].obj = null; } } lastScreenObj.Clear(); for (int x = 0; x < UPDATE_MAP_SIZE; x++) { for (int y = 0; y < UPDATE_MAP_SIZE; y++) { int sx = startX + x; int sy = startY + y; int _x = UPDATE_MAP_SIZE / 2 - x; int _y = UPDATE_MAP_SIZE / 2 - y; if (sx < 0 || sx >= map.GetLength(0)) { break; } if (sy < 0 || sy >= map.GetLength(1)) { continue; } bool isopen = false; //小地图中的点是否打开,如果已经打开 则不用计算距离 if (!smallMap.IsOpenPoint(sx, sy)) { if (Mathf.Sqrt(_x * _x + _y * _y) <= UPDATE_MAP_SIZE / 2) { isopen = true; } } InGameMapPointData data = map[sx, sy]; if (data == null) { if (isopen) { smallMap.OpenUnit(sx, sy, MazeCreate.PointType.nullpoint); } continue; } if (isopen) { smallMap.OpenUnit(sx, sy, data.type); } for (int i = 0; i < data.objList.Count; i++) { if (data.objList[i].obj == null) { MapPointObj mapPointObj = data.objList[i]; InGameBaseMapObj obj = GetPoolObj(mapPointObj.conf); obj.transform.position = GameCommon.GetWorldPos(mapPointObj.pos) + new Vector2(0, Random.Range(0, 0.1f)); obj.transform.localScale = mapPointObj.scale; GameCommon.SetObjZIndex(obj.gameObject, mapPointObj.conf.depth); mapPointObj.obj = obj; obj.Show(); mapObjActionList.Add(obj); } } lastScreenObj.Add(data); } } //处理mapobj 动画 for (int i = mapObjActionList.Count - 1; i >= 0; i--) { InGameBaseMapObj obj = mapObjActionList[i]; obj.ActionUpdate(); if (!obj.isAction) { mapObjActionList.RemoveAt(i); } } }