void MoveAction() { Vector3 tp = GameCommon.GetWorldPos(path[0]); float dis = Vector2.Distance(parent.transform.position, tp); if (dis <= parent.GetMoveSpeed() * Time.deltaTime) { SetPathPos(); if (path.Count <= 0) { parent.StopAction(); } else { parent.Move(path[0]); } return; } else { parent.Move(path[0]); parent.SetAnimatorState(InGameBaseCharacter.AnimatorState.Run, parent.GetMoveSpeed() * 0.6f); } }
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; //} }
public override void Update() { for (int i = 0; i < enemyPoints.Count; i++) { enemyPoints[i].ObjUpdate(); } for (int i = enemyList.Count - 1; i >= 0; i--) { if (enemyList[i] == null) { enemyList.RemoveAt(i); } } List <CharacterConf> roleList = ConfigManager.characterConfManager.dicByType[(int)CharacterConf.enCharacterType.enemy]; while (enemyList.Count < 5) { //InGameBaseCharacter enemy = InGameManager.GetInstance().inGameObjManager.AddObj(roleList[Random.Range(0, roleList.Count)].id, enMSCamp.en_camp_enemy) as InGameBaseCharacter; InGameBaseCharacter enemy = InGameManager.GetInstance().inGameObjManager.AddObj(100008, enMSCamp.en_camp_enemy) as InGameBaseCharacter; //100011 enemy.AddAI(); Vector3 pos = InGameManager.GetInstance().inGameLevelManager.gameMap.GetRandomWay(); enemy.transform.position = GameCommon.GetWorldPos(pos); enemy.SetZPos(); enemyList.Add(enemy); } }
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 CreateRocks(Vector3 v) { GameObject column = (GameObject)Resources.Load("Prefabs/MapObj/rocks_" + Random.Range(0, 8)); column = MonoBehaviour.Instantiate(column); column.transform.position = GameCommon.GetWorldPos(v) * mapscale; column.transform.position += new Vector3(0, 0, v.y); column.transform.localScale = new Vector3(mapscale, mapscale, mapscale); }
public virtual void Move(Vector3 targetpos) { targetpos = GameCommon.GetWorldPos(targetpos); Vector3 v = (targetpos - new Vector3(transform.position.x, transform.position.y)).normalized; transform.position += v * Time.deltaTime * this.GetMoveSpeed(); SetDir(v.x); }
GameObject CreateGround(Vector3 v, int scale) { GameObject column = (GameObject)Resources.Load("Prefabs/MapObj/MapGround_1_" + scale + "_" + 0); column = MonoBehaviour.Instantiate(column); column.transform.position = GameCommon.GetWorldPos(v) * mapscale; column.transform.position += new Vector3(0, 0, v.y - v.x + 100); column.transform.localScale = new Vector3(mapscale, mapscale, mapscale); return(column); }
static void OrderSelObjList() { GameObject[] go = Selection.gameObjects; for (int i = 0; i < go.Length; i++) { Transform transform = go[i].transform; int size = (int)Mathf.Sqrt(transform.childCount); for (int j = 0; j < transform.childCount; j++) { Transform child = transform.GetChild(j); child.transform.localPosition = GameCommon.GetWorldPos(new Vector3(j / size, j % size, 0)); } } }
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 void Init() { base.Init(); EventManager.Register(this, EventID.EVENT_GAME_TOUCH_GROUND, EventID.EVENT_GAME_TOUCH_OBJ, EventID.EVENT_UI_EQUIP, EventID.EVENT_UI_DELEQUIP, EventID.EVENT_UI_UNEQUIP, EventID.EVENT_DATA_REFRESHPROPERTY); RoleData rd = UserDataManager.instance.GetChooseRoleData(); role = InGameManager.GetInstance().inGameObjManager.AddObj(rd.roldid,enMSCamp.en_camp_player) as InGameBaseCharacter; role.SetData(rd); //InGameManager.GetInstance().GetManager<InGameObjManager>(InGameManager.enGameManager.InGameObjManager).AddObj(0); Vector3 startpos = InGameManager.GetInstance().inGameLevelManager.gameMap.GetStartPosition(); role.transform.position = GameCommon.GetWorldPos(startpos); role.SetZPos(); InGameManager.GetInstance().inGameCameraManager.SetTarget(role.gameObject); for (int i = 0; i < rd.choseEquipList.Count; i++) { if (rd.choseEquipList[i] == -1) continue; EquipData edata = UserDataManager.instance.GetEquip(rd.choseEquipList[i]); role.AddEquip(edata); } //UserDataManager.instance.AddLevelupPoint(role.GetData().instanceid,5); role.ResetAllProperty(true); EventData.CreateEvent(EventID.EVENT_GAME_INITROLE).AddData(role).Send(); }
public void DrawBGLine() { #if UNITY_EDITOR Gizmos.color = insideColor; for (float y = 0; y < lo.mapHeight; y++) { Gizmos.DrawLine(GameCommon.GetWorldPos(new Vector3(0, y, -1f)), GameCommon.GetWorldPos(new Vector3(lo.mapWidth - 1, y, -1f))); //Handles.Label(new Vector3(-1f,y+0.5f , 0f), "" + y); } for (float x = 0; x < lo.mapWidth; x++) { Gizmos.DrawLine(GameCommon.GetWorldPos(new Vector3(x, 0, -1f)), GameCommon.GetWorldPos(new Vector3(x, lo.mapHeight - 1, -1f))); //Handles.Label(new Vector3(x,-0.2f, 0f), "" + x); } Gizmos.color = sideColor; #endif }
void SetPathPos() { this.targetPos = GameCommon.GetWorldPos(path[0]); path.RemoveAt(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)); } }
//动态生成地面 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); } } }