Files
HX_MapEditor/Assets/Scripts/Map/UtilityClass.cs
2025-07-18 22:28:40 +08:00

31 lines
910 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}