在 Android 上的 Unity 中运行 Python 程序 [英] Running a Python program in Unity on Android

查看:34
本文介绍了在 Android 上的 Unity 中运行 Python 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR:我可以通过多少种不同的方式在 Android 设备上的 Unity 中运行 Python 程序?

TLDR: How many different ways can I run a Python program in Unity on an Android device?

这是用于存储地理位置的 Android 应用,稍后将在其他设备上查询.

This is for a Android app that stores a geolocation, which is to be queried later on other devices.

我知道 IronPython,但它没有针对 Python 3+ 进行更新,这是我用来编写需要运行的 Python 程序的工具.

I know about IronPython but it is not updated for Python 3+, which is what I used to write the Python program I need to run.

更多背景故事:我正在尝试使用 AWS dynamoDB,它具有 Unity 开发工具包,因为它构建在 .net 上.但是,专门针对查询搜索,他们还没有实现 <或 >或复合搜索,而该实现在 Python 中可用.

More backstory: I am trying to use AWS dynamoDB which has an SDK for Unity as it's built on .net. However, specifically for query search, they have not implemented < or > or compound searches, whereas that implementation is available in Python.

以下 Python 脚本有效.

The following Python script works.

import boto3
import json
import decimal
from boto3.dynamodb.conditions import Key, Attr
import sys

lat = sys.argv[1]
lon = sys.argv[2]
r = sys.argv[3]


# Helper class to convert a DynamoDB item to JSON.
class DecimalEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, decimal.Decimal):
            if o % 1 > 0:
                return float(o)
            else:
                return int(o)
        return super(DecimalEncoder, self).default(o)

dynamodb = boto3.resource('dynamodb')

table = dynamodb.Table('tree')

fe = Key('lon').between((decimal.Decimal(lat) - decimal.Decimal(r)), (decimal.Decimal(lat) + decimal.Decimal(r)))
 #THIS IS THE BETWEEN SEARCH THAT IS NOT AVAILABLE IN UNITY
fe1 = Key('lat').between((decimal.Decimal(lon) - decimal.Decimal(r)), (decimal.Decimal(lon) + decimal.Decimal(r)))
pe = "#l, lon, treeStage"
# Expression Attribute Names for Projection Expression only.
ean = { "#l": "lat", }
esk = None


response = table.scan(
    FilterExpression=fe,
    ProjectionExpression=pe,
    ExpressionAttributeNames=ean
    )

for i in response['Items']:
    print(json.dumps(i, cls=DecimalEncoder))

while 'LastEvaluatedKey' in response:
    response = table.scan(
        ProjectionExpression=pe,
        FilterExpression=fe and fe1, #THIS IS THE COMPOUND SEARCH THAT DOESNT WORK IN UNITY
        ExpressionAttributeNames= ean,
        ExclusiveStartKey=response['LastEvaluatedKey']
        
        )

    for i in response['Items']:
        print(json.dumps(i, cls=DecimalEncoder))

我的问题是:我有哪些可用选项可以通过 Unity 的 C# 将这个 Python 程序构建成可以在 Android 设备上运行的文件类型?

My question is: what available options do I have to build this Python program into a file type that could be run on an Android device through Unity's C#?

目前我只是打印从 dynamoDB 收到的信息,但我愿意直接读取它或写入文件以在必要时在 Unity 中读取.

Currently I'm just printing the info received from dynamoDB, but I would be open to reading it directly or writing to a file to read in Unity if necessary.

推荐答案

没有执行此操作的高性能和维护解决方案.有一些社区制作的解决方案,但它们对于生产游戏来说太不稳定了.

There no performant and maintained solution to do this. There are some community-made solutions but they are too unstable for a production game.

您可以在网络服务上托管此 Python 脚本.您可以调用 webservers,它会获取数据并进行处理,然后返回给您.这种方式可能是最简单、最有效的.

You can host this python script on a webservices. You can call webserives, it will get data and process it then returns to you. This way is probably the easiest and most efficient.

如果不可能,您可以使用 python-for-android.但这会使事情复杂化,而且根本没有性能.

If not possible, you can use python-for-android. But this complicates things alot and not performant at all.

这篇关于在 Android 上的 Unity 中运行 Python 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆