Created
July 25, 2025 11:23
-
-
Save Hafune/a042019b1ee6720183f0bd212b3932ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using UnityEngine; | |
namespace Core | |
{ | |
public static class CreateReferencePathsForSelected | |
{ | |
[MenuItem("Auto/Create reference paths for selected", false, 1)] | |
private static void CreateMany() | |
{ | |
//https://discussions.unity.com/t/how-to-get-path-from-the-current-opened-folder-in-the-project-window-in-unity-editor/226209 | |
var projectWindowUtilType = typeof(ProjectWindowUtil); | |
var getActiveFolderPath = | |
projectWindowUtilType.GetMethod("GetActiveFolderPath", BindingFlags.Static | BindingFlags.NonPublic)!; | |
var obj = getActiveFolderPath.Invoke(null, Array.Empty<object>()); | |
var pathToCurrentFolder = obj.ToString(); | |
foreach (var go in Selection.gameObjects) | |
CreateReferencePath(go, pathToCurrentFolder); | |
} | |
private static void CreateReferencePath(GameObject go, string pathToCurrentFolder) | |
{ | |
var stage = PrefabStageUtility.GetCurrentPrefabStage(); | |
if (!stage) | |
return; | |
var refPath = ScriptableObject.CreateInstance<ReferencePath>(); | |
refPath.SetPrefabPart(AssetDatabase.LoadAssetAtPath<GameObject>(stage.assetPath), ReferencePath.GetPath(go)); | |
AssetDatabase.CreateAsset(refPath, pathToCurrentFolder + "/Path_" + go.name + ".asset"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment