private static void CheckPathField(MonoBehaviour behaviour, FieldInfo field) { var attribute = field.GetCustomAttribute <PathAttribute>(); var value = field.GetValue <string>(behaviour); var path = attribute.isRelative ? UnityApp.MakeAbsolute(value) : value; var exists = attribute.isFile ? File.Exists(path) : Directory.Exists(path); if (exists == false && Settings.QuitForInvalidPaths) { Debug.LogError($"Invalid path \"{path}\" on the GameObject ({behaviour.name})."); UnityApp.Quit(); } }
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { BeginGUI(rect, property, label); var path = attribute.isRelative ? UnityApp.MakeAbsolute(property.stringValue) : property.stringValue; var exists = attribute.isFile ? File.Exists(path) : Directory.Exists(path); Rect textRect, buttonRect; SplitFromRight(28, out textRect, out buttonRect); var prevCol = SetColour(exists ? Pastel.Green : Pastel.Red); EditorGUI.PropertyField(textRect, property, Label); SetColour(prevCol); if (GUI.Button(buttonRect, "...")) { path = exists ? path : UnityApp.DataPath; if (attribute.isFile) { path = EditorUtility.OpenFilePanel("Select file...", path, ""); } else { path = EditorUtility.OpenFolderPanel("Select folder...", path, "") + "/"; } if (path == "" || path == "/") { return; } property.stringValue = attribute.isRelative ? UnityApp.MakeRelative(path, false) : path; } EndGUI(); }