Skip to content

Commit 7746753

Browse files
committed
Refactoring and push 1.4.0
1 parent 8aec3d3 commit 7746753

11 files changed

Lines changed: 353 additions & 400 deletions

Packages/net.pawlygon.unitytools/Editor/AvatarSetupWizard.cs

Lines changed: 72 additions & 176 deletions
Large diffs are not rendered by default.

Packages/net.pawlygon.unitytools/Editor/EyeMuscleSettingsCore.cs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,41 +95,10 @@ internal class AnalysisResult
9595
public EyeMuscleValues RightEye;
9696
}
9797

98-
// =====================================================================
99-
// Cached reflection types
100-
// =====================================================================
101-
102-
private static Type cachedDescriptorType;
103-
private static bool descriptorTypeLookedUp;
104-
10598
// =====================================================================
10699
// Avatar discovery
107100
// =====================================================================
108101

109-
/// <summary>
110-
/// Finds the first VRCAvatarDescriptor type via TypeCache, caching the result.
111-
/// Returns null if the VRChat Avatars SDK is not installed.
112-
/// </summary>
113-
internal static Type FindVRCAvatarDescriptorType()
114-
{
115-
if (descriptorTypeLookedUp) return cachedDescriptorType;
116-
117-
descriptorTypeLookedUp = true;
118-
cachedDescriptorType = null;
119-
120-
TypeCache.TypeCollection monoBehaviourTypes = TypeCache.GetTypesDerivedFrom<MonoBehaviour>();
121-
foreach (Type type in monoBehaviourTypes)
122-
{
123-
if (type.Name == "VRCAvatarDescriptor" && type.Namespace != null && type.Namespace.StartsWith("VRC"))
124-
{
125-
cachedDescriptorType = type;
126-
break;
127-
}
128-
}
129-
130-
return cachedDescriptorType;
131-
}
132-
133102
/// <summary>
134103
/// Finds the first scene root GameObject that has a VRCAvatarDescriptor component.
135104
/// Returns null if none found.
@@ -149,7 +118,7 @@ internal static GameObject FindFirstAvatarInScene()
149118
return null;
150119
}
151120

152-
Type descriptorType = FindVRCAvatarDescriptorType();
121+
Type descriptorType = PawlygonEditorUtils.FindVRCAvatarDescriptorType();
153122

154123
// Prefer a root object with a VRCAvatarDescriptor
155124
if (descriptorType != null)

Packages/net.pawlygon.unitytools/Editor/FTDiffGenerator.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void LaunchProcess(string executablePath, string arguments)
8787
{
8888
try
8989
{
90-
var process = new Process
90+
using var process = new Process
9191
{
9292
StartInfo = new ProcessStartInfo
9393
{
@@ -164,26 +164,11 @@ public string GetPatcherFolderAssetPath()
164164
return AssetDatabase.GetAssetPath(outputDirectory) + "/patcher";
165165
}
166166

167-
/// <summary>
168-
/// Converts an absolute file system path to a Unity asset path (relative to Assets/).
169-
/// </summary>
170-
internal static string ToAssetPath(string absolutePath)
171-
{
172-
string normalized = absolutePath.Replace('\\', '/');
173-
string dataPath = Application.dataPath.Replace('\\', '/');
174-
if (normalized.StartsWith(dataPath, StringComparison.OrdinalIgnoreCase))
175-
{
176-
return "Assets" + normalized.Substring(dataPath.Length);
177-
}
178-
179-
return normalized;
180-
}
181-
182167
private bool SetExecutablePermission(string path)
183168
{
184169
try
185170
{
186-
var chmod = new Process
171+
using var chmod = new Process
187172
{
188173
StartInfo = new ProcessStartInfo
189174
{

Packages/net.pawlygon.unitytools/Editor/FTPatchConfigGenerator.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static string GenerateConfig(ConfigContext context)
114114
}
115115

116116
string assetName = ResolveAssetName(context);
117-
string assetPath = CombineAssetPath(configFolder, assetName + ".asset");
117+
string assetPath = PawlygonEditorUtils.CombineAssetPath(configFolder, assetName + ".asset");
118118

119119
// Check if an existing config already exists at this path
120120
ScriptableObject existingConfig = AssetDatabase.LoadAssetAtPath<ScriptableObject>(assetPath);
@@ -136,7 +136,7 @@ public static string GenerateConfig(ConfigContext context)
136136
}
137137
else
138138
{
139-
EnsureFolderExists(configFolder);
139+
PawlygonEditorUtils.EnsureFolderExists(configFolder);
140140
AssetDatabase.CreateAsset(config, assetPath);
141141
Debug.Log($"{LogPrefix} Created new FTPatchConfig at '{assetPath}'.");
142142
}
@@ -321,28 +321,5 @@ private static string ResolveAssetName(ConfigContext context)
321321

322322
return "FTPatchConfig";
323323
}
324-
325-
private static void EnsureFolderExists(string assetPath)
326-
{
327-
if (AssetDatabase.IsValidFolder(assetPath))
328-
{
329-
return;
330-
}
331-
332-
string parent = Path.GetDirectoryName(assetPath)?.Replace('\\', '/');
333-
if (string.IsNullOrEmpty(parent))
334-
{
335-
return;
336-
}
337-
338-
EnsureFolderExists(parent);
339-
string folderName = Path.GetFileName(assetPath);
340-
AssetDatabase.CreateFolder(parent, folderName);
341-
}
342-
343-
private static string CombineAssetPath(params string[] parts)
344-
{
345-
return string.Join("/", parts.Where(p => !string.IsNullOrEmpty(p)));
346-
}
347324
}
348325
}

Packages/net.pawlygon.unitytools/Editor/FXGestureChecker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ private void AutoSelectFirstSceneRoot()
515515
}
516516

517517
// Prefer a root object with a VRCAvatarDescriptor
518-
Type descriptorType = FXGestureCheckerCore.FindVRCAvatarDescriptorType();
518+
Type descriptorType = PawlygonEditorUtils.FindVRCAvatarDescriptorType();
519519

520520
if (descriptorType != null)
521521
{

Packages/net.pawlygon.unitytools/Editor/FXGestureCheckerCore.cs

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -89,37 +89,10 @@ internal class AnalysisResult
8989
// Cached reflection types
9090
// =====================================================================
9191

92-
private static Type cachedDescriptorType;
93-
private static bool descriptorTypeLookedUp;
94-
9592
// =====================================================================
9693
// Reflection helpers
9794
// =====================================================================
9895

99-
/// <summary>
100-
/// Finds the VRCAvatarDescriptor type via TypeCache, caching the result.
101-
/// Returns null if the VRChat Avatars SDK is not installed.
102-
/// </summary>
103-
internal static Type FindVRCAvatarDescriptorType()
104-
{
105-
if (descriptorTypeLookedUp) return cachedDescriptorType;
106-
107-
descriptorTypeLookedUp = true;
108-
cachedDescriptorType = null;
109-
110-
TypeCache.TypeCollection monoBehaviourTypes = TypeCache.GetTypesDerivedFrom<MonoBehaviour>();
111-
foreach (Type type in monoBehaviourTypes)
112-
{
113-
if (type.Name == "VRCAvatarDescriptor" && type.Namespace != null && type.Namespace.StartsWith("VRC"))
114-
{
115-
cachedDescriptorType = type;
116-
break;
117-
}
118-
}
119-
120-
return cachedDescriptorType;
121-
}
122-
12396
/// <summary>
12497
/// Extracts the FX AnimatorController from a VRCAvatarDescriptor component using reflection.
12598
/// Reads baseAnimationLayers array and finds the entry where type == AnimLayerType.FX (5).
@@ -206,7 +179,7 @@ internal static AnalysisResult Analyze(GameObject avatar)
206179
};
207180
}
208181

209-
Type descriptorType = FindVRCAvatarDescriptorType();
182+
Type descriptorType = PawlygonEditorUtils.FindVRCAvatarDescriptorType();
210183
if (descriptorType == null)
211184
{
212185
return new AnalysisResult
@@ -576,7 +549,7 @@ internal static AnimatorController CopyFXController(AnimatorController source, s
576549
}
577550

578551
string folder = string.IsNullOrEmpty(outputFolder) ? "Assets" : outputFolder;
579-
EnsureFolderExists(folder);
552+
PawlygonEditorUtils.EnsureFolderExists(folder);
580553

581554
string fileName = Path.GetFileNameWithoutExtension(sourcePath);
582555
string extension = Path.GetExtension(sourcePath);
@@ -668,22 +641,6 @@ internal static bool AssignFXControllerToDescriptor(Component descriptor, Type d
668641
return true;
669642
}
670643

671-
/// <summary>
672-
/// Recursively ensures that all folders in the given asset path exist,
673-
/// creating them via <see cref="AssetDatabase.CreateFolder"/> as needed.
674-
/// </summary>
675-
internal static void EnsureFolderExists(string assetPath)
676-
{
677-
if (string.IsNullOrEmpty(assetPath) || AssetDatabase.IsValidFolder(assetPath)) return;
678-
679-
string parent = Path.GetDirectoryName(assetPath)?.Replace('\\', '/');
680-
if (string.IsNullOrEmpty(parent)) return;
681-
682-
EnsureFolderExists(parent);
683-
string folderName = Path.GetFileName(assetPath);
684-
AssetDatabase.CreateFolder(parent, folderName);
685-
}
686-
687644
// =====================================================================
688645
// Selection helpers
689646
// =====================================================================

Packages/net.pawlygon.unitytools/Editor/PawlygonEditorUI.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public static class PawlygonEditorUI
3232
private static GUIStyle headerSubtitleStyle;
3333
private static GUIStyle footerStyle;
3434
private static GUIStyle footerLinkStyle;
35+
private static GUIStyle headerBoxStyle;
36+
private static GUIStyle footerBoxStyle;
37+
private static GUIStyle primaryButtonStyle;
38+
private static GUIStyle sectionBoxStyle;
39+
private static GUIStyle sectionTitleStyle;
3540

3641
// =====================================================================
3742
// Style Initialization
@@ -106,6 +111,26 @@ public static void EnsureStyles()
106111

107112
footerLinkStyle.normal.textColor = new Color(0.39f, 0.67f, 1f);
108113
footerLinkStyle.hover.textColor = new Color(0.58f, 0.79f, 1f);
114+
115+
headerBoxStyle = new GUIStyle(EditorStyles.helpBox)
116+
{
117+
padding = new RectOffset(14, 14, 12, 12)
118+
};
119+
120+
footerBoxStyle = new GUIStyle(EditorStyles.helpBox)
121+
{
122+
padding = new RectOffset(12, 12, 10, 10)
123+
};
124+
125+
sectionBoxStyle = new GUIStyle(EditorStyles.helpBox)
126+
{
127+
padding = new RectOffset(15, 15, 15, 15)
128+
};
129+
130+
sectionTitleStyle = new GUIStyle(EditorStyles.boldLabel)
131+
{
132+
fontSize = 14
133+
};
109134
}
110135

111136
// =====================================================================
@@ -126,7 +151,7 @@ public static void DrawHeader(string title, string subtitle)
126151

127152
EditorGUILayout.Space(6f);
128153

129-
using (new EditorGUILayout.VerticalScope(new GUIStyle(EditorStyles.helpBox) { padding = new RectOffset(14, 14, 12, 12) }))
154+
using (new EditorGUILayout.VerticalScope(headerBoxStyle))
130155
{
131156
Rect headerRect = EditorGUILayout.GetControlRect(false, 84f);
132157

@@ -162,7 +187,7 @@ public static void DrawFooter()
162187
{
163188
string version = GetPackageVersion();
164189

165-
using (new EditorGUILayout.VerticalScope(new GUIStyle(EditorStyles.helpBox) { padding = new RectOffset(12, 12, 10, 10) }))
190+
using (new EditorGUILayout.VerticalScope(footerBoxStyle))
166191
{
167192
EditorGUILayout.LabelField($"Made with \u2764 by Pawlygon Studio \u2022 v{version}", footerStyle);
168193
EditorGUILayout.Space(6f);
@@ -200,13 +225,16 @@ private static void DrawFooterLink(string label, string url)
200225
/// <returns>True if the button was clicked.</returns>
201226
public static bool DrawPrimaryButton(string text, float height = 34f)
202227
{
228+
if (primaryButtonStyle == null)
229+
{
230+
primaryButtonStyle = new GUIStyle(GUI.skin.button) { fontStyle = FontStyle.Bold, fontSize = 13 };
231+
}
232+
203233
Color oldColor = GUI.backgroundColor;
204234
GUI.backgroundColor = EditorGUIUtility.isProSkin
205235
? new Color(0.2f, 0.6f, 1f)
206236
: new Color(0.1f, 0.4f, 0.8f);
207-
bool clicked = GUILayout.Button(text,
208-
new GUIStyle(GUI.skin.button) { fontStyle = FontStyle.Bold, fontSize = 13 },
209-
GUILayout.Height(height));
237+
bool clicked = GUILayout.Button(text, primaryButtonStyle, GUILayout.Height(height));
210238
GUI.backgroundColor = oldColor;
211239
return clicked;
212240
}
@@ -226,9 +254,9 @@ public static void DrawSeparator()
226254
/// </summary>
227255
public static void DrawSection(string title, string description, Action drawContent)
228256
{
229-
using (new EditorGUILayout.VerticalScope(new GUIStyle(EditorStyles.helpBox) { padding = new RectOffset(15, 15, 15, 15) }))
257+
using (new EditorGUILayout.VerticalScope(sectionBoxStyle))
230258
{
231-
EditorGUILayout.LabelField(title, new GUIStyle(EditorStyles.boldLabel) { fontSize = 14 });
259+
EditorGUILayout.LabelField(title, sectionTitleStyle);
232260
EditorGUILayout.Space(2);
233261
EditorGUILayout.LabelField(description, SubLabelStyle);
234262
EditorGUILayout.Space(12);

0 commit comments

Comments
 (0)