/// <summary> /// Calculate the correct sorting order for a given position. /// </summary> /// <param name="position">Position that needs a sorting order value.</param> /// <param name="fine">Use fine calculation for within a grid tile.</param> /// <returns></returns> public int CalculateSortingLayer(Vector3 position, bool fine = false) { var cell = go_grid.WorldToCell(position); var transformedCell = new Vector2Int(13 - cell.x, 13 - cell.y); var baseLayer = (transformedCell.x * 12 + transformedCell.y) * SORTING_ORDER_GRANULARITY; if (fine) { var cellPos = getNode(new Vector2Int(cell.x, cell.y)).worldPosition; var posDiff = cellPos - position; var fineLayer = (int)((posDiff.y / (SORTING_ORDER_GRANULARITY / 2)) * 100); return(baseLayer + fineLayer); } else { return(baseLayer); } }
void IConvertGameObjectToEntity.Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var cellCoord = WorldGrid.WorldToCell(transform.position); Debug.Log("Unit coord::" + cellCoord); int2 currentCellCoord = new int2(cellCoord.x, cellCoord.y); dstManager.AddComponentData(entity, new Unit { Id = Id, Fraction = Fraction }); dstManager.AddComponentData(entity, new CopyTransformToGameObject()); var selectionArchetype = dstManager.CreateArchetype(typeof(SpriteRenderer), typeof(Selection)); var selectionEntity = dstManager.CreateEntity(selectionArchetype); dstManager.AddComponentData(selectionEntity, new Selection { LinkedUnit = entity }); dstManager.AddComponentObject(selectionEntity, _selectionSprite); dstManager.AddComponentObject(selectionEntity, _selectionSprite.transform); dstManager.AddComponentData(entity, new UnitController { SelectionEntity = selectionEntity }); dstManager.AddComponentData(entity, new UnitMovement { Speed = Speed, CurrentCellCoord = currentCellCoord, }); }