Skip to content

Commit 22bf600

Browse files
committed
update doc: add poco.sendMessage(), poco.invoke()
1 parent ed1f5fd commit 22bf600

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

doc/drivers/unity3d.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,65 @@ If you are going to control multiple devices in the same test case, please follo
134134
ui2.swipe('up')
135135
136136
137+
Integrating and Using Poco Interface Functions in Unity
138+
-------------------------------------------------------
139+
140+
This document serves as a guide for integrating and using the new ``UnityPoco.sendMessage()`` and ``UnityPoco.invoke()`` functions in your Unity project.
141+
These functions facilitate communication between your Unity game and Poco, allowing for simple calls with single string arguments or calls with custom arguments.
142+
143+
Getting Started
144+
````````````````
145+
146+
Before using the new interfaces, ensure that you have the latest version of the Poco SDK that includes the changelog updates mentioned. This functionality relies on the updates provided in https://github.com/AirtestProject/Poco-SDK/pull/123.
147+
148+
Using the ``sendMessage()`` Function
149+
`````````````````````````````````````
150+
151+
The ``UnityPoco.sendMessage()`` function allows you to send simple messages with a single string argument from Poco to Unity.
152+
153+
Poco-side
154+
~~~~~~~~~
155+
156+
To use the ``sendMessage()`` function on the Poco side, you just need to call it and pass the message.
157+
158+
.. code-block:: python
159+
160+
poco = UnityPoco()
161+
poco.sendMessage("Your message here")
162+
163+
164+
165+
Using the ``invoke()`` Function
166+
```````````````````````````````
167+
168+
The ``UnityPoco.invoke()`` function allows for more complex interactions with custom arguments.
169+
170+
Poco-side
171+
~~~~~~~~~
172+
173+
To use the ``invoke()`` function on the Poco side, you'll need to specify the listener and the arguments you want to pass.
174+
175+
.. code-block:: python
176+
177+
poco = UnityPoco()
178+
poco.invoke(listener="say_hello", name="anonymous", year=2024)
179+
180+
Unity-side
181+
~~~~~~~~~~
182+
183+
On the Unity side, set up a method that will be called when ``invoke()`` is used from Poco.
184+
185+
1. Create a class that derives from ``PocoListenerBase``.
186+
2. Add a method that corresponds to the ``invoke()`` call:
187+
188+
.. code-block:: csharp
189+
190+
[PocoMethod("say_hello")]
191+
public void SayHello(string name, int year)
192+
{
193+
Debug.Log($"Hi, {name}! The year {year} is coming soon!");
194+
}
195+
196+
3. Add a reference to the new class in the ``PocoManager`` so that it knows to listen for calls to the ``say_hello`` method.
197+
137198
.. _airtest.core.api.connect_device: https://airtest.readthedocs.io/en/latest/all_module/airtest.core.api.html#airtest.core.api.connect_device

0 commit comments

Comments
 (0)