mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using AssetRipper.SourceGenerated.Classes.ClassID_1;
|
|
using AssetRipper.SourceGenerated.Classes.ClassID_1001;
|
|
using AssetRipper.SourceGenerated.Classes.ClassID_18;
|
|
using AssetRipper.SourceGenerated.MarkerInterfaces;
|
|
|
|
namespace AssetRipper.SourceGenerated.Extensions
|
|
{
|
|
public static class PrefabInstanceExtensions
|
|
{
|
|
public static string GetName(this IPrefabInstance prefab)
|
|
{
|
|
string? name = prefab.RootGameObjectP?.Name;
|
|
return string.IsNullOrEmpty(name) ? prefab.ClassName : name;
|
|
}
|
|
|
|
public static IGameObject GetRootGameObject(this IPrefabInstance prefab)
|
|
{
|
|
return prefab.RootGameObjectP ?? throw new ArgumentException("Prefab has no root GameObject.", nameof(prefab));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the <see cref="IPrefabInstance"/> as the internal prefab for all <see cref="IEditorExtension"/>s in the hierarchy.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Prior to 2018.3, Prefab was an actual asset inside "*.prefab" files.
|
|
/// </remarks>
|
|
/// <param name="prefab"></param>
|
|
public static void SetPrefabInternal(this IPrefabInstance prefab)
|
|
{
|
|
if (prefab is IPrefabMarker prefabMarker)
|
|
{
|
|
foreach (IEditorExtension editorExtension in prefab.GetRootGameObject().FetchHierarchy())
|
|
{
|
|
editorExtension.PrefabInternal_C18P = prefabMarker;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|