Well, as thread title says: i have a bunch of prefabs which are not in scene on start but loading them before world creation, then i want to convert them as entities prefabs, but see no way except of spawning them as gameobject with ConvertToEntity component or create special gameobject with authoring component, give it all prefabs and let it be converted with all this prefabs at once (my current solution)
public class AddressablesToEntitiesAuthoring : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs
{
private List<GameObject> _prefabs;
private string[] _prefabsGUIDs;
public void Initialize(List<GameObject> prefabs, string[] prefabsGUIDs)
{
_prefabs = prefabs;
_prefabsGUIDs = prefabsGUIDs;
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
#if UNITY_EDITOR
dstManager.SetName(entity, "AddressablesAssetMap");
#endif
var assetMap = dstManager.AddBuffer<AssetMapElement>(entity);
for(int i = 0; i < _prefabs.Count; i++)
{
var guid = new Unity.Collections.FixedString64(_prefabsGUIDs[i]);
var hash = guid.GetHashCode();
assetMap.Add(new AssetMapElement { entity = conversionSystem.GetPrimaryEntity(_prefabs[i]), assetGUID = guid, assetGUIDHash = hash });
}
}
public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
{
referencedPrefabs.AddRange(_prefabs);
}
}