public GameObject AddNpcPatrolPoint(float posx, float posy, float posz, GameObject obj) { BornInfo borninfo = obj.GetComponent <BornInfo>(); if (borninfo == null) { return(null); } if (!borninfo.CheckPatrolPoint((int)posx, (int)posy)) { return(null); } GameObject patrolpoint = InstantiatePrefabWithpos(posx, posy, posz, ref PatrolBorn); patrolpoint.transform.SetParent(obj.transform); patrolpoint.transform.localScale = new Vector3(0.4f, 0.4f, 0.01f); patrolpoint.name = "巡逻点"; PatrolPointInfo info = new PatrolPointInfo(); info.m_GridX = (int)posx; info.m_GridY = (int)posy; borninfo.m_PatrolInfo.Add(info); PatrolInfo patrol = patrolpoint.GetComponent <PatrolInfo>(); if (patrol != null) { patrol.m_GridX = info.m_GridX; patrol.m_GridY = info.m_GridY; } return(patrolpoint); }
public void SetPatrolPoint(int nIndex, int actionid, int x, int y, int waittime) { PatrolPointInfo partolpoint = m_PatrolInfo[nIndex]; partolpoint.m_ActionId = actionid; partolpoint.m_GridX = x; partolpoint.m_GridY = y; partolpoint.m_WaitTime = waittime; }
public int GetPatrolPointIndex(int x, int y) { for (int i = 0; i < m_PatrolInfo.Count; i++) { PatrolPointInfo point = m_PatrolInfo[i]; if (point.m_GridX == x && point.m_GridY == y) { return(i); } } return(-1); }
public bool CheckPatrolPoint(int x, int y) { for (int i = 0; i < m_PatrolInfo.Count; i++) { PatrolPointInfo point = m_PatrolInfo[i]; if (point.m_GridX == x && point.m_GridY == y) { return(false); } } return(true); }
private void Start() { var apostleManager = GetComponent <ApostleManager>(); this.apostleCollisionHandler = apostleManager.ApostleCollisionHandler; this.apostleStatusVariables = apostleManager.ApostleStatusVariables; if (GameManager.instance.NavigationAcessor == null) { GameManager.instance.NavigationAcessor = GameObject.FindGameObjectWithTag("Navigation").GetComponent <Navigation>(); } navigation = GameManager.instance.NavigationAcessor; CreateTriggerArea(); startPointPatrolInfo = new PatrolPointInfo(startPointTransform, startPointFloorCollider, startPointTransitionFloorType, navigation); endPointPatrolInfo = new PatrolPointInfo(endPointTransform, endPointFloorCollider, endPointTransitionFloorType, navigation); patrolTransitionFloorList = new List <TransitionFloor>(); var teste = new List <Floor>(); navigation.CalculatePath(startPointPatrolInfo.currentFloor, endPointPatrolInfo.currentFloor, teste); foreach (var floor in teste) { Debug.Log(floor); } currentAimNode = new NavigationNode(startPointTransform, TransitionFloorType.None, null); navigationNodes = new List <NavigationNode> { new NavigationNode(startPointTransform, TransitionFloorType.None, null), new NavigationNode(endPointTransform, TransitionFloorType.None, null), }; foreach (var transitionFloor in patrolTransitionFloorList) { if (transitionFloor.transform == null) { continue; } navigationNodes.Insert( navigationNodes.FindIndex(lambdaExpression => lambdaExpression.transform == endPointTransform), new NavigationNode(transitionFloor.transform, transitionFloor.type, transitionFloor.floors)); } }
void DrawBornInfo() { if (mo_ChooseObj == null) { return; } GUI.backgroundColor = Color.red; GUI.color = Color.yellow; GUI.skin.textField.fontSize = 15; GUI.skin.label.fontSize = 12; GUI.skin.box.fontSize = 15; EditorStyles.popup.fontSize = 12; EditorGUILayout.BeginVertical(); DrawBoxWithText("类型", GetTypeNameByObjectType((CreateObjType)mcs_Borninfo.m_eObjType)); if (name.Length > 0) { DrawBoxWithText("名字", name); } DrawBoxWithText("ID", mcs_Borninfo.mi_ObjId.ToString()); if (mcs_Borninfo.m_eObjType != 1)//不是功能NPC,就一定有强度 { m_minPower = DrawBoxWithInt("怪物限定最低强度:", mcs_Borninfo.m_minPower); mcs_Borninfo.m_minPower = m_minPower; m_maxPower = DrawBoxWithInt("怪物限定最低强度:", mcs_Borninfo.m_maxPower); mcs_Borninfo.m_maxPower = m_maxPower; m_groupId = DrawBoxWithInt("怪物组id:", mcs_Borninfo.mi_Group); mcs_Borninfo.mi_Group = m_groupId; } m_nRebornTime = DrawBoxWithInt("OBJ复活时间:", mcs_Borninfo.m_nRebornTime); mcs_Borninfo.m_nRebornTime = m_nRebornTime; Transform tran = mo_ChooseObj.transform; Vector2 pos = SceneEditorWindow._windowInstance.GetMapPosWith3DPos(tran.position.x, tran.position.y); DrawBoxWithInt("X坐标", (int)pos.x); DrawBoxWithInt("Y坐标", (int)pos.y); //tran.localPosition = new Vector3(posx, DrawBoxWithInt("Y坐标", posy) + 0.5f, tran.localPosition.z); int angel = GetAngelWithDireciton((enDirection)DrawBoxWithPop("朝向", (int)GetDirectionWithAngel(mcs_Borninfo.rotation), ref m_saDirection)); mcs_Borninfo.rotation = angel; if (mcs_Borninfo.m_eObjType == 1) { int graphDir = DrawBoxWithInt("图形朝向:", mcs_Borninfo.graphDir); mcs_Borninfo.graphDir = graphDir; } if (mcs_Borninfo.me_Type == CreateMode.enRegionObj) { m_nWidth = DrawBoxWithInt("随机范围Width:", mcs_Borninfo.m_nWidth); mcs_Borninfo.m_nWidth = m_nWidth; m_nHeight = DrawBoxWithInt("随机范围Height:", mcs_Borninfo.m_nHeight); mcs_Borninfo.m_nHeight = m_nHeight; m_SumonNum = DrawBoxWithInt("随机怪组数:", mcs_Borninfo.m_RegionNpcInfo.Count); //mcs_Borninfo.m_SumonNum = m_SumonNum; mcs_Borninfo.ReSizeRegionObj(m_SumonNum); for (int regionindex = 0; regionindex < mcs_Borninfo.m_RegionNpcInfo.Count; regionindex++) { int showindex = regionindex + 1; RegionObjInfo regionobj = mcs_Borninfo.m_RegionNpcInfo[regionindex]; int nID = DrawBoxWithInt("随机怪物" + showindex + "ID:", regionobj.ObjId); int nNum = DrawBoxWithInt("随机怪物" + showindex + "数量:", regionobj.Nums); int Time = DrawBoxWithInt("随机怪物" + showindex + "时间:", regionobj.Time); int Dir = DrawBoxWithInt("随机怪物" + showindex + "朝向:", regionobj.Dir); int nRate = DrawBoxWithInt("随机怪物" + showindex + "几率:", regionobj.Rate); regionobj.ObjId = nID; regionobj.Nums = nNum; regionobj.Time = Time; regionobj.Dir = Dir; regionobj.Rate = nRate; } } else { if (mcs_Borninfo.m_eObjType == 0) { m_nRebornTime = DrawBoxWithInt("重生时间", mcs_Borninfo.m_nRebornTime); mcs_Borninfo.m_nRebornTime = m_nRebornTime; m_nLiveTime = DrawBoxWithInt("生存时间", mcs_Borninfo.m_nLiveTime); mcs_Borninfo.m_nLiveTime = m_nLiveTime; int nRate = DrawBoxWithInt("几率:", mcs_Borninfo.m_nRate); mcs_Borninfo.m_nRate = nRate; m_nRoundType = DrawBoxWithIntPop("巡逻类型", mcs_Borninfo.m_RoundType, m_RoundType, m_sRoundType); mcs_Borninfo.m_RoundType = m_nRoundType; m_nRoundNum = DrawBoxWithInt("巡逻点数量", mcs_Borninfo.m_PatrolInfo.Count); mcs_Borninfo.ReSizePatrolPoint(m_nRoundNum); //巡逻点 for (int i = 0; i < mcs_Borninfo.m_PatrolInfo.Count; i++) { PatrolPointInfo point = mcs_Borninfo.m_PatrolInfo[i]; int WaitTime = DrawBoxWithInt(" 等待时间", point.m_WaitTime); int ActionId = DrawBoxWithInt(" 行为Id", point.m_ActionId); int gridx = DrawBoxWithInt(" X坐标", point.m_GridX); int gridy = DrawBoxWithInt(" Y坐标", point.m_GridY); point.m_WaitTime = WaitTime; point.m_ActionId = ActionId; //point.m_GridX = gridx; //point.m_GridY = gridy; } } if (mcs_Borninfo.m_eObjType == 1) { m_nMoveMode = DrawBoxWithIntPop("移动方式", mcs_Borninfo.m_nMoveMode, m_MoveMode, m_sMoveMode); mcs_Borninfo.m_nMoveMode = m_nMoveMode; m_nMoveRadius = DrawBoxWithInt("移动半径:", mcs_Borninfo.m_nMoveRadius); mcs_Borninfo.m_nMoveRadius = m_nMoveRadius; m_nRoundType = DrawBoxWithIntPop("巡逻类型", mcs_Borninfo.m_RoundType, m_RoundType, m_sRoundType); mcs_Borninfo.m_RoundType = m_nRoundType; m_nRoundNum = DrawBoxWithInt("巡逻点数量", mcs_Borninfo.m_PatrolInfo.Count); mcs_Borninfo.ReSizePatrolPoint(m_nRoundNum); //巡逻点 for (int i = 0; i < mcs_Borninfo.m_PatrolInfo.Count; i++) { PatrolPointInfo point = mcs_Borninfo.m_PatrolInfo[i]; int WaitTime = DrawBoxWithInt(" 等待时间", point.m_WaitTime); int ActionId = DrawBoxWithInt(" 行为Id", point.m_ActionId); int gridx = DrawBoxWithInt(" X坐标", point.m_GridX); int gridy = DrawBoxWithInt(" Y坐标", point.m_GridY); point.m_WaitTime = WaitTime; point.m_ActionId = ActionId; point.m_GridX = gridx; point.m_GridY = gridy; } } if (mcs_Borninfo.m_eObjType == 2) { int nRate = DrawBoxWithInt("几率:", mcs_Borninfo.m_nRate); mcs_Borninfo.m_nRate = nRate; m_nDelayBornTime = DrawBoxWithInt("延迟出生时间", mcs_Borninfo.m_nDelayBornTime); mcs_Borninfo.m_nDelayBornTime = m_nDelayBornTime; m_nTrapSceneId = DrawBoxWithInt("OBJ传送场景id:", mcs_Borninfo.m_nTrapSceneId); mcs_Borninfo.m_nTrapSceneId = m_nTrapSceneId; m_nPosX = DrawBoxWithInt("OBJ传送位置X:", mcs_Borninfo.m_nPosX); mcs_Borninfo.m_nPosX = m_nPosX; m_nPosY = DrawBoxWithInt("OBJ传送位置Y:", mcs_Borninfo.m_nPosY); mcs_Borninfo.m_nPosY = m_nPosY; } } EditorGUILayout.EndVertical(); RestorGuiSkin(); }
void ExportPointNpcInfo(string tablename, Transform parent, ref StreamWriter sw) { int index = 1; string key = tablename; for (int i = 0; i < parent.childCount; ++i) { Transform ChildTRF = parent.GetChild(i); BornInfo info = ChildTRF.GetComponent <BornInfo>(); key = tablename + "[" + (index++).ToString() + "]"; Vector2 mapPos = m_csPathGrid.GetMapPosByWordPos(ChildTRF.position.x, ChildTRF.position.y); int id = info.mi_Id; sw.WriteLine(key + "= {}"); sw.WriteLine(key + "['ID']" + " = " + i); sw.WriteLine(key + "['Type']" + " = " + info.m_eObjType); if (info.m_eObjType != 1) { sw.WriteLine(key + "['MinPower']" + " = " + info.m_minPower); sw.WriteLine(key + "['MaxPower']" + " = " + info.m_maxPower); } sw.WriteLine(key + "['ObjId']" + " = " + info.mi_ObjId); sw.WriteLine(key + "['Time'] = " + info.m_nRebornTime); sw.WriteLine(key + "['Dir']" + " = " + info.rotation); if (info.m_eObjType == 1) { sw.WriteLine(key + "['GraphicDir']" + " = " + info.graphDir); } sw.WriteLine(key + "['GridX']" + " = " + mapPos.x); sw.WriteLine(key + "['GridY']" + " = " + mapPos.y); sw.WriteLine(key + "['LiveTime'] = " + info.m_nLiveTime); sw.WriteLine(key + "['DelayBornTime'] = " + info.m_nDelayBornTime); sw.WriteLine(key + "['Rate'] = " + info.m_nRate); sw.WriteLine(key + "['RoundType'] = " + info.m_RoundType); sw.WriteLine(key + "['LinkID'] = " + info.mi_Group); sw.WriteLine(key + "['RoundNum'] = " + info.m_PatrolInfo.Count); if (info.m_PatrolInfo.Count > 0) { for (int k = 0; k < info.m_PatrolInfo.Count; k++) { int showKey = k; PatrolPointInfo patrolinfo = info.m_PatrolInfo[k]; sw.WriteLine(key + "['Round_" + showKey + "'] = {}"); sw.WriteLine(key + "['Round_" + showKey + "']['WaitTime'] = " + patrolinfo.m_WaitTime); sw.WriteLine(key + "['Round_" + showKey + "']['ActionID'] = " + patrolinfo.m_ActionId); sw.WriteLine(key + "['Round_" + showKey + "']['GridX'] = " + patrolinfo.m_GridX); sw.WriteLine(key + "['Round_" + showKey + "']['GridY'] = " + patrolinfo.m_GridY); } } else { sw.WriteLine(key + "['MoveMode'] = " + info.m_nMoveMode); sw.WriteLine(key + "['MoveRadius'] = " + info.m_nMoveRadius); } if (info.m_nTrapSceneId > 0) { sw.WriteLine(key + "['Tranp_SceneID'] = " + info.m_nTrapSceneId); sw.WriteLine(key + "['Tranp_PosX'] = " + info.m_nPosX); sw.WriteLine(key + "['Tranp_PosY'] = " + info.m_nPosY); sw.WriteLine(key + "['Tranp_Dir'] = " + 0); } } }
public void ImportNpcMapInfo(string filePath) { m_bOnImport = true; CreateMode mode = InteractionTool.GetNowCreateMode(); BornInfo info; int preid = InteractionTool.m_iChooseFunNpcId; InteractionTool.SetCanDraw(false); //fileName = fileName.Substring(filename.IndexOf("/Scene/") + "/Scene/".Length).Replace(".lua", ""); string fileName = filePath.Substring(filePath.IndexOf("/Map/") + 1).Replace(".lua", ""); object[] objarray = m_fLoadFunNpcFun.LazyCall(fileName); string sRegionNpcIdInfo = objarray[0].ToString(); LuaTable tRegionNpcInfo = (LuaTable)objarray[1]; string sPointNpcIdInfo = objarray[2].ToString(); LuaTable tPointNpcInfo = (LuaTable)objarray[3]; string sPathSetInfo = objarray[4].ToString(); LuaTable tPathSetInfo = (LuaTable)objarray[5]; string sScenePointInfo = objarray[6].ToString(); LuaTable tScenenPointInfo = (LuaTable)objarray[7]; string[] npcIdList = sRegionNpcIdInfo.Split(','); for (int i = 0; i < npcIdList.Length; i++) { int id = -1; if (!int.TryParse(npcIdList[i], out id)) { continue; } LuaTable npcInfo = (LuaTable)tRegionNpcInfo[id]; int Type = int.Parse(npcInfo["Type"].ToString()); int ID = int.Parse(npcInfo["ID"].ToString()); int GridX = int.Parse(npcInfo["GridX"].ToString()); int GridY = int.Parse(npcInfo["GridY"].ToString()); int GridW = int.Parse(npcInfo["GridW"].ToString()); int GridH = int.Parse(npcInfo["GridH"].ToString()); int summonNum = int.Parse(npcInfo["NpcSum"].ToString()); List <RegionObjInfo> regionObjInfo = new List <RegionObjInfo>(); int ObjId = 0; int Dir = 0; for (int key = 0; key < summonNum; key++) { int showkey = key + 1; LuaTable tNpc = (LuaTable)npcInfo["npc_" + showkey]; ObjId = int.Parse(tNpc["ObjId"].ToString()); int Nums = int.Parse(tNpc["Nums"].ToString()); Dir = int.Parse(tNpc["Dir"].ToString()); int Time = int.Parse(tNpc["Time"].ToString()); int nRate = 0; if (tNpc["Rate"] != null && tNpc["Rate"].ToString() != "") { nRate = int.Parse(tNpc["Rate"].ToString()); } RegionObjInfo newobj = new RegionObjInfo(); newobj.ObjId = ObjId; newobj.Nums = Nums; newobj.Dir = Dir; newobj.Time = Time; newobj.Per = 0; newobj.Rate = nRate; regionObjInfo.Add(newobj); } int minPower = 1; if (npcInfo["MinPower"] != null && npcInfo["MinPower"].ToString() != "") { minPower = int.Parse(npcInfo["MinPower"].ToString()); } int maxPower = 99; if (npcInfo["MaxPower"] != null && npcInfo["MaxPower"].ToString() != "") { maxPower = int.Parse(npcInfo["MaxPower"].ToString()); } GameObject obj = InteractionTool.AddReginNpc(GridX, GridY, -1, ObjId, (CreateObjType)Type, Dir); if (obj != null) { BornInfo bornInfo = obj.GetComponent <BornInfo>(); bornInfo.m_minPower = minPower; bornInfo.m_maxPower = maxPower; bornInfo.m_nWidth = GridW; bornInfo.m_nHeight = GridH; bornInfo.m_RegionNpcInfo = regionObjInfo; } } string[] funNpcIdList = sPointNpcIdInfo.Split(','); for (int i = 0; i < funNpcIdList.Length; i++) { int funnpcid = -1; if (!int.TryParse(funNpcIdList[i], out funnpcid)) { continue; } LuaTable funNpcInfo = (LuaTable)tPointNpcInfo[funnpcid]; int Type = int.Parse(funNpcInfo["Type"].ToString()); int ID = int.Parse(funNpcInfo["ID"].ToString()); int nTime = 0; if (funNpcInfo["Time"] != null && funNpcInfo["Time"].ToString() != "") { nTime = int.Parse(funNpcInfo["Time"].ToString()); } int nLiveTime = 0; if (funNpcInfo["LiveTime"] != null && funNpcInfo["LiveTime"].ToString() != "") { nLiveTime = int.Parse(funNpcInfo["LiveTime"].ToString()); } int nDelayBornTime = 0; if (funNpcInfo["DelayBornTime"] != null && funNpcInfo["DelayBornTime"].ToString() != "") { nLiveTime = int.Parse(funNpcInfo["DelayBornTime"].ToString()); } int nRate = 0; if (funNpcInfo["Rate"] != null && funNpcInfo["Rate"].ToString() != "") { nRate = int.Parse(funNpcInfo["Rate"].ToString()); } int nGraphicDir = 0; if (funNpcInfo["GraphicDir"] != null && funNpcInfo["GraphicDir"].ToString() != "") { nGraphicDir = int.Parse(funNpcInfo["GraphicDir"].ToString()); } int ObjId = int.Parse(funNpcInfo["ObjId"].ToString()); int GridX = int.Parse(funNpcInfo["GridX"].ToString()); int GridY = int.Parse(funNpcInfo["GridY"].ToString()); int Dir = int.Parse(funNpcInfo["Dir"].ToString()); int nTrapSceneId = 0; int nTrapPosX = 0; int nTrapPosY = 0; if (funNpcInfo["Tranp_SceneID"] != null && funNpcInfo["Tranp_SceneID"].ToString() != "") { nTrapSceneId = int.Parse(funNpcInfo["Tranp_SceneID"].ToString()); nTrapPosX = int.Parse(funNpcInfo["Tranp_PosX"].ToString()); nTrapPosY = int.Parse(funNpcInfo["Tranp_PosY"].ToString()); } int minPower = 1; if (funNpcInfo["MinPower"] != null && funNpcInfo["MinPower"].ToString() != "") { minPower = int.Parse(funNpcInfo["MinPower"].ToString()); } int maxPower = 99; if (funNpcInfo["MaxPower"] != null && funNpcInfo["MaxPower"].ToString() != "") { maxPower = int.Parse(funNpcInfo["MaxPower"].ToString()); } int RoundType = 0; if (funNpcInfo["RoundType"] != null && funNpcInfo["RoundType"].ToString() != "") { RoundType = int.Parse(funNpcInfo["RoundType"].ToString()); } int LinkID = 0; if (funNpcInfo["LinkID"] != null && funNpcInfo["LinkID"].ToString() != "") { LinkID = int.Parse(funNpcInfo["LinkID"].ToString()); } int RoundNum = 0; if (funNpcInfo["RoundNum"] != null && funNpcInfo["RoundNum"].ToString() != "") { RoundNum = int.Parse(funNpcInfo["RoundNum"].ToString()); } List <PatrolPointInfo> patrolInfo = new List <PatrolPointInfo>(); int MoveMode = 0; int MoveRadius = 0; if (RoundNum > 0) { for (int key = 0; key < RoundNum; key++) { LuaTable tRoundInfo = (LuaTable)funNpcInfo["Round_" + key.ToString()]; PatrolPointInfo patrolpoint = new PatrolPointInfo(); patrolpoint.m_WaitTime = int.Parse(tRoundInfo["WaitTime"].ToString()); patrolpoint.m_ActionId = int.Parse(tRoundInfo["ActionID"].ToString()); patrolpoint.m_GridX = int.Parse(tRoundInfo["GridX"].ToString()); patrolpoint.m_GridY = int.Parse(tRoundInfo["GridY"].ToString()); patrolInfo.Add(patrolpoint); } } else { if (funNpcInfo["MoveMode"] != null && funNpcInfo["MoveMode"].ToString() != "") { MoveMode = int.Parse(funNpcInfo["MoveMode"].ToString()); } if (funNpcInfo["MoveRadius"] != null && funNpcInfo["MoveRadius"].ToString() != "") { MoveRadius = int.Parse(funNpcInfo["MoveRadius"].ToString()); } } GameObject obj = InteractionTool.AddPointNpc(GridX, GridY, -1, ObjId, (CreateObjType)Type, Dir); if (obj != null) { BornInfo bornInfo = obj.GetComponent <BornInfo>(); bornInfo.m_nRebornTime = nTime; bornInfo.m_nTrapSceneId = nTrapSceneId; bornInfo.m_nPosX = nTrapPosX; bornInfo.m_nPosY = nTrapPosY; bornInfo.m_minPower = minPower; bornInfo.m_maxPower = maxPower; bornInfo.mi_Group = LinkID; bornInfo.m_RoundType = RoundType; bornInfo.m_nMoveMode = MoveMode; bornInfo.m_nMoveRadius = MoveRadius; bornInfo.m_nLiveTime = nLiveTime; bornInfo.m_nDelayBornTime = nDelayBornTime; bornInfo.m_nRate = nRate; bornInfo.graphDir = nGraphicDir; for (int n = 0; n < patrolInfo.Count; n++) { PatrolPointInfo point = patrolInfo[n]; InteractionTool.AddNpcPatrolPoint(point.m_GridX, point.m_GridY, -1, obj); } bornInfo.m_PatrolInfo = patrolInfo; } } Debug.Log("导入功能NPC文件完成:" + filePath); InteractionTool.SetCanDraw(true); InteractionTool.SetCreateMode(mode); m_bOnImport = false; SceneEditorWindow._windowInstance.m_sBornListPath = filePath; }