using HighwayRacers; using System.Collections.Generic; using Unity.Entities; using UnityEngine; public class CarSpawnerAuthoring : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs { public int carCount; public GameObject americanPrefab; public GameObject europeanPrefab; public GameObject tilePrefab; [Tooltip("European cars are blue. American cars are green")] public DriverProfile DriverProfile = DriverProfile.Random; private void Start() { } //--------------------------------------------------------------------------------------- // This function is required by IDeclareReferencedPrefabs public void DeclareReferencedPrefabs(List referencedPrefabs) { // Conversion only converts the GameObjects in the scene. // This function allows us to inject extra GameObjects, // in this case prefabs that live in the assets folder. referencedPrefabs.Add(americanPrefab); referencedPrefabs.Add(europeanPrefab); referencedPrefabs.Add(tilePrefab); } //--------------------------------------------------------------------------------------- // This function is required by IConvertGameObjectToEntity public void Convert(Entity entity, EntityManager dstManager , GameObjectConversionSystem conversionSystem) { //retrieve streets. var streets = FindObjectOfType(); // GetPrimaryEntity fetches the entity that resulted from the conversion of // the given GameObject, but of course this GameObject needs to be part of // the conversion, that's why DeclareReferencedPrefabs is important here. dstManager.AddComponentData(entity, new CarSpawnerComponent { // StreetsCount = streets.StreetInfo.Features.Length, CarCount = carCount, AmericanCarPrefab = conversionSystem.GetPrimaryEntity(americanPrefab), EuropeanCarPrefab = conversionSystem.GetPrimaryEntity(europeanPrefab), TilePrefab = conversionSystem.GetPrimaryEntity(tilePrefab), DriverProfile = DriverProfile, StreetsCount = streets.StreetInfo.Features.Length }); } }