public void CalculatePath(Entity entity) { //reading of the start and end positions and generation of the path to provide it to the //entity that is related later Translation ballposEnemy = manager.GetComponentData <Translation>(entity); startPosition = ballposEnemy.Value; NavMeshPath path = new NavMeshPath(); targetPosition = AppManager.instance.playerPosition; NavMesh.CalculatePath(startPosition, targetPosition, NavMesh.AllAreas, path); // set nodeindex to 0 so the Job does not run during update ActiveNodeIndexData nodeIndex = manager.GetComponentData <ActiveNodeIndexData>(entity); ActiveNodeIndexData tempNode = nodeIndex; tempNode.nodeInPath = 0; manager.SetComponentData(entity, tempNode); //when you do not reload the buffer directly from the entity but rather try to cach it then //you get spammed by errors telling you the native array has been deallocated and cant be accessed DynamicBuffer <Float3BufferElement> float3Buffer = manager.GetBuffer <Float3BufferElement>(entity); float3Buffer.Clear(); for (int i = 0; i < path.corners.Length; i++) { convertPlaceholder = path.corners[i]; float3Buffer.Add(new Float3BufferElement { Value = convertPlaceholder }); } //reset the variables since they could have bneen changed by other operations in the mean time //by another script nodeIndex = manager.GetComponentData <ActiveNodeIndexData>(entity); tempNode = nodeIndex; tempNode.nodeInPath = 1; manager.SetComponentData(entity, tempNode); OJO_RequestRecalculationData recalc = manager.GetComponentData <OJO_RequestRecalculationData>(entity); recalc.requestState = MyCode.RequestState.NoRequest; manager.SetComponentData(entity, recalc); return; }
public void Convert(Entity entity, EntityManager manager, GameObjectConversionSystem conversionSystem) { World.DefaultGameObjectInjectionWorld.EntityManager.AddBuffer <Float3BufferElement>(entity); World.DefaultGameObjectInjectionWorld.EntityManager.AddComponent <ActiveNodeIndexData>(entity); World.DefaultGameObjectInjectionWorld.EntityManager.AddComponent <RecalcTag>(entity); World.DefaultGameObjectInjectionWorld.EntityManager.AddComponent <RaycastRecalcTimer>(entity); World.DefaultGameObjectInjectionWorld.EntityManager.AddComponent <OJO_TargetPointData>(entity); World.DefaultGameObjectInjectionWorld.EntityManager.AddComponent <OJO_RequestRecalculationData>(entity); OJO_RequestRecalculationData recalc = manager.GetComponentData <OJO_RequestRecalculationData>(entity); RaycastRecalcTimer rayRecalc = manager.GetComponentData <RaycastRecalcTimer>(entity); recalc.requestState = MyCode.RequestState.InitializeRequest; manager.SetComponentData(entity, recalc); rayRecalc.timer = UnityEngine.Random.Range(0.00f, 2.00f); manager.SetComponentData(entity, rayRecalc); }