-
Notifications
You must be signed in to change notification settings - Fork 0
/
I5Tools.cs
196 lines (180 loc) · 8.8 KB
/
I5Tools.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
185
186
187
188
189
190
191
192
193
194
195
196
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using VRC.SDK3.Dynamics.PhysBone.Components;
using VRC.Dynamics;
using VRC.SDKBase.Editor;
using VRC.Core;
using UnityEditor.SceneManagement;
namespace I5Tools
{
public class Tools : MonoBehaviour
{
[MenuItem("Tools/I5Tools/Optimize Texture Formats", false, 1000)]
public static void OptimizeTextureFormats()
{
string[] guids = AssetDatabase.FindAssets("t:Texture2D");
foreach (string guid in guids)
{
bool changesMade = false;
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
if (assetPath.Contains("com.unity")) continue;
TextureImporter importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (importer == null)
{
Debug.LogWarning("Failed to get TextureImporter for asset: " + assetPath);
continue;
}
TextureImporterPlatformSettings standalone = importer.GetPlatformTextureSettings("Standalone");
if (standalone == null)
{
Debug.LogWarning("Failed to get Standalone TextureImporterPlatformSettings for asset: " + assetPath);
continue;
}
switch (importer.textureType)
{
case TextureImporterType.Default:
if (!importer.mipmapEnabled || !importer.streamingMipmaps)
{
Debug.Log("Enabling mipmap streaming: " + assetPath);
importer.mipmapEnabled = true;
importer.streamingMipmaps = true;
changesMade = true;
}
if (importer.crunchedCompression)
{
Debug.Log("Uncrunching texture: " + assetPath);
importer.crunchedCompression = false;
changesMade = true;
}
if (importer.textureCompression == TextureImporterCompression.Uncompressed)
{
Debug.Log("Compressing texture: " + assetPath);
importer.textureCompression = TextureImporterCompression.Compressed;
changesMade = true;
}
if (importer.textureCompression != TextureImporterCompression.CompressedHQ && importer.DoesSourceTextureHaveAlpha() && importer.alphaSource != TextureImporterAlphaSource.None && importer.sRGBTexture)
{
Debug.Log("Setting texture compression to BC7: " + assetPath);
importer.textureCompression = TextureImporterCompression.CompressedHQ;
importer.alphaIsTransparency = true;
changesMade = true;
}
break;
case TextureImporterType.NormalMap:
if (standalone.format != TextureImporterFormat.BC5 || !standalone.overridden)
{
Debug.Log("Normal map not in BC5 format: " + assetPath);
standalone.overridden = true;
standalone.maxTextureSize = importer.maxTextureSize;
standalone.format = TextureImporterFormat.BC5;
importer.SetPlatformTextureSettings(standalone);
changesMade = true;
}
break;
default:
break;
}
if (changesMade)
{
importer.SaveAndReimport();
}
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
[MenuItem("Tools/I5Tools/Make All Bones Immovable in World Space", false, 1001)]
public static void MakeAllBonesImmovable()
{
VRCPhysBone[] physBones = FindObjectsOfType<VRCPhysBone>();
foreach (VRCPhysBone physBone in physBones)
{
physBone.immobileType = VRCPhysBoneBase.ImmobileType.World;
physBone.immobile = 1.0f;
}
}
[MenuItem("Tools/I5Tools/Delete All OSC Config Files", false, 1002)]
public static void DeleteAllOscConfigFiles()
{
string oscfolderpath = VRC_SdkBuilder.GetLocalLowPath() + "/VRChat/VRChat/OSC/";
Debug.Log("Deleting all usr_* folders in " + oscfolderpath);
string[] oscfolders = System.IO.Directory.GetDirectories(oscfolderpath);
oscfolders = System.Array.FindAll(oscfolders, s => s.Contains("usr_"));
if (oscfolders.Length == 0)
{
Debug.Log("No OSC folders found");
return;
}
foreach (string oscfolder in oscfolders)
{
Debug.Log("Deleting " + oscfolder);
System.IO.Directory.Delete(oscfolder, true);
}
}
[MenuItem("Tools/I5Tools/Force Scene View in Play Mode", false, 1003)]
public static void CreateDebugManager()
{
GameObject debugManager = new GameObject("ForceSceneView");
debugManager.AddComponent<ForceSceneView>();
}
[MenuItem("Tools/I5Tools/Set Anchor/Head", false, 1004)]
public static void SetAnchorHead() => SetAnchor("Armature/Hips/Spine/Chest/Neck/Head");
[MenuItem("Tools/I5Tools/Set Anchor/Chest", false, 1005)]
public static void SetAnchorChest() => SetAnchor("Armature/Hips/Spine/Chest");
[MenuItem("Tools/I5Tools/Set Anchor/Spine", false, 1006)]
public static void SetAnchorSpine() => SetAnchor("Armature/Hips/Spine");
private static void SetAnchor(string path)
{
PipelineManager[] avatars = FindObjectsOfType<PipelineManager>();
int avatarCount = avatars.Length;
for (int i = 0; i < avatarCount; i++)
{
GameObject avatarObject = avatars[i].gameObject;
// find head bone
Transform anchorBone = avatarObject.transform.Find(path);
Debug.Log("Found bone: " + anchorBone.name);
// get All Meshes
SkinnedMeshRenderer[] skinnedMeshRenderers = avatarObject.GetComponentsInChildren<SkinnedMeshRenderer>();
foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderers)
{
Debug.Log("Setting probeAnchor for " + skinnedMeshRenderer.name + " to " + anchorBone.name + " on " + avatarObject.name);
skinnedMeshRenderer.probeAnchor = anchorBone;
}
MeshRenderer[] meshRenderers = avatarObject.GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer meshRenderer in meshRenderers)
{
Debug.Log("Setting probeAnchor for " + meshRenderer.name + " to " + anchorBone.name + " on " + avatarObject.name);
meshRenderer.probeAnchor = anchorBone;
}
}
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
[MenuItem("Tools/I5Tools/Set Biggest Bounds", false, 1004)]
public static void SetBiggestBounds()
{
PipelineManager[] avatars = FindObjectsOfType<PipelineManager>();
int avatarCount = avatars.Length;
for (int i = 0; i < avatarCount; i++)
{
GameObject avatarObject = avatars[i].gameObject;
// get All Meshes
SkinnedMeshRenderer[] skinnedMeshRenderers = avatarObject.GetComponentsInChildren<SkinnedMeshRenderer>();
Bounds biggestBounds = new Bounds(Vector3.zero, Vector3.zero);
foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderers)
{
if (skinnedMeshRenderer.bounds.size.sqrMagnitude > biggestBounds.size.sqrMagnitude)
{
biggestBounds = skinnedMeshRenderer.localBounds;
}
}
foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderers)
{
Debug.Log("Setting localBounds for " + skinnedMeshRenderer.name + " to " + biggestBounds.size + " on " + avatarObject.name);
skinnedMeshRenderer.localBounds = biggestBounds;
}
}
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
}
}
#endif