- 「RegexAttribute.cs」をUnityプロジェクトに追加します
- Unityプロジェクトに「Editor」フォルダが存在しない場合は作成します
- 「RegexDrawer.cs」をUnityプロジェクトの「Editor」フォルダに追加します
- 下記のような構文で使用します
using UnityEngine; public class MyBehaviourScript : MonoBehaviour { [Regex(@"^(?:\d{1,3}\.){3}\d{1,3}$", "Invalid IP address!\nExample: '127.0.0.1'")] public string ServerAddress; }
このRegexAttributeを使用すると、
Inspector上で設定できるstring型の値を正規表現を使用して制限することができます
http://blogs.unity3d.com/2012/09/07/property-drawers-in-unity-4/