2025-06-22 15:21:25 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public static class UtilityClass
|
|
|
|
|
|
{
|
|
|
|
|
|
public static bool IsPosValidFormat(string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 使用正则表达式判断格式是否为 x,y(正整数)
|
|
|
|
|
|
string pattern = @"^\d+,\d+$";
|
|
|
|
|
|
return Regex.IsMatch(value, pattern);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IsNumValidFormat(string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 使用正则表达式判断是否为正整数
|
|
|
|
|
|
string pattern = @"^\d+$";
|
|
|
|
|
|
return Regex.IsMatch(value, pattern);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static Vector2Int GetVector2Pos(string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsPosValidFormat(value))
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] parts = value.Split(',');
|
|
|
|
|
|
int x = int.Parse(parts[0]);
|
|
|
|
|
|
int y = int.Parse(parts[1]);
|
|
|
|
|
|
return new Vector2Int(x, y);
|
|
|
|
|
|
}
|
|
|
|
|
|
return Vector2Int.zero;
|
|
|
|
|
|
}
|
2025-07-18 22:28:40 +08:00
|
|
|
|
}
|