示例#1
0
        private static void BuildEntityInstance(LDtkDataLayer layerData, LDtkDataEntity entityData,
                                                LDtkEntityAssetCollection entityAssets, GameObject layerObj, int layerSortingOrder)
        {
            LDtkEntityAsset entityAsset = entityAssets.GetAssetByIdentifier(entityData.__identifier);

            if (entityAsset == null)
            {
                return;
            }

            int        pixelsPerUnit = layerData.__gridSize;
            Vector2Int pixelPos      = entityData.px.ToVector2Int();
            Vector2    spawnPos      = (LDtkToolOriginCoordConverter.ConvertPosition(pixelPos, layerData.__cHei * pixelsPerUnit, pixelsPerUnit) / pixelsPerUnit) + Vector2.up;

            InstantiateEntity(entityData, entityAsset.ReferencedAsset, spawnPos, layerObj, layerSortingOrder);
        }
示例#2
0
        private static void BuildEntityInstance(LDtkDataLayer layerData, LDtkDataEntity entityData,
                                                LDtkEntityAssetCollection entityAssets, GameObject layerObj, int layerSortingOrder)
        {
            LDtkEntityAsset entityAsset = entityAssets.GetAssetByIdentifier(entityData.__identifier);

            if (entityAsset == null)
            {
                return;
            }

            int        pixelsPerUnit = layerData.__gridSize;
            Vector2Int pixelPos      = entityData.px.ToVector2Int();
            Vector2    spawnPos      = (LDtkToolOriginCoordConverter.ConvertPosition(pixelPos, layerData.__cHei * pixelsPerUnit, pixelsPerUnit) / pixelsPerUnit) + Vector2.up;

            GameObject entityObj = InstantiateEntity(entityAsset.ReferencedAsset, spawnPos, layerObj);

            LDtkFieldInjector.InjectInstanceFields(entityData, entityObj);

            MonoBehaviour[] behaviors = entityObj.GetComponents <MonoBehaviour>();

            PostEntityInterfaceEvent <ILDtkFieldInjectedEvent>(behaviors, e => e.OnLDtkFieldsInjected());
            PostEntityInterfaceEvent <ILDtkSettableSortingOrder>(behaviors, e => e.OnLDtkSetSortingOrder(layerSortingOrder));
            PostEntityInterfaceEvent <ILDtkSettableOpacity>(behaviors, e => e.OnLDtkSetOpacity(layerData.__opacity));
        }