33 lines
934 B
C#
33 lines
934 B
C#
#if UNITY_EDITOR
|
||
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;
|
||
}
|
||
}
|
||
#endif |