tkunity 2026.10.31__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tkunity/__init__.py +27 -0
- tkunity/__main__.py +8 -0
- tkunity/api.py +112 -0
- tkunity/cli.py +106 -0
- tkunity/components.py +125 -0
- tkunity/editor.py +702 -0
- tkunity/export.py +740 -0
- tkunity/py.typed +0 -0
- tkunity/pyu.py +125 -0
- tkunity/runtime.py +232 -0
- tkunity-2026.10.31.dist-info/LICENSE +216 -0
- tkunity-2026.10.31.dist-info/METADATA +194 -0
- tkunity-2026.10.31.dist-info/RECORD +16 -0
- tkunity-2026.10.31.dist-info/WHEEL +5 -0
- tkunity-2026.10.31.dist-info/entry_points.txt +2 -0
- tkunity-2026.10.31.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: tkunity
|
|
3
|
+
Version: 2026.10.31
|
|
4
|
+
Summary: tkunity - 纯标准库的 Unity 风格 2D 游戏编辑器与运行时,可把 .pyu 游戏导出为 Android APK 工程(Apache 2.0, oiiaio-web)
|
|
5
|
+
Author: oiiaio-web
|
|
6
|
+
Author-email: oiiaio-web <3926580760@qq.com>
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://github.com/oiiaio-web/tkunity
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/oiiaio-web/tkunity/issues
|
|
10
|
+
Keywords: game,editor,tkinter,unity,android,apk,2d
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Games/Entertainment
|
|
21
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Dynamic: author
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
|
|
28
|
+
# tkunity
|
|
29
|
+
|
|
30
|
+
> 纯标准库、零第三方依赖(尤其不依赖 pygame)的 **Unity 风格 2D 游戏编辑器 + 运行时**,
|
|
31
|
+
> 把你在编辑器里拖出来的 `.pyu` 游戏一键导出成 **Android APK 工程**。
|
|
32
|
+
|
|
33
|
+
- **许可证**:Apache License 2.0
|
|
34
|
+
- **作者**:oiiaio-web <3926580760@qq.com>
|
|
35
|
+
- **版本**:2026.10.31
|
|
36
|
+
- **Python**:>= 3.8(开发测试于 3.12)
|
|
37
|
+
- **依赖**:**零**。只使用标准库 `tkinter / json / base64 / argparse / struct`。Linux 上若缺少 tk 图形环境,请安装系统包 `python3-tk`(这不是 pip 依赖)。
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 一、安装
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install -e . # 从源码目录安装(或直接 pip install tkunity 发布后)
|
|
45
|
+
tkunity --version # 查看版本
|
|
46
|
+
tkunity -h / -help / --help # 三种写法功能一样,都显示帮助
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
不需要 pygame、不需要 Kivy、不需要任何 pip 第三方包。
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 二、快速上手
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
tkunity # 启动图形编辑器(左:零件库 / 中:网格画布 / 右:属性面板)
|
|
57
|
+
tkunity edit examples/demo.pyu
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
在编辑器里:
|
|
61
|
+
|
|
62
|
+
1. **左侧「零件库」**:点选一个零件(矩形 / 椭圆 / 文本 / 图片 / 点击触发器 / 定时器),再在中间网格上点一下即可放置;双击零件则放到画布中心。
|
|
63
|
+
2. **中间画布**:按住物体拖动移动位置(自动吸附网格 20px),右下角小方块可拖拽缩放,点选物体右侧出现属性。
|
|
64
|
+
3. **右侧「属性」**:修改名称、坐标、尺寸、颜色、文本、点击动作、定时器动作等;「应用」或按回车生效。
|
|
65
|
+
4. 工具栏:`新建 / 打开 / 保存 / 另存为`(项目文件后缀 **`.pyu`**)、`预览`、`导出APK`。
|
|
66
|
+
|
|
67
|
+
也可以用 API 纯代码建项目:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from tkunity import Project, GameObject, save
|
|
71
|
+
|
|
72
|
+
p = Project(name="弹球", scene_width=960, scene_height=640, background="#1e1e2e")
|
|
73
|
+
ball = GameObject("ball", x=200, y=200, width=60, height=60)
|
|
74
|
+
ball.add_sprite("oval", fill="#f38ba8", outline="#f9e2af")
|
|
75
|
+
ball.add_timer(16, "bounce")
|
|
76
|
+
p.add(ball)
|
|
77
|
+
save(p, "examples/demo.pyu")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
命令行直接导出 APK 工程:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
tkunity build examples/demo.pyu -o out/android_game
|
|
84
|
+
cd out/android_game && ./build_apk.sh # 或 Windows 下 build_apk.bat
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 三、`.pyu` 项目文件格式
|
|
90
|
+
|
|
91
|
+
`.pyu` = 8 字节魔数 `TKU-PYU\x00\x01\n` + 一个 JSON 对象:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"meta": { "tkunity_version": "2026.10.31", "name": "...", "scene_width": 960,
|
|
96
|
+
"scene_height": 640, "background": "#1e1e2e" },
|
|
97
|
+
"entities": [
|
|
98
|
+
{ "id": 1, "name": "ball",
|
|
99
|
+
"components": {
|
|
100
|
+
"Transform": { "x": 200, "y": 200, "width": 60, "height": 60,
|
|
101
|
+
"rotation": 0.0, "layer": 0 },
|
|
102
|
+
"Sprite": { "shape": "oval", "fill": "#f38ba8",
|
|
103
|
+
"outline": "#f9e2af", "image": "" },
|
|
104
|
+
"Label": { "text": "", "font_size": 18, "color": "#000000", "bold": false },
|
|
105
|
+
"TapHandler": { "action": "none" },
|
|
106
|
+
"Timer": { "interval_ms": 16, "action": "bounce" }
|
|
107
|
+
} }
|
|
108
|
+
],
|
|
109
|
+
"assets": { "images/logo.png": "<base64 PNG 数据>" }
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- 图片资源会 **base64 内嵌**进 `.pyu`,单文件自包含,拷走即走。
|
|
114
|
+
- 图片仅支持 **PNG / GIF**(tkinter 原生能力,无第三方库)。
|
|
115
|
+
|
|
116
|
+
### 组件一览
|
|
117
|
+
|
|
118
|
+
| 组件 | 字段 | 说明 |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `Transform` | x, y, width, height, rotation, layer | 所有物体自动拥有,layer 决定绘制层级 |
|
|
121
|
+
| `Sprite` | shape(rect/oval/image), fill, outline, image | 视觉主体 |
|
|
122
|
+
| `Label` | text, font_size, color, bold | 文本,居中显示在物体内 |
|
|
123
|
+
| `TapHandler` | action | 点击动作(桌面预览支持任意 Python 表达式) |
|
|
124
|
+
| `Timer` | interval_ms, action | 定时动作 |
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 四、导出 APK(关键说明)
|
|
129
|
+
|
|
130
|
+
`tkunity build xxx.pyu` 会生成一个**可直接用 Android Studio / Gradle 构建**的完整 Android 工程:
|
|
131
|
+
|
|
132
|
+
- 纯 **Java + org.json**,**零第三方依赖**,minSdk **26**(与你的设备习惯一致),targetSdk 34;
|
|
133
|
+
- `GameView` 用 `android.graphics.Canvas` 渲染场景:网格背景、rect/oval/图片、文本、层级、触摸拖拽、点击、定时器;
|
|
134
|
+
- 内置动作(桌面预览与 APK 通用):`none`、`print(...)`、`move-left / move-right / move-up / move-down`(持续移动)、`bounce`(弹跳并碰边反弹)、`stop`。
|
|
135
|
+
|
|
136
|
+
> **诚实的边界**:`TapHandler/Timer` 里写的**自定义 Python 表达式只在桌面预览中运行**(tkinter 运行时用受限 `eval` 执行)。APK 是独立渲染器,只支持上表「内置动作」。复杂逻辑请用「多个物体 + 定时器 + 内置动作」组合实现,或导出工程后在 `GameView.java` 里扩展。
|
|
137
|
+
|
|
138
|
+
构建工程产物(每项都会生成):
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
out/android_game/
|
|
142
|
+
├── settings.gradle build.gradle gradle.properties
|
|
143
|
+
├── app/build.gradle
|
|
144
|
+
├── app/src/main/AndroidManifest.xml
|
|
145
|
+
├── app/src/main/assets/game.pyu # 游戏数据(含内嵌图片)
|
|
146
|
+
├── app/src/main/java/com/oiiaio/tkunity/
|
|
147
|
+
│ ├── MainActivity.java
|
|
148
|
+
│ └── GameView.java
|
|
149
|
+
├── build_apk.bat / build_apk.sh # 自动下载 Gradle 8.5 并构建
|
|
150
|
+
└── README_BUILD.md
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
构建条件:JDK 17 + Android SDK(设置 `ANDROID_HOME`,或在工程里放 `local.properties: sdk.dir=...`)。构建后 APK 位于 `app/build/outputs/apk/debug/app-debug.apk`。
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 五、运行 API
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
import tkunity
|
|
161
|
+
from tkunity.runtime import Scene
|
|
162
|
+
import tkinter as tk
|
|
163
|
+
|
|
164
|
+
root = tk.Tk()
|
|
165
|
+
game = Scene(root, tkunity.load("examples/demo.pyu"))
|
|
166
|
+
game.pack(fill="both", expand=True)
|
|
167
|
+
game.start()
|
|
168
|
+
root.mainloop()
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## 六、目录结构
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
tkunity/
|
|
177
|
+
├── pyproject.toml / setup.py / LICENSE / README.md
|
|
178
|
+
├── tkunity/
|
|
179
|
+
│ ├── __init__.py # 公共入口 Project/GameObject/save/load
|
|
180
|
+
│ ├── components.py # 组件注册表与零件库
|
|
181
|
+
│ ├── pyu.py # .pyu 序列化(含资源内嵌)
|
|
182
|
+
│ ├── api.py # 面向对象建项目 API
|
|
183
|
+
│ ├── runtime.py # tkinter 游戏运行时
|
|
184
|
+
│ ├── editor.py # Unity 风格三栏编辑器
|
|
185
|
+
│ ├── export.py # Android APK 工程生成器
|
|
186
|
+
│ ├── cli.py # 命令行入口
|
|
187
|
+
│ └── __main__.py
|
|
188
|
+
├── examples/ # 示例游戏(demo.pyu / make_demo.py)
|
|
189
|
+
└── tests/ # 无第三方依赖的冒烟测试(直接 python 运行)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 七、许可证
|
|
193
|
+
|
|
194
|
+
Apache License 2.0,Copyright 2026 oiiaio-web <3926580760@qq.com>。完整文本见 `LICENSE`。
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
tkunity/__init__.py,sha256=2hGOulozo-htyqAXCKAik5TJEPrSuVAKQdmXu0nz7uU,904
|
|
2
|
+
tkunity/__main__.py,sha256=kP1Pl-dap_x-EVWFcAYCGbTr6rkgYJ0w_SyPkSORDGs,141
|
|
3
|
+
tkunity/api.py,sha256=54SRBk4HXblOG7LuaZ1eEAwJ2GKGtHH4KrjyByq0TQc,3697
|
|
4
|
+
tkunity/cli.py,sha256=YjO8jmEcYM5Ru03Cq4D0hmlLQVZ4ZTa-Be4aMbCEFDU,3448
|
|
5
|
+
tkunity/components.py,sha256=okWj_pzpmJbu43wER-ccHoPGm6Lq-WjS_U9R6kRgj8c,5055
|
|
6
|
+
tkunity/editor.py,sha256=XPpv7DXvm4M9SM8PnCjRv2Vg9kFRrFHoaQHs-fXeR-Y,30705
|
|
7
|
+
tkunity/export.py,sha256=cL86-ZkspmXpiqLEPlrGwueN8CUXo4OYEfRAKnfkUig,24852
|
|
8
|
+
tkunity/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
tkunity/pyu.py,sha256=wRx5voAgtxZcn744sGY3_dwXkeXE_hy0dy4K7qJ3cNY,4051
|
|
10
|
+
tkunity/runtime.py,sha256=JHgQpAE5Z2HRdN6dL2ispoKV1oPx0qDHDVvJWiHgTXU,8677
|
|
11
|
+
tkunity-2026.10.31.dist-info/LICENSE,sha256=ejBf0Hfi0uWqx7m9H9ITe1zS1hnqnrvsxMFoRg3S8zo,11936
|
|
12
|
+
tkunity-2026.10.31.dist-info/METADATA,sha256=v2QfoqVGomwFuD8QguCE9EITpdKC5cE7hSmwfwXORYs,7958
|
|
13
|
+
tkunity-2026.10.31.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
|
14
|
+
tkunity-2026.10.31.dist-info/entry_points.txt,sha256=LlJDKQtt8IA8jyEfxN17Zycnn857nLDEA8C-ZicdNIk,45
|
|
15
|
+
tkunity-2026.10.31.dist-info/top_level.txt,sha256=uM8s-PRoGmNeSzmo0GikOBhlVICij3KbqGLQgfSEBhg,8
|
|
16
|
+
tkunity-2026.10.31.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tkunity
|