private void LoadFromText() { Global.mapobj_config_mgr.ReloadDataFromFile(textResourcesPath, EditionType.ALL, false); Global.mapobj_config_mgr.ForEach(delegate(MapObjectConfigReference moc) { if (moc.map == curMap.ID) { MPObject mp; if (moc.isRole) { mp = new MPRole(); } else { mp = new MPItem(); } try { mp.LoadFromText(moc); //mp.CreateGameObject(); mapObjs_.Add(mp.sn, mp); } catch (System.Exception exp) { errorCaught_ = true; Debug.Log(exp.Message); Debug.Log(exp.StackTrace); } } } ); }
void ApplyAIToObjectsWithSameID(MPRole role) { foreach (MPObject mo in mapObjs_.Values) { if (mo is MPRole && ((MPRole)mo).refid == role.refid) { ((MPRole)mo).aiRefid = role.aiRefid; } } }
MPObject CreateObject(Vector3 pos) { int refid; int.TryParse(editTargetID_, out refid); MPObject mapobj = null; //暂时使用同一个reference RoleReference reference = Global.role_mgr.GetReference(refid); if (reference == null) { Debug.Log("无此ID" + refid); return(null); } if (objectType_ == 2) { if (mapObjectResLoadPathStrFormat.Length <= 0) { Debug.Log("待添加物件资源路径"); return(null); } mapobj = new MPItem(); ((MPItem)mapobj).reference = reference; } else { mapobj = new MPRole(); ((MPRole)mapobj).reference = reference; } if (objectType_ == 0) { mapobj.ObjectType = "Monster"; } if (objectType_ == 1) { mapobj.ObjectType = "Npc"; } if (objectType_ == 2) { mapobj.ObjectType = "Object"; } mapobj.map = curMap.ID; mapobj.refid = refid; mapobj.apprId = reference.Apprid; mapobj.sn = GetUseableSN(); mapobj.ID = reference.ID; mapobj.CreateGameObject((a) => { mapObjs_[a.sn] = a; a.position = pos; }); return(mapobj); }
void DrawAllPath() { foreach (MPObject mpo in MapPlacementController.instance) { if (mpo is MPRole) { MPRole mpr = mpo as MPRole; if (mpr.routePointCount > 0) { DrawRolePath(mpr); } } } }
private void LoadFromXml(string filePath) { try { XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNodeList xnList = doc.DocumentElement.ChildNodes; foreach (XmlNode node in xnList) { XmlElement ele = node as XmlElement; MPObject mp; //Debug.Log( string.Format( "{0},{1}", ele.LocalName, ele.Name ) ); if (ele.Name == "Role") { mp = new MPRole(); } else if (ele.Name == "Item") { mp = new MPItem(); } else { mp = new MPObject(); } try{ mp.LoadFromXml(ele); //mp.CreateGameObject(); mapObjs_.Add(mp.sn, mp); } catch (System.Exception exp) { errorCaught_ = true; Debug.Log(exp.Message); Debug.Log(exp.StackTrace); } } lastSaveTime_ = Time.time; } catch (System.Exception exp) { Debug.Log(exp.ToString()); Debug.Log(exp.StackTrace); } }
private List <TemplateMapObjectConfig> PrepareSaveJson() { List <TemplateMapObjectConfig> objs = new List <TemplateMapObjectConfig>(); foreach (MPObject mpo in mapObjs_.Values) { TemplateMapObjectConfig tempConfig = new TemplateMapObjectConfig(); tempConfig.objType = mpo.ObjectType; tempConfig.refId = mpo.mocReference_.refid; tempConfig.pos = MyVector3.GetMyVector3(GameUtility.StrToVector3(mpo.mocReference_.position)); tempConfig.dir = MyVector3.GetMyVector3(GameUtility.StrToVector3(mpo.mocReference_.direction)); tempConfig.visible = mpo.available; tempConfig.sn = mpo.sn; tempConfig.isVisibleInMiddleMap = mpo.IsShowInMiddleMap; if (mpo.ObjectType != "Object") { MPRole mpoRole = mpo as MPRole; tempConfig.patrolType = mpoRole.patrolType.ToString(); tempConfig.patrolPath = new List <MyVector3>(); foreach (MPRole.RoutePoint point in mpoRole.routeList) { tempConfig.patrolPath.Add(MyVector3.GetMyVector3(point.position)); } tempConfig.camp = (int)mpoRole.camp; tempConfig.aiRefId = mpoRole.aiRefid; tempConfig.team = mpoRole.teamID; } else { MPItem mpItem = mpo as MPItem; tempConfig.team = mpItem.teamID; } objs.Add(tempConfig); //if (!Physics.Raycast(new Vector3(mpo.position.x, 10, mpo.position.z), Vector3.down, 200)) //{ // Debug.Log("物体坐标非法 sn:" + mpo.sn); //} } return(objs); }
void DrawRolePath(MPRole mpr) { BeforeUseGL(); GL.Color(Color.red); GL.Begin(GL.LINES); { GL.Vertex(mpr.position); GL.Vertex(mpr.routeList[0].position); for (int i = 0; i < mpr.routeList.Count - 1; i++) { GL.Vertex(mpr.routeList[i].position); GL.Vertex(mpr.routeList[i + 1].position); } } GL.End(); GL.Color(Color.blue); GL.Begin(GL.QUADS); for (int i = 0; i < mpr.routeList.Count; i++) { Vector3 orgPos = mpr.routeList[i].position; if (MapPlacementController.instance.curSelectRoutePoint == mpr.routeList[i]) { GL.Color(Color.yellow); } else { GL.Color(Color.blue); } for (int k = 0; k < 4; k++) { GL.Vertex(orgPos + dirForQuadsDraw_[k]); } } GL.End(); }
private IEnumerator LoadFromJson(string filePath) { if (!File.Exists(filePath)) { yield break; } StreamReader sr = File.OpenText(filePath); string json = sr.ReadToEnd(); sr.Close(); List <TemplateMapObjectConfig> objsRead = JsonMapper.ToObject <List <TemplateMapObjectConfig> >(json); if (objsRead == null) { yield break; } for (int i = 0; i < objsRead.Count; i++) { yield return(null);//每一个都延迟一帧执行,以免加载角色出错 MPObject mapObj = null; Vector3 positon = objsRead[i].pos.GetVector3(); Vector3 direction = objsRead[i].dir.GetVector3(); if (objsRead[i].objType != "Object") { mapObj = new MPRole(); } else { mapObj = new MPItem(); } mapObj.refid = objsRead[i].refId; mapObj.ObjectType = objsRead[i].objType; RoleReference reference = Global.role_mgr.GetReference(mapObj.refid); if (reference == null) { Debug.LogError(string.Format("无此role表Id:{0}", mapObj.refid)); } else { mapObj.apprId = reference.Apprid; } mapObj.map = curMap.ID; mapObj.sn = objsRead[i].sn; mapObj.ID = curMap.ID * 10000 + mapObj.sn; mapObjs_[mapObj.sn] = mapObj; mapObj.available = objsRead[i].visible; mapObj.camp = (MPObject.ObjectCamp)objsRead[i].camp; mapObj.IsShowInMiddleMap = objsRead[i].isVisibleInMiddleMap; if (mapObj.ObjectType != "Object") { MPRole mpRole = mapObj as MPRole; mpRole.reference = Global.role_mgr.GetReference(mpRole.refid); mpRole.teamID = objsRead[i].team; mpRole.patrolType = (MPRole.PatrolType)Enum.Parse(typeof(MPRole.PatrolType), objsRead[i].patrolType); foreach (MyVector3 myVec in objsRead[i].patrolPath) { mpRole.routeList.Add(new MPRole.RoutePoint(myVec.GetVector3(), 0)); } mpRole.aiRefid = objsRead[i].aiRefId; } else { MPItem item = mapObj as MPItem; item.reference = Global.role_mgr.GetReference(item.refid); item.teamID = objsRead[i].team; } //if (!Physics.Raycast(new Vector3(positon.x, 10, positon.z), Vector3.down, 200)) //{ // Debug.Log("物体坐标非法 sn:" + mapObj.sn); //} mapObj.CreateGameObject((a) => { mapObj.position = positon; mapObj.direction = direction; }); } }