Skip to content

Instantly share code, notes, and snippets.

@esperecyan
Last active April 17, 2024 11:14
Show Gist options
  • Save esperecyan/59884a58f4860fa2cc94d91670b36754 to your computer and use it in GitHub Desktop.
Save esperecyan/59884a58f4860fa2cc94d91670b36754 to your computer and use it in GitHub Desktop.
『SortSerializedUdonPrograms.cs』 VRChat SDK3 -Worlds プロジェクト内のSerializedUdonProgramsをUdonアセットのフォルダへ、UdonSharpの場合はそれらをスクリプトのフォルダへ振り分けるUnityエディタ拡張。Assets/Editorフォルダなどを作成してその中に入れてください。上部メニュー→「VRChat SDK」→「Utilities」→「SerializedUdonPrograms、Udonアセットを振り分ける」から実行できます。
using System.IO;
using UnityEditor;
#if UDONSHARP
using UdonSharp;
#endif
namespace Esperecyan.SortSerializedUdonPrograms
{
/// <summary>
/// SerializedUdonProgramsをUdonアセットのフォルダへ、UdonSharpの場合はそれらをスクリプトのフォルダへ振り分けます。
/// </summary>
/// <remarks>
/// Author: 100の人
/// SPDX-License-Identifier: MPL-2.0
/// </remarks>
public class SortSerializedUdonPrograms
{
/// <summary>
/// 追加するメニュー項目の位置。
/// </summary>
public const int Priority = 1121;
[MenuItem(
"VRChat SDK/Utilities/SerializedUdonPrograms、Udonアセットを振り分ける",
false,
SortSerializedUdonPrograms.Priority
)]
private static void Sort()
{
foreach (var serializedUdonProgramPath in AssetDatabase.GetAllAssetPaths())
{
if (!serializedUdonProgramPath.StartsWith("Assets/SerializedUdonPrograms/"))
{
continue;
}
var assetPath
= AssetDatabase.GUIDToAssetPath(Path.GetFileNameWithoutExtension(serializedUdonProgramPath));
if (assetPath == null || !assetPath.StartsWith("Assets/"))
{
continue;
}
var destinationFolderPath = Path.GetDirectoryName(assetPath);
#if UDONSHARP
var udonSharpProgramAsset = AssetDatabase.LoadAssetAtPath<UdonSharpProgramAsset>(assetPath);
if (udonSharpProgramAsset != null)
{
var script = udonSharpProgramAsset.sourceCsScript;
if (script != null)
{
var scriptPath = AssetDatabase.GetAssetPath(script);
if (!string.IsNullOrEmpty(scriptPath))
{
destinationFolderPath = Path.GetDirectoryName(scriptPath);
AssetDatabase.MoveAsset(
assetPath,
Path.Combine(destinationFolderPath, Path.GetFileName(assetPath))
);
}
}
}
#endif
AssetDatabase.MoveAsset(
serializedUdonProgramPath,
Path.Combine(destinationFolderPath, Path.GetFileName(serializedUdonProgramPath))
);
}
}
}
}
fileFormatVersion: 2
guid: 2498e290cebd9bc4b9b37ecc9d010c7c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment