using Unity.Collections; using Unity.Entities; using Unity.Rendering; using UnityEngine; public class CarAuthoring : MonoBehaviour, IConvertGameObjectToEntity { public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var allRenderers = transform.GetComponentsInChildren(); var needBaseColor = new NativeArray(allRenderers.Length, Allocator.Temp); Debug.Log(string.Format("-- CarAuthoring.Convert allRenders.Length={0}",allRenderers.Length)); for(int i = 0; i < allRenderers.Length; ++i) { var gameObject = allRenderers[i].gameObject; needBaseColor[i] = conversionSystem.GetPrimaryEntity(gameObject); } // We could have used AddComponent in the loop above, but as a general rule in // DOTS, doing a batch of things at once is more efficient. dstManager.AddComponent(needBaseColor); dstManager.AddComponent(entity); } }