So hey i have the following depreciated dots code and im not certain how do i convert it to the new dots system.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using static Terrain;
using System.Diagnostics;
public class OnEntityAssign : MonoBehaviour ,IConvertGameObjectToEntity
{
private Entity entity;
private EntityManager entityManager;
public PathIndex pathIndex;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
this.entity = entity;
this.entityManager = dstManager;
dstManager.AddBuffer<PathBuffer>(entity);
}
public Entity GetEntity()
{
return entity;
}
public EntityManager GetEntityManager()
{
return entityManager;
}
public PathIndex GetPathIndex()
{
return entityManager.GetComponentData<PathIndex>(entity);
}
public DynamicBuffer<PathBuffer> GetPathBuffer()
{
return entityManager.GetBuffer<PathBuffer>(entity);
}
public void SetComponentData(PathIndex pathIndex)
{
entityManager.SetComponentData(entity, pathIndex);
}
public void EnityConvert()
{
//this.gameObject.AddComponent<ConvertToEntity>();
}
}
First things first, everything that is public needs to be made nonpublic (except for Convert). Bakers don’t really have a way to communicate with each other. And MonoBehaviours need to be treated as readonly data.
1 Like
→ Baker overview | Entities | 1.0.16
(Oh boy am I glad they changed to the Baker workflow, this looks awful)
2 Likes
So if anybody is curious here is how i rewrote and it works now so neat
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using static Terrain;
using System.Diagnostics;
public struct OnEntityAssign : IComponentData
{
public Entity entity;
public Entity GetEntity()
{
return entity;
}
public EntityManager GetEntityManager()
{
return World.DefaultGameObjectInjectionWorld.EntityManager;
}
public PathIndex GetPathIndex()
{
return GetEntityManager().GetComponentData<PathIndex>(GetEntity());
}
public void InitBuffer()
{
GetEntityManager().AddBuffer<PathBuffer>(GetEntity());
}
public DynamicBuffer<PathBuffer> GetPathBuffer()
{
return GetEntityManager().GetBuffer<PathBuffer>(GetEntity());
}
public void SetComponentData(PathIndex pathIndex)
{
GetEntityManager().SetComponentData(GetEntity(), pathIndex);
}
}
and the baker:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
public class OnEntityAuthoring : MonoBehaviour
{
public int id;
}
public class OnEntityAssignBaker : Baker<OnEntityAuthoring>
{
public override void Bake(OnEntityAuthoring authoring)
{
var entityy = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entityy, new OnEntityAssign
{
entity = entityy,
});
}
}