blueloveTH před 2 roky
rodič
revize
ee2d69dcd6
2 změnil soubory, kde provedl 35 přidání a 3 odebrání
  1. 32 0
      docs/unity/console.md
  2. 3 3
      docs/unity/introduction.md

+ 32 - 0
docs/unity/console.md

@@ -0,0 +1,32 @@
+---
+label: Python Console
+icon: dot
+order: 5
+---
+
+You can open the Python console in Unity by clicking the `Window/Python Console` menu item.
+
+By default, the console creates a unmodified `VM` instance to execute your code.
+You may want to provide an enhanced `VM` instance for the console in Unity Editor.
+For example, adding some class bindings in `UnityEngine` namespace.
+
+To do this, you need to create a class derived from `VM` and put it in `Assets/Editor/` folder.
+By adding `[EditorVM]` attribute to the class,
+the console will use it instead of the default `VM` instance.
+
+
+```csharp
+using UnityEngine;
+using PocketPython;
+
+[EditorVM]      // this attribute is required
+public class EnhancedVM: VM{
+    public EnhancedVM() {
+        RegisterAutoType<GameObject>(builtins);
+        RegisterAutoType<Transform>(builtins);
+        RegisterAutoType<Vector2>(builtins);
+        RegisterAutoType<Vector3>(builtins);
+        // ...
+    }
+}
+```

+ 3 - 3
docs/unity/introduction.md

@@ -43,7 +43,7 @@ The features marked with `YES` are supported, and the features marked with `NO`
 | Unpacking       | `a, b = 1, 2`                   | YES       | YES |
 | Star Unpacking  | `a, *b = [1, 2, 3]`             | YES       | YES |
 | Exception       | `raise/try..catch`              | YES       | NO |
-| Dynamic Code    | `eval()/exec()`                 | YES       | NO |
+| Dynamic Code    | `eval()/exec()`                 | YES       | YES |
 | Reflection      | `hasattr()/getattr()/setattr()` | YES       | YES |
 | Import          | `import/from..import`           | YES       | YES |
 | Context Block   | `with <expr> as <id>:`          | YES       | NO |
@@ -65,7 +65,7 @@ which means passing arguments between C# and Python is extremely easy and intuit
 
 | Python Type | C# Type |
 | ----------- | ------- |
-| `None`      | `PocketPy.NoneType` |
+| `None`      | `NoneType` |
 | `object`    | `System.Object` |
 | `bool`      | `System.Boolean` |
 | `int`       | `System.Int32` |
@@ -73,7 +73,7 @@ which means passing arguments between C# and Python is extremely easy and intuit
 | `str`       | `System.String` |
 | `tuple`     | `System.Object[]` |
 | `list`      | `System.Collections.Generic.List<object>` |
-| `dict`      | `System.Collections.Generic.Dictionary<PocketPy.PyDictKey, object>` |
+| `dict`      | `System.Collections.Generic.Dictionary<PyDictKey, object>` |
 | ...         | ... |
 
 ### Python Console in Editor