| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.Events; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | | using UnityEngine.Serialization; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Text.RegularExpressions; |
| | 8 | |
|
| | 9 | | public class CoordinateUtils |
| | 10 | | { |
| | 11 | | public const string COORDINATE_MATCH_REGEX = "[-]?\\d{1,3},[-]?\\d{1,3}"; |
| | 12 | | public const int MAX_X_COORDINATE = 163; |
| | 13 | | public const int MIN_X_COORDINATE = -150; |
| | 14 | | public const int MAX_Y_COORDINATE = 158; |
| | 15 | | public const int MIN_Y_COORDINATE = -150; |
| | 16 | |
|
| 0 | 17 | | public static bool IsCoordinateInRange(int x, int y) { return (x <= MAX_X_COORDINATE && x >= MIN_X_COORDINATE && y < |
| | 18 | |
|
| | 19 | | public static List<string> GetTextCoordinates(string text) |
| | 20 | | { |
| 42 | 21 | | Regex filter = new Regex(COORDINATE_MATCH_REGEX); |
| 42 | 22 | | List<string> matchingWords = new List<string>(); |
| 286 | 23 | | foreach (var item in text.Split(' ')) |
| | 24 | | { |
| 101 | 25 | | var match = filter.Match(item.ToString()); |
| | 26 | | int x; |
| | 27 | | int y; |
| 101 | 28 | | if (match.Success) |
| | 29 | | { |
| 0 | 30 | | Int32.TryParse(item.ToString().Split(',')[0], out x); |
| 0 | 31 | | Int32.TryParse(item.ToString().Split(',')[1], out y); |
| | 32 | |
|
| 0 | 33 | | if (IsCoordinateInRange(x, y)) |
| 0 | 34 | | matchingWords.Add(match.Value); |
| | 35 | | } |
| | 36 | | } |
| 42 | 37 | | return matchingWords; |
| | 38 | | } |
| | 39 | |
|
| | 40 | | public static bool HasValidTextCoordinates(string text) |
| | 41 | | { |
| 42 | 42 | | return GetTextCoordinates(text).Count > 0; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | public static ParcelCoordinates ParseCoordinatesString(string coordinates) |
| | 46 | | { |
| 0 | 47 | | return new ParcelCoordinates(Int32.Parse(coordinates.Split(',')[0]), Int32.Parse(coordinates.Split(',')[1])); |
| | 48 | | } |
| | 49 | | } |