forked from Zakhazerd/Doge-Unity-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Doge Tools.cs
184 lines (162 loc) · 7.11 KB
/
Doge Tools.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Reflection;
using System;
public class DogeTools : EditorWindow
{
AnimationClip my_variable;
string tmp;
DefaultAsset my_file;
GameObject Parent;
[MenuItem("Tools/Doge Tools")]
public static void ShowWindow()
{
GetWindow(typeof(DogeTools));
}
private void OnGUI()
{
GUILayout.Label("Append time :)", EditorStyles.boldLabel);
tmp = EditorGUILayout.TextField("New Hierchy", tmp);
my_variable = EditorGUILayout.ObjectField("Animation", my_variable, typeof(AnimationClip), false) as AnimationClip;
if (GUILayout.Button("Do the thing"))
{
Reheirchy();
}
GUILayout.Label("Copy all from folder", EditorStyles.boldLabel);
my_file = (DefaultAsset)EditorGUILayout.ObjectField("Folder", my_file, typeof(DefaultAsset), false);
if (my_file != null) {
if (my_file.name == "Assets")
{
EditorGUILayout.HelpBox("Bruh just don't", MessageType.Warning, true);
}
}
if (GUILayout.Button("Do the thing"))
{
Copy_move();
}
GUILayout.Label("Normalize and set anchors", EditorStyles.boldLabel);
Parent = EditorGUILayout.ObjectField("Parent", Parent, typeof(GameObject), true) as GameObject;
if (GUILayout.Button("Do the thing"))
{
print_children();
}
}
void Copy(string sourceDir, string targetDir, string folder_name)
{
Directory.CreateDirectory(targetDir);
foreach (var file in Directory.GetFiles(sourceDir))
File.Copy(file, Path.Combine(targetDir, folder_name + Path.GetFileName(file)));
foreach (var directory in Directory.GetDirectories(sourceDir))
Copy(directory, Path.Combine(targetDir, Path.GetFileName(directory)), folder_name); //this is recursive but i dont know what ends it
}
private void Copy_move()
{
Type projectWindowUtilType = typeof(ProjectWindowUtil);
MethodInfo getActiveFolderPath = projectWindowUtilType.GetMethod("GetActiveFolderPath", BindingFlags.Static | BindingFlags.NonPublic);
object obj = getActiveFolderPath.Invoke(null, new object[0]);
string folder_name = Path.GetFileNameWithoutExtension(obj.ToString()) + " ";
string pathToCurrentFolder = obj.ToString(); //I have litterally no how the above works
string current_filePath = Path.Combine(Directory.GetCurrentDirectory(), pathToCurrentFolder);
current_filePath = current_filePath.Replace("/", "\\");
string selected_assetPath = AssetDatabase.GetAssetPath(my_file);
string selected_filePath = Path.Combine(Directory.GetCurrentDirectory(), selected_assetPath);
selected_filePath = selected_filePath.Replace("/", "\\");
Copy(selected_filePath,current_filePath, folder_name);
AssetDatabase.Refresh();
}
private void Reheirchy()
{
string assetPath = AssetDatabase.GetAssetPath(my_variable); // turn this into a function retard even tho i probably only need the realitive path but fuck you
string filePath = Path.Combine(Directory.GetCurrentDirectory(), assetPath);
filePath = filePath.Replace("/", "\\");
string to_append = " path: ";
string line;
int offset = 10;
to_append = to_append + tmp;
tmp = filePath;
tmp = tmp.Remove(tmp.Length - 5, 5);
tmp = tmp + " new.anim"; //clean this up its stupid
string out_path = tmp;
StreamReader infile = new StreamReader(filePath);
StreamWriter outfile = new StreamWriter(out_path);
line = infile.ReadLine();
while (line != null)
{
if (line[4] == 'p' && line[5] == 'a')
{
line = line.Remove(0,offset);
line = to_append + line;
outfile.WriteLine(line);
}
else
{
outfile.WriteLine(line);
}
line = infile.ReadLine();
}
tmp = line;
outfile.Close();
infile.Close();
AssetDatabase.Refresh();
}
void print_children()
{
float tempXcenter;
float tempYcenter;
float tempZcenter;
float tempXextent;
float tempYextent;
float tempZextent;
float greatestX = 0;
float greatestY = 0;
float greatestZ = 0;
foreach (Transform Child in Parent.transform)
{
if (Child.gameObject.GetComponent<SkinnedMeshRenderer>() != null)
{
tempXcenter = Math.Abs(Child.gameObject.GetComponent<SkinnedMeshRenderer>().localBounds.center.x);
tempYcenter = Math.Abs(Child.gameObject.GetComponent<SkinnedMeshRenderer>().localBounds.center.y);
tempZcenter = Math.Abs(Child.gameObject.GetComponent<SkinnedMeshRenderer>().localBounds.center.z);
tempXextent = Child.gameObject.GetComponent<SkinnedMeshRenderer>().localBounds.extents.x;
tempYextent = Child.gameObject.GetComponent<SkinnedMeshRenderer>().localBounds.extents.y;
tempZextent = Child.gameObject.GetComponent<SkinnedMeshRenderer>().localBounds.extents.z;
tempXextent = (tempXcenter + tempXextent) * 2;
tempYextent = (tempYcenter + tempYextent) * 2;
tempZextent = (tempZcenter + tempZextent) * 2;
if (tempXextent > greatestX) greatestX = tempXextent;
if (tempYextent > greatestY) greatestY = tempYextent;
if (tempZextent > greatestZ) greatestZ = tempZextent;
Child.gameObject.GetComponent<SkinnedMeshRenderer>().localBounds = new Bounds(new Vector3(0, 0, 0), new Vector3 (tempXextent, tempYextent, tempZextent));
Debug.Log(Child.name);
}
}
foreach (Transform Child in Parent.transform)
{
if (Child.gameObject.GetComponent<SkinnedMeshRenderer>() != null)
{
Child.gameObject.GetComponent<SkinnedMeshRenderer>().localBounds = new Bounds(new Vector3(0, 0, 0), new Vector3(greatestX, greatestY, greatestZ));
Debug.Log(Child.name);
}
}
Transform Hips = Parent.transform;
foreach (Transform Child in Parent.transform)
{
if (Child.name == "Armature")
{
foreach (Transform subChild in Child.transform)
{
if (subChild.name == "Hips")
{
Hips = subChild;
break;
}
}
}
if (Child.gameObject.GetComponent<SkinnedMeshRenderer>() != null)
{
Child.gameObject.GetComponent<SkinnedMeshRenderer>().probeAnchor = Hips;
}
}
}
}