/// <summary> /// /// </summary> public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { createModelEntities_(conversionSystem, this.gameObject, this.Material, this.LodOptionalMeshTops); var drawInstatnce = initInstanceEntityComponents_(conversionSystem, this.gameObject, this.LodOptionalMeshTops); conversionSystem.AddLod2ComponentToDrawInstanceEntity(drawInstatnce, this.gameObject, this.LodOptionalMeshTops); return; void createModelEntities_ (GameObjectConversionSystem gcs, GameObject main, Material srcMaterial, ObjectAndDistance[] lodOpts) { var lods = LodOptionalMeshTops.Select(x => x.objectTop).ToArray(); var objsForModel = gcs.BuildMeshesForModelEntity(main, lods, this.GetMeshCombineFuncPerObjects); foreach (var go in objsForModel) { Debug.Log($"{go.name} model ent"); var mesh = gcs.GetFromStructureMeshDictionary(go); createModelEntity_(gcs, go, srcMaterial, mesh); } return; void createModelEntity_ (GameObjectConversionSystem gcs_, GameObject top_, Material srcMaterial_, Mesh mesh_) { var mat = new Material(srcMaterial_); const BoneType BoneType = BoneType.TR; const int boneLength = 1; gcs_.CreateDrawModelEntityComponents(top_, mesh_, mat, BoneType, boneLength); } } Entity initInstanceEntityComponents_(GameObjectConversionSystem gcs, GameObject main, ObjectAndDistance[] lodOpts) { dstManager.SetName_(entity, $"{this.name}"); var em = gcs.DstEntityManager; var mainEntity = gcs.GetPrimaryEntity(main); var archetype = em.CreateArchetype( typeof(ModelPrefabNoNeedLinkedEntityGroupTag), typeof(BinderTrimBlankLinkedEntityGroupTag), typeof(DrawInstance.MeshTag), typeof(DrawInstance.ModeLinkData), typeof(DrawInstance.TargetWorkData), typeof(Translation), typeof(Rotation), typeof(NonUniformScale) ); em.SetArchetype(mainEntity, archetype); em.SetComponentData(mainEntity, new DrawInstance.ModeLinkData //new DrawTransform.LinkData { DrawModelEntityCurrent = gcs.GetDrawModelEntity(main, lodOpts), } ); em.SetComponentData(mainEntity, new DrawInstance.TargetWorkData { DrawInstanceId = -1, } ); em.SetComponentData(mainEntity, new Translation { Value = float3.zero, } ); em.SetComponentData(mainEntity, new Rotation { Value = quaternion.identity, } ); em.SetComponentData(mainEntity, new NonUniformScale { Value = new float3(1.0f, 1.0f, 1.0f), } ); return(mainEntity); } }