BITKit/Packages/Runtime~/Unity/ECS/CovertToEntity.cs

38 lines
850 B
C#

using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;
using ZXing.QrCode.Internal;
namespace BITKit
{
public interface ICovertToEntity
{
void CovertToEntity(EntityManager entityManager,Entity entity);
}
public class CovertToEntity : MonoBehaviour
{
private void Start()
{
var _transform = this.transform;
if (Time.time is not 0) return;
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = entityManager.CreateEntity();
foreach (var x in GetComponentsInChildren<ICovertToEntity>())
{
x.CovertToEntity(entityManager,entity);
}
entityManager.AddComponentData(entity, new LocalTransform()
{
Position = _transform.position,
Rotation = _transform.rotation,
});
Destroy(gameObject);
}
}
}