prefab variantからprefabを取得するのは簡単だけど、prefabから作成されたvariantをまとめて探す方法がわからなかったので作りました。 とりあえずログに出力させています。 通常のプレハブしか選択できないようになっています。
Created
March 10, 2022 15:27
-
-
Save zawazawagh/0ae0c87eb9ea8c338b467b2b15242816 to your computer and use it in GitHub Desktop.
This file contains 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 UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
namespace PrefabUtil | |
{ | |
public static class FindVariantsFromOriginal | |
{ | |
[MenuItem("Assets/PrefabUtil/Find Prefab Variant from Original Prefab", validate = true)] | |
private static bool Validate() | |
{ | |
var root = Selection.activeObject as GameObject; | |
if (root == null) | |
{ | |
return false; | |
} | |
if (PrefabUtility.IsPartOfRegularPrefab(root)) | |
{ | |
return true; | |
} | |
return false; | |
} | |
[MenuItem("Assets/PrefabUtil/Find Prefab Variant from Original Prefab")] | |
private static void FindPrefabVariantFromOriginalPrefab() | |
{ | |
var origin = Selection.activeObject as GameObject; | |
var guids = AssetDatabase.FindAssets("t:Prefab"); | |
int count = 0; | |
for (int i = 0; i < guids.Length; i++) | |
{ | |
var path = AssetDatabase.GUIDToAssetPath(guids[i]); | |
var go = AssetDatabase.LoadAssetAtPath<GameObject>(path); | |
var correspondingObject = PrefabUtility.GetCorrespondingObjectFromSource(go); | |
if (correspondingObject && correspondingObject == origin) | |
{ | |
count++; | |
Debug.Log($"Found prefab variant : {go.name}"); | |
} | |
} | |
if (count == 0) | |
{ | |
Debug.Log($"No prefab variant found"); | |
} | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment