17 lines
613 B
C#
17 lines
613 B
C#
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
|
|
namespace VOID.Editor.Utils
|
|
{
|
|
public static class GameObjectExtensions
|
|
{
|
|
public static GameObject GetPrefabAsset(this GameObject gameObject)
|
|
{
|
|
var prefab = AssetDatabase.IsMainAsset(gameObject) ? gameObject : null;
|
|
if (prefab == null) prefab = PrefabUtility.GetOutermostPrefabInstanceRoot(gameObject);
|
|
if (prefab == null) prefab = AssetDatabase.LoadAssetAtPath<GameObject>(PrefabStageUtility.GetPrefabStage(gameObject)?.assetPath);
|
|
return prefab;
|
|
}
|
|
}
|
|
} |