45 lines
982 B
C#
45 lines
982 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using Unity.Entities;
|
|
using UnityEngine;
|
|
|
|
public interface IdProvider
|
|
{
|
|
ulong Id { get; }
|
|
}
|
|
[System.Serializable]
|
|
public struct IdComponent:IComponentData
|
|
{
|
|
public ulong Id;
|
|
}
|
|
[System.Serializable]
|
|
public struct ConstId:IdProvider
|
|
{
|
|
[SerializeField]
|
|
private ulong Id;
|
|
ulong IdProvider.Id => Id;
|
|
}
|
|
|
|
[System.Serializable]
|
|
public struct GetIdFromInstanceId : IdProvider
|
|
{
|
|
[SerializeField] private GameObject gameObject;
|
|
ulong IdProvider.Id => (ulong)gameObject.GetInstanceID();
|
|
}
|
|
|
|
public class IdComponentConvert : MonoBehaviour,ICovertToEntity
|
|
{
|
|
[SerializeField, SerializeReference, SubclassSelector]
|
|
private IdProvider provider;
|
|
|
|
public void CovertToEntity(EntityManager entityManager, Entity entity)
|
|
{
|
|
var component = new IdComponent()
|
|
{
|
|
Id = provider.Id,
|
|
};
|
|
entityManager.AddComponentData(entity, component);
|
|
}
|
|
}
|