//设置某个圆形区域的显示状态(每种类型只能显示一个) public void SetCircularRangeRenderStateActive(bool active, GridRenderType gridRenderType, int centerRow = -1, int centerColumn = -1, int radius = -1) { //确定是哪种范围 List <GridUnit> rangeHighlightGridUnits = null; switch (gridRenderType) { case GridRenderType.MoveRange: if (centerRow != -1 && centerColumn != -1) { BattleUnit battleUnit = fieldRenderer.battleField.battleMap.GetGridData(centerRow, centerColumn).battleUnit; moveRangeGridUnits = MapNavigator.Instance.GetAccessibleGrids(battleUnit, fieldRenderer.battleField.battleMap); } rangeHighlightGridUnits = moveRangeGridUnits; break; case GridRenderType.SkillReleaseRange: rangeHighlightGridUnits = skillReleaseRangeGridUnits; break; case GridRenderType.SkillEffectRange: rangeHighlightGridUnits = skillEffectRangeGridUnits; break; default: UtilityHelper.LogError(string.Format("SetRangeHighlightActive error grid render type : {0}", gridRenderType)); return; } //当前是取消激活 if (!active) { for (int i = 0; i < rangeHighlightGridUnits.Count; ++i) { if (rangeHighlightGridUnits[i].gridUnitRenderer != null) { rangeHighlightGridUnits[i].gridUnitRenderer.RemoveGridRenderType(gridRenderType); } } //rangeHighlightGridUnits.Clear(); } else { //当前存在上一个激活,先隐藏 if (rangeHighlightGridUnits.Count > 0) { SetCircularRangeRenderStateActive(false, gridRenderType); } //获取格子 if (gridRenderType != GridRenderType.MoveRange) { fieldRenderer.battleField.battleMap.GetCircularGrids(centerRow, centerColumn, radius, 0, true, rangeHighlightGridUnits); } //设置高亮状态 for (int i = 0; i < rangeHighlightGridUnits.Count; ++i) { if (rangeHighlightGridUnits[i].gridUnitRenderer != null) { rangeHighlightGridUnits[i].gridUnitRenderer.AppendGridRenderType(gridRenderType); } } } }
//点击了技能,在以固定地点为原点的技能情况下 private void OnBattleUnitAndGridTouched_StateSkill_GridUnitTarget(GridUnit gridTouched, BattleUnit battleUnitTouched) { //如果当前有点中的格子 if (selectedGridUnitRenderer != null && (selectedGridUnitRenderer.Equals(gridTouched.gridUnitRenderer) || usedManualReleaseAnalysisor.battleSkill.GetReleaseRadius(usedManualReleaseAnalysisor.releaser.mapGrid) <= 0)) { //如果当前的释放距离为0,表示无需二次点击确认,直接释放 if (usedManualReleaseAnalysisor.battleSkill.GetReleaseRadius(usedManualReleaseAnalysisor.releaser.mapGrid) <= 0) { ManualSkill(manualOperatingBattleUnitRenderer.battleUnit.mapGrid); return; } //点中了重复的格子,判断是否有目标 bool hasTarget = false; for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { if (usedManualReleaseAnalysisor.suitableUnits[i].mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.effectRadius) { hasTarget = true; break; } } //有目标,则释放 if (hasTarget) { ManualSkill(gridTouched); } else { UtilityHelper.Log("范围内没有目标"); } } else { //这个格子不在范围内 if (manualOperatingBattleUnitRenderer.battleUnit.mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.GetReleaseRadius(usedManualReleaseAnalysisor.releaser.mapGrid)) { if (selectedGridUnitRenderer != null) { //取消上一个范围显示 SetCircularRangeRenderStateActive(false, GridRenderType.SkillEffectRange); //取消可被攻击单位的显示 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } } //设置新的范围显示 selectedGridUnitRenderer = gridTouched.gridUnitRenderer; SetCircularRangeRenderStateActive( true, GridRenderType.SkillEffectRange, gridTouched.row, gridTouched.column, usedManualReleaseAnalysisor.battleSkill.effectRadius ); //设置新的可被攻击单位的显示 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { if (usedManualReleaseAnalysisor.suitableUnits[i].mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.effectRadius) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected); } } } else { UtilityHelper.Log("超出区域"); UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } } }
//某个战斗单位点击了使用技能 public void BattleUnitUseSkill(BattleUnit battleUnit, SO_BattleSkill skill) { if (battleUnit == null || battleUnit.battleUnitRenderer == null || !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer)) { UtilityHelper.LogError("Battle unit use skill failed."); HideManualActionList(); return; } //获取推算的技能释放结果 usedManualReleaseAnalysisor = BattleCalculator.Instance.ManualReleaseAnalysisor; //分析结果 usedManualReleaseAnalysisor.Analysis(manualOperatingBattleUnitRenderer.battleUnit, skill); //显示技能释放范围 if (skill.GetReleaseRadius(battleUnit.mapGrid) > 0) { SetCircularRangeRenderStateActive( true, GridRenderType.SkillReleaseRange, battleUnit.mapGrid.row, battleUnit.mapGrid.column, skill.GetReleaseRadius(battleUnit.mapGrid)); } //根据类型判断技能显示状态 switch (skill.targetType) { //对单个目标 case BattleSkillTargetType.BattleUnit: //可以被选中的 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selectable); } //不可以被选中的 for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i) { usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable); } //队伍不合适的 for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i) { usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } //设定技能操作类型 skillOperationType = skill.effectRadius > 0 ? SkillOperationType.SurroundBattleUnit : SkillOperationType.SingleBattleUnitTarget; break; //对范围(某一个位置)目标 case BattleSkillTargetType.GridUnit: skillOperationType = SkillOperationType.GridUnitTarget; //如果没有位置可选,则直接打开范围 if (skill.GetReleaseRadius(battleUnit.mapGrid) <= 0) { //可以被选中,标记为已被选中 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected); } //不可以被选中的 for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i) { usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable); } //队伍不合适的 for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i) { usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } OnBattleUnitAndGridTouched_StateSkill_GridUnitTarget(battleUnit.mapGrid, null); } else { //需要指定范围,需要点击目标地块 } break; //以自身为中心的 case BattleSkillTargetType.Self: //可以被选中,标记为已被选中 for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i) { usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected); } //不可以被选中的 for (int i = 0; i < usedManualReleaseAnalysisor.distanceLimit.Count; ++i) { usedManualReleaseAnalysisor.distanceLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.NotSelectable); } //队伍不合适的 for (int i = 0; i < usedManualReleaseAnalysisor.teamLimit.Count; ++i) { usedManualReleaseAnalysisor.teamLimit[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal); } skillOperationType = SkillOperationType.SurroundSelf; //省去一步点击操作,直接展示区域 OnBattleUnitAndGridTouched_StateSkill_SurroundSelf(battleUnit.mapGrid, battleUnit); break; default: break; } //切换操作状态 manualOperationState = ManualOperationState.Skill; HideManualActionList(); }
//点击了地块、战斗单位 -- 在当前是选择移动目标的情况下 private void OnBattleUnitAndGridTouched_StateMove(GridUnit gridTouched, BattleUnit battleUnitTouched) { //点中了战斗单位 if (battleUnitTouched != null) { //显示战斗单位的详情 UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } //点中了地图 else { //障碍物不能作为移动目标(暂时) if (gridTouched.GridType == GridType.Obstacle) { UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } else { //点击是否超出了范围 GridUnit fromGrid = manualOperatingBattleUnitRenderer.battleUnit.mapGrid; if (fromGrid.Distance(gridTouched) > manualOperatingBattleUnitRenderer.battleUnit.battleUnitAttribute.mobility) { UtilityHelper.Log("超出了移动半径!"); UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } else { MapNavigator.Instance.NewNavigate( manualOperatingBattleUnitRenderer.battleUnit, fieldRenderer.battleField.battleMap, fromGrid, gridTouched, UtilityObjs.gridUnits); //判断移动是否可以到达 //bool result = MapNavigator.Instance.Navigate( // fieldRenderer.battleField.battleMap, // fromGrid, // gridTouched, // UtilityObjs.gridUnits, // null, // manualOperatingBattleUnitRenderer.battleUnit.battleUnitAttribute.mobility // ); bool result = MapNavigator.Instance.NewNavigate( manualOperatingBattleUnitRenderer.battleUnit, fieldRenderer.battleField.battleMap, fromGrid, gridTouched, UtilityObjs.gridUnits); //判断是否可以到达(导航成功且可以可以到达) if (result && UtilityObjs.gridUnits[UtilityObjs.gridUnits.Count - 1].Equals(gridTouched)) { //可以到达 ManualMoveTo(gridTouched, UtilityObjs.gridUnits.ToArray()); UtilityObjs.gridUnits.Clear(); } else { //不可以到达 UtilityHelper.Log("点击位置不可到达!"); UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched); } } } } }
public static BattleMap ReadBattleMapFromXML(string xmlFilePath) { TextAsset xmlfile = Resources.Load(xmlFilePath) as TextAsset; if (!xmlfile) { UtilityHelper.LogFormat("Load {0} xml file failed!", xmlFilePath); return(null); } int mapWidth = 0; int mapHeight = 0; GridUnit[,] gridMap = null; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlfile.text); XmlNodeList xmlNodeList = xmlDoc.SelectSingleNode("MapBaseMsg").ChildNodes; XmlNodeList mapMsgList = null; foreach (XmlElement xmlElement in xmlNodeList) { switch (xmlElement.Name) { case ("Width"): mapWidth = Convert.ToInt32(xmlElement.InnerText); break; case ("Height"): mapHeight = Convert.ToInt32(xmlElement.InnerText); break; case ("GridMsg"): mapMsgList = xmlElement.ChildNodes; break; } } BattleMap battleMap = new BattleMap(mapWidth, mapHeight); foreach (XmlElement gridUnitInfo in mapMsgList) { int posX = 0, posY = 0; GridAttribute gridAttribute = new GridAttribute(); foreach (XmlElement xmlElement in gridUnitInfo.ChildNodes) { switch (xmlElement.Name) { case ("PosX"): posX = Convert.ToInt32(xmlElement.InnerText); break; case ("PosY"): posY = Convert.ToInt32(xmlElement.InnerText); break; case ("Name"): gridAttribute.m_Name = Convert.ToString(xmlElement.InnerText); break; case ("Avoid"): gridAttribute.m_Avoid = Convert.ToSingle(xmlElement.InnerText); break; case ("Defense"): gridAttribute.m_Defense = Convert.ToSingle(xmlElement.InnerText); break; case ("Height"): gridAttribute.m_Height = Convert.ToSingle(xmlElement.InnerText); break; case ("MaxPassVolume"): gridAttribute.m_MaxPassVolume = Convert.ToSingle(xmlElement.InnerText); break; case ("CrossCost"): gridAttribute.m_CrossCost = Convert.ToSingle(xmlElement.InnerText); break; case ("GridType"): gridAttribute.SetGridType(Convert.ToString(xmlElement.InnerText)); break; } } GridUnit gridUnit = battleMap.mapGrids[posX - 1, posY - 1]; if (gridUnit == null) { gridUnit = new GridUnit(battleMap, posY - 1, posX - 1); battleMap.mapGrids[posX - 1, posY - 1] = gridUnit; } gridUnit.column = posX - 1; gridUnit.row = posY - 1; gridUnit.m_GridAttribute = gridAttribute; gridUnit.localPosition = new Vector3(posX * EGameConstL.Map_GridWidth, -posY * EGameConstL.Map_GridOffsetY, 0); if (gridUnit.m_GridAttribute.m_GridType == GridType.Normal) { battleMap.normalGrids.Add(gridUnit); } else if (gridUnit.m_GridAttribute.m_GridType == GridType.Obstacle) { battleMap.obstacleGrids.Add(gridUnit); } } return(battleMap); }