-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicBonesStubInstaller.cs
57 lines (48 loc) · 2.14 KB
/
DynamicBonesStubInstaller.cs
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
#if UNITY_EDITOR
using System;
using System.IO;
using System.Linq;
using UnityEditor;
[InitializeOnLoad]
public class DynamicBonesStubInstaller
{
static DynamicBonesStubInstaller()
{
bool fikStubPresent = AppDomain.CurrentDomain.GetAssemblies()
.Any(x => x.GetTypes().Any(y => y.FullName == "DynamicBone"));
bool anythingInLocation = Directory.Exists("Assets/DynamicBone/Scripts");
if (fikStubPresent && !anythingInLocation)
{
EditorUtility.DisplayDialog("Bad Dynamic Bones Install", "Dynamic Bones Found in wrong folder. Please move your Dynamic Bones/Dynamic Bones Stub over to Assets/DynamicBone/Scripts", "Ok");
}
if (!fikStubPresent && !anythingInLocation)
{
string file = AssetDatabase.FindAssets("DynamicBonesStubInstaller", new[] { "Packages", "Assets" }).Select(AssetDatabase.GUIDToAssetPath).FirstOrDefault();
if (file == null)
{
EditorUtility.DisplayDialog("Bad Dynamic Bones Install", "Dynamic Bones Stub not found. Please install Dynamic Bones Stub from the package manager", "Ok");
return;
}
string[] files = Directory.GetFiles(Path.GetDirectoryName(file) + "/Scripts", "*.*", SearchOption.AllDirectories);
CopyFiles(files, "Assets/DynamicBone/");
}
}
private static void CopyFiles(string[] files, string finalPath)
{
foreach (var file in files)
{
if (file.EndsWith(".cs.no"))
{
string partialPath = file.Substring(file.IndexOf("Scripts", StringComparison.Ordinal));
string directory = Path.GetDirectoryName(partialPath);
if (!string.IsNullOrEmpty(directory))
{
Directory.CreateDirectory(finalPath + directory);
}
File.Copy(file, finalPath + partialPath.Replace(".cs.no", ".cs"));
File.Copy(file.Replace(".cs.no", ".cs.meta.no"), finalPath + partialPath.Replace(".cs.no",".cs.meta"));
}
}
}
}
#endif