com.wallstop-studios.unity-helpers 1.0.1-rc05 → 1.0.1-rc07
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/AnimationCopier.cs +9 -4
- package/Editor/AnimatorControllerCopier.cs +134 -0
- package/Editor/AnimatorControllerCopier.cs.meta +3 -0
- package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef +3 -1
- package/package.json +1 -1
- package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef +0 -17
- package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef.meta +0 -7
- package/Tests/Editor.meta +0 -8
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
int processed = 0;
|
|
78
79
|
foreach (string assetGuid in AssetDatabase.FindAssets("t:AnimationClip", new[] { animationSourcePath }))
|
|
79
80
|
{
|
|
80
81
|
string path = AssetDatabase.GUIDToAssetPath(assetGuid);
|
|
@@ -88,14 +89,14 @@
|
|
|
88
89
|
|
|
89
90
|
string prefix = animationClip.name;
|
|
90
91
|
string relativePath = path.Substring(animationSourcePath.Length);
|
|
91
|
-
int
|
|
92
|
-
if (
|
|
92
|
+
int prefixIndex = relativePath.LastIndexOf(prefix, StringComparison.OrdinalIgnoreCase);
|
|
93
|
+
if (prefixIndex < 0)
|
|
93
94
|
{
|
|
94
95
|
this.LogWarn("Unsupported animation at '{0}', expected to be prefixed by '{1}'.", path, prefix);
|
|
95
96
|
continue;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
string partialPath = relativePath.Substring(0,
|
|
99
|
+
string partialPath = relativePath.Substring(0, prefixIndex);
|
|
99
100
|
string outputPath = _fullDestinationPath + partialPath;
|
|
100
101
|
|
|
101
102
|
if (!Directory.Exists(outputPath))
|
|
@@ -103,7 +104,7 @@
|
|
|
103
104
|
_ = Directory.CreateDirectory(outputPath);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
string destination = animationDestinationPath + partialPath + relativePath.Substring(
|
|
107
|
+
string destination = animationDestinationPath + partialPath + relativePath.Substring(prefixIndex);
|
|
107
108
|
bool copySuccessful = AssetDatabase.CopyAsset(path, destination);
|
|
108
109
|
if (copySuccessful)
|
|
109
110
|
{
|
|
@@ -112,12 +113,16 @@
|
|
|
112
113
|
{
|
|
113
114
|
this.LogError("Failed to delete asset at path '{0}'.", path);
|
|
114
115
|
}
|
|
116
|
+
|
|
117
|
+
++processed;
|
|
115
118
|
}
|
|
116
119
|
else
|
|
117
120
|
{
|
|
118
121
|
this.LogError("Failed to copy animation from '{0}' to '{1}'.", path, destination);
|
|
119
122
|
}
|
|
120
123
|
}
|
|
124
|
+
|
|
125
|
+
this.Log($"Processed {processed} AnimationClips.");
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
#endif
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
namespace UnityHelpers.Editor
|
|
2
|
+
{
|
|
3
|
+
#if UNITY_EDITOR
|
|
4
|
+
using System;
|
|
5
|
+
using System.IO;
|
|
6
|
+
using Core.Attributes;
|
|
7
|
+
using Core.Extension;
|
|
8
|
+
using UnityEditor;
|
|
9
|
+
using UnityEngine;
|
|
10
|
+
using Utils;
|
|
11
|
+
|
|
12
|
+
public sealed class AnimatorControllerCopier : ScriptableWizard
|
|
13
|
+
{
|
|
14
|
+
private string _fullSourcePath;
|
|
15
|
+
private string _fullDestinationPath;
|
|
16
|
+
|
|
17
|
+
[ReadOnly]
|
|
18
|
+
public string controllerSourcePath;
|
|
19
|
+
|
|
20
|
+
[ReadOnly]
|
|
21
|
+
public string controllerDestinationpath;
|
|
22
|
+
|
|
23
|
+
[MenuItem("Tools/Unity Helpers/Animator Controller Copier")]
|
|
24
|
+
public static void CopyAnimations()
|
|
25
|
+
{
|
|
26
|
+
_ = DisplayWizard<AnimatorControllerCopier>("Animator Controller Copier", "Copy");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected override bool DrawWizardGUI()
|
|
30
|
+
{
|
|
31
|
+
bool returnValue = base.DrawWizardGUI();
|
|
32
|
+
|
|
33
|
+
if (GUILayout.Button("Set Animator Controller Source Path"))
|
|
34
|
+
{
|
|
35
|
+
string sourcePath = EditorUtility.OpenFolderPanel(
|
|
36
|
+
"Select Animator Controller Source Path", EditorUtilities.GetCurrentPathOfProjectWindow(),
|
|
37
|
+
string.Empty);
|
|
38
|
+
int assetIndex = sourcePath?.IndexOf("Assets", StringComparison.Ordinal) ?? -1;
|
|
39
|
+
if (assetIndex < 0)
|
|
40
|
+
{
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_fullSourcePath = controllerSourcePath = sourcePath ?? string.Empty;
|
|
45
|
+
controllerSourcePath = controllerSourcePath.Substring(assetIndex);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (GUILayout.Button("Set Animator Controller Destination Path"))
|
|
50
|
+
{
|
|
51
|
+
string sourcePath = EditorUtility.OpenFolderPanel(
|
|
52
|
+
"Select Animator Controller Destination Path", EditorUtilities.GetCurrentPathOfProjectWindow(),
|
|
53
|
+
string.Empty);
|
|
54
|
+
int assetIndex = sourcePath?.IndexOf("Assets", StringComparison.Ordinal) ?? -1;
|
|
55
|
+
if (assetIndex < 0)
|
|
56
|
+
{
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
_fullDestinationPath = controllerDestinationpath = sourcePath ?? string.Empty;
|
|
61
|
+
controllerDestinationpath = controllerDestinationpath.Substring(assetIndex);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return returnValue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private void OnWizardCreate()
|
|
69
|
+
{
|
|
70
|
+
if (string.IsNullOrEmpty(_fullSourcePath) || string.IsNullOrEmpty(_fullDestinationPath))
|
|
71
|
+
{
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (string.IsNullOrEmpty(controllerSourcePath) || string.IsNullOrEmpty(controllerDestinationpath))
|
|
76
|
+
{
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
int processed = 0;
|
|
81
|
+
foreach (string assetGuid in AssetDatabase.FindAssets(
|
|
82
|
+
"t:AnimatorController", new[] { controllerSourcePath }))
|
|
83
|
+
{
|
|
84
|
+
string path = AssetDatabase.GUIDToAssetPath(assetGuid);
|
|
85
|
+
|
|
86
|
+
RuntimeAnimatorController animatorController =
|
|
87
|
+
AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(path);
|
|
88
|
+
if (animatorController == null)
|
|
89
|
+
{
|
|
90
|
+
this.LogError("Invalid Animator Controller (null) found at path '{0}', skipping.", path);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
string prefix = animatorController.name;
|
|
95
|
+
string relativePath = path.Substring(controllerSourcePath.Length);
|
|
96
|
+
int prefixIndex = relativePath.LastIndexOf(prefix, StringComparison.OrdinalIgnoreCase);
|
|
97
|
+
if (prefixIndex < 0)
|
|
98
|
+
{
|
|
99
|
+
this.LogWarn(
|
|
100
|
+
"Unsupported AnimatorController at '{0}', expected to be prefixed by '{1}'.", path, prefix);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
string partialPath = relativePath.Substring(0, prefixIndex);
|
|
105
|
+
string outputPath = _fullDestinationPath + partialPath;
|
|
106
|
+
|
|
107
|
+
if (!Directory.Exists(outputPath))
|
|
108
|
+
{
|
|
109
|
+
_ = Directory.CreateDirectory(outputPath);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
string destination = controllerDestinationpath + partialPath + relativePath.Substring(prefixIndex);
|
|
113
|
+
bool copySuccessful = AssetDatabase.CopyAsset(path, destination);
|
|
114
|
+
if (copySuccessful)
|
|
115
|
+
{
|
|
116
|
+
bool deleteSuccessful = AssetDatabase.DeleteAsset(path);
|
|
117
|
+
if (!deleteSuccessful)
|
|
118
|
+
{
|
|
119
|
+
this.LogError("Failed to delete Animator Controller asset at path '{0}'.", path);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
++processed;
|
|
123
|
+
}
|
|
124
|
+
else
|
|
125
|
+
{
|
|
126
|
+
this.LogError("Failed to copy Animator Controller from '{0}' to '{1}'.", path, destination);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.Log($"Processed {processed} Animator Controllers.");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
#endif
|
|
134
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "WallstopStudios.UnityHelpers.Tests.Editor",
|
|
3
|
-
"rootNamespace": "",
|
|
4
|
-
"references": [
|
|
5
|
-
"UnityEditor.TestRunner",
|
|
6
|
-
"UnityEngine.TestRunner"
|
|
7
|
-
],
|
|
8
|
-
"includePlatforms": [],
|
|
9
|
-
"excludePlatforms": [],
|
|
10
|
-
"allowUnsafeCode": false,
|
|
11
|
-
"overrideReferences": false,
|
|
12
|
-
"precompiledReferences": [],
|
|
13
|
-
"autoReferenced": true,
|
|
14
|
-
"defineConstraints": [],
|
|
15
|
-
"versionDefines": [],
|
|
16
|
-
"noEngineReferences": false
|
|
17
|
-
}
|