public void findAttackRange(Transform root, int step, int maxStep) { if (root != null && (step > 0)) { Identy rootID = root.GetComponent <Identy>(); if (!rootID.River && !rootID.Trees) { if (maxStep < step) { return; } else if (maxStep == step) { if (rootID.step == 0 || rootID.step > step) { rootID.step = step; if (!AttackRangeList.Contains(root)) { AttackRangeList.Add(root); } } } else { if (rootID.step == 0 || rootID.step > step) { rootID.step = step; if (!AttackRangeList.Contains(root)) { AttackRangeList.Add(root); } foreach (Transform child in rootID.neighbor) { findAttackRange(child, step + 1, maxStep); } } } } } else if (root != null && (step == 0)) { Identy rootID = root.GetComponent <Identy>(); if (!rootID.River && !rootID.Trees) { if (maxStep < step) { return; } else if (maxStep == step) { if (rootID.step == 0 || rootID.step > step) { rootID.step = step; if (!AttackRangeList.Contains(root)) { AttackRangeList.Add(root); } } } else { if (rootID.step == 0 || rootID.step > step) { rootID.step = step; if (!AttackRangeList.Contains(root)) { AttackRangeList.Add(root); } foreach (Transform child in rootID.neighbor) { findAttackRange(child, step + 1, maxStep); } } } } } }
public void findMoveRange(Transform root, int step, int maxStep) { if (root != null && (step > 0)) { Identy rootID = root.GetComponent <Identy>(); if (!rootID.River && !rootID.Trees && !MapUtility.MapHelper.IsMapOccupied(root)) { if (maxStep < step) { return; } else if (maxStep == step) { if (rootID.step == 0 || rootID.step > step) { rootID.step = step; if (!MoveRangeList.Contains(root)) { MoveRangeList.Add(root); } } } else { if (rootID.step == 0 || rootID.step > step) { rootID.step = step; if (!MoveRangeList.Contains(root)) { MoveRangeList.Add(root); } foreach (Transform child in rootID.neighbor) { findMoveRange(child, step + 1, maxStep); } } } } } else if (root != null && (step == 0)) { Identy rootID = root.GetComponent <Identy>(); if (!rootID.River && !rootID.Trees) { if (maxStep < step) { return; } else if (maxStep == step) { if (rootID.step == 0 || rootID.step > step) { rootID.step = step; if (!MoveRangeList.Contains(root) && !MapUtility.MapHelper.IsMapOccupied(root)) { MoveRangeList.Add(root); } } } else { if (rootID.step == 0 || rootID.step > step) { rootID.step = step; if (!MoveRangeList.Contains(root) && !MapUtility.MapHelper.IsMapOccupied(root)) { MoveRangeList.Add(root); } foreach (Transform child in rootID.neighbor) { findMoveRange(child, step + 1, maxStep); } } } } } }
public IList FindPathList(Transform root, int maxStep, Transform destination) { IList pathList = new List <Transform>(); if (root != null) { Identy rootID = root.GetComponent <Identy>(); if (maxStep == 1) { pathList.Add(root); pathList.Add(destination); } else if (maxStep == 2) { pathList.Add(root); Dictionary <float, Transform> sortingDict = new Dictionary <float, Transform>(); foreach (Transform t in rootID.neighbor) { if (t != null) { Identy tID = t.GetComponent <Identy>(); if (!tID.River && !tID.Trees && !MapUtility.MapHelper.IsMapOccupied(t)) { float dis = Vector3.Distance(t.transform.position, destination.transform.position); if (!sortingDict.ContainsKey(dis)) { sortingDict.Add(dis, t); } } } } var list = sortingDict.Keys.ToList(); list.Sort(); Transform midPath = sortingDict[list[0]]; pathList.Add(midPath); pathList.Add(destination); } else if (maxStep == 3) { pathList.Add(root); Dictionary <float, Transform> sortingDict = new Dictionary <float, Transform>(); foreach (Transform t in rootID.neighbor) { if (t != null) { Identy tID = t.GetComponent <Identy>(); if (!tID.River && !tID.Trees && !MapUtility.MapHelper.IsMapOccupied(t)) { float dis = Vector3.Distance(t.transform.position, destination.transform.position); if (!sortingDict.ContainsKey(dis)) { sortingDict.Add(dis, t); } } } } var list = sortingDict.Keys.ToList(); list.Sort(); Transform midPath = sortingDict[list[0]]; pathList.Add(midPath); sortingDict.Clear(); list.Clear(); Identy midPathID = midPath.GetComponent <Identy>(); foreach (Transform t in midPathID.neighbor) { if (t != null) { Identy tID = t.GetComponent <Identy>(); if (!tID.River && !tID.Trees && !MapUtility.MapHelper.IsMapOccupied(t)) { float dis = Vector3.Distance(t.transform.position, destination.transform.position); if (!sortingDict.ContainsKey(dis)) { sortingDict.Add(dis, t); } } } } list = sortingDict.Keys.ToList(); list.Sort(); Transform midPathB = sortingDict[list[0]]; pathList.Add(midPathB); pathList.Add(destination); } } return(pathList); }