EditorUtilities.cs
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UnityEditor.XR.Management
{
internal static class EditorUtilities
{
internal static readonly string[] s_DefaultGeneralSettingsPath = {"XR"};
internal static readonly string[] s_DefaultLoaderPath = {"XR","Loaders"};
internal static readonly string[] s_DefaultSettingsPath = {"XR","Settings"};
internal static bool AssetDatabaseHasInstanceOfType(string type)
{
var assets = AssetDatabase.FindAssets(String.Format("t:{0}", type));
return assets.Any();
}
internal static string GetAssetPathForComponents(string[] pathComponents, string root = "Assets")
{
if (pathComponents.Length <= 0)
return null;
string path = root;
foreach( var pc in pathComponents)
{
string subFolder = Path.Combine(path, pc);
bool shouldCreate = true;
foreach (var f in AssetDatabase.GetSubFolders(path))
{
if (String.Compare(Path.GetFullPath(f), Path.GetFullPath(subFolder), true) == 0)
{
shouldCreate = false;
break;
}
}
if (shouldCreate)
AssetDatabase.CreateFolder(path, pc);
path = subFolder;
}
return path;
}
internal static string TypeNameToString(Type type)
{
return type == null ? "" : TypeNameToString(type.FullName);
}
internal static string TypeNameToString(string type)
{
string[] typeParts = type.Split(new char[] { '.' });
if (!typeParts.Any())
return String.Empty;
string[] words = Regex.Matches(typeParts.Last(), "(^[a-z]+|[A-Z]+(?![a-z])|[A-Z][a-z]+)")
.OfType<Match>()
.Select(m => m.Value)
.ToArray();
return string.Join(" ", words);
}
}
}