Skip to content

🏷️ 支持交互控制的能力

tongsim.entity.ability.impl.interactable

tongsim.entity.ability.impl.interactable

InteractableAbility

Bases: Protocol

InteractableAbility 定义了支持交互控制的实体能力接口。

Source code in src\tongsim\entity\ability\impl\interactable.py
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
class InteractableAbility(Protocol):
    """
    InteractableAbility 定义了支持交互控制的实体能力接口。
    """

    async def async_get_active_state(self) -> bool:
        """
        异步获取当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

        Returns:
            bool: True 表示激活,False 表示未激活。
        """

    def get_active_state(self) -> bool:
        """
        同步获取当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

        Returns:
            bool: True 表示激活,False 表示未激活。
        """

    async def async_set_active_state(self, is_active: bool) -> bool:
        """
        异步设置当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

        Args:
            is_active (bool): True 表示激活,False 表示关闭。

        Returns:
            bool: 是否设置成功。
        """

    def set_active_state(self, is_active: bool) -> bool:
        """
        同步设置当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

        Args:
            is_active (bool): True 表示激活,False 表示关闭。

        Returns:
            bool: 是否设置成功。
        """

    async def async_get_interact_point(self) -> Vector3:
        """
        异步获取当前实体的交互点。依赖资产配置,若资产配置缺失,则返回 物体锚点。

        Returns:
            Vector3: 交互点的世界坐标。
        """

    def get_interact_point(self) -> Vector3:
        """
        同步获取当前实体的交互点信息。依赖资产配置,若资产配置缺失,则返回 物体锚点。

        Returns:
            Vector3: 交互点的世界坐标。
        """

    async def async_get_group_id(self) -> str:
        """
        异步获取当前实体的分组 ID。

        Returns:
            str: 分组 ID。
        """

    def get_group_id(self) -> str:
        """
        同步获取当前实体的分组 ID。

        Returns:
            str: 分组 ID。
        """

    async def async_get_entity_ids_in_same_group(self) -> list[str]:
        """
        异步获取同一分组内所有实体的 ID。

        Returns:
            list[str]: 实体 ID 列表。
        """

    def get_entity_ids_in_same_group(self) -> list[str]:
        """
        同步获取同一分组内所有实体的 ID。

        Returns:
            list[str]: 实体 ID 列表。
        """

    async def async_set_group_id(self, new_group_id: str) -> bool:
        """
        异步设置当前实体的分组 ID。

        Args:
            new_group_id (str): 新的分组 ID。

        Returns:
            bool: 是否设置成功。
        """

    def set_group_id(self, new_group_id: str) -> bool:
        """
        同步设置当前实体的分组 ID。

        Args:
            new_group_id (str): 新的分组 ID。

        Returns:
            bool: 是否设置成功。
        """

    def is_working(self) -> bool:
        """
        同步获取当前实体是否正在运作(例如电器是否正在工作)。

        Returns:
            bool: True 表示正在工作,False 表示未工作。
        """

    async def async_is_working(self) -> bool:
        """
        异步获取当前实体是否正在运作(例如电器是否正在工作)。

        Returns:
            bool: True 表示正在工作,False 表示未工作。
        """

    async def async_get_place_point(self) -> Vector3:
        """
        异步获取当前实体的配置的放置点。依赖资产配置,若资产配置缺失,则返回物体锚点。
        举例:
        - 获取 饮水机接水时 的 水杯放置位置
        - 获取 够不着的水龙头交互时 的 凳子放置位置

        Returns:
            Vector3: 交互点的世界坐标。
        """

    def get_place_point(self) -> Vector3:
        """
        同步获取当前实体的配置的放置点。依赖资产配置,若资产配置缺失,则返回物体锚点。
        举例:
        - 获取 饮水机接水时 的 水杯放置位置
        - 获取 够不着的水龙头交互时 的 凳子放置位置

        Returns:
            Vector3: 交互点的世界坐标。
        """

    async def async_set_ui_text(self, text: str) -> bool:
        """
        设置一个物体显示的文本,如支持文本显示功能
        举例:
        - 设置密码锁显示文本

        Args:
            text (str): 需要显示的文本。

        Returns:
            bool: 成功与否。
        """

    def set_ui_text(self, text: str) -> bool:
        """
        设置一个物体显示的文本,如支持文本显示功能
        举例:
        - 设置密码锁显示文本

        Args:
            text (str): 需要显示的文本。

        Returns:
            bool: 成功与否。
        """

async_get_active_state async

async_get_active_state() -> bool

异步获取当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

Returns:

Name Type Description
bool bool

True 表示激活,False 表示未激活。

Source code in src\tongsim\entity\ability\impl\interactable.py
22
23
24
25
26
27
28
async def async_get_active_state(self) -> bool:
    """
    异步获取当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

    Returns:
        bool: True 表示激活,False 表示未激活。
    """

get_active_state

get_active_state() -> bool

同步获取当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

Returns:

Name Type Description
bool bool

True 表示激活,False 表示未激活。

Source code in src\tongsim\entity\ability\impl\interactable.py
30
31
32
33
34
35
36
def get_active_state(self) -> bool:
    """
    同步获取当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

    Returns:
        bool: True 表示激活,False 表示未激活。
    """

async_set_active_state async

async_set_active_state(is_active: bool) -> bool

异步设置当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

Parameters:

Name Type Description Default
is_active bool

True 表示激活,False 表示关闭。

required

Returns:

Name Type Description
bool bool

是否设置成功。

Source code in src\tongsim\entity\ability\impl\interactable.py
38
39
40
41
42
43
44
45
46
47
async def async_set_active_state(self, is_active: bool) -> bool:
    """
    异步设置当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

    Args:
        is_active (bool): True 表示激活,False 表示关闭。

    Returns:
        bool: 是否设置成功。
    """

set_active_state

set_active_state(is_active: bool) -> bool

同步设置当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

Parameters:

Name Type Description Default
is_active bool

True 表示激活,False 表示关闭。

required

Returns:

Name Type Description
bool bool

是否设置成功。

Source code in src\tongsim\entity\ability\impl\interactable.py
49
50
51
52
53
54
55
56
57
58
def set_active_state(self, is_active: bool) -> bool:
    """
    同步设置当前实体的激活状态。注意如果一个电器没有通电,状态激活了也不会工作。

    Args:
        is_active (bool): True 表示激活,False 表示关闭。

    Returns:
        bool: 是否设置成功。
    """

async_get_interact_point async

async_get_interact_point() -> Vector3

异步获取当前实体的交互点。依赖资产配置,若资产配置缺失,则返回 物体锚点。

Returns:

Name Type Description
Vector3 Vector3

交互点的世界坐标。

Source code in src\tongsim\entity\ability\impl\interactable.py
60
61
62
63
64
65
66
async def async_get_interact_point(self) -> Vector3:
    """
    异步获取当前实体的交互点。依赖资产配置,若资产配置缺失,则返回 物体锚点。

    Returns:
        Vector3: 交互点的世界坐标。
    """

get_interact_point

get_interact_point() -> Vector3

同步获取当前实体的交互点信息。依赖资产配置,若资产配置缺失,则返回 物体锚点。

Returns:

Name Type Description
Vector3 Vector3

交互点的世界坐标。

Source code in src\tongsim\entity\ability\impl\interactable.py
68
69
70
71
72
73
74
def get_interact_point(self) -> Vector3:
    """
    同步获取当前实体的交互点信息。依赖资产配置,若资产配置缺失,则返回 物体锚点。

    Returns:
        Vector3: 交互点的世界坐标。
    """

async_get_group_id async

async_get_group_id() -> str

异步获取当前实体的分组 ID。

Returns:

Name Type Description
str str

分组 ID。

Source code in src\tongsim\entity\ability\impl\interactable.py
76
77
78
79
80
81
82
async def async_get_group_id(self) -> str:
    """
    异步获取当前实体的分组 ID。

    Returns:
        str: 分组 ID。
    """

get_group_id

get_group_id() -> str

同步获取当前实体的分组 ID。

Returns:

Name Type Description
str str

分组 ID。

Source code in src\tongsim\entity\ability\impl\interactable.py
84
85
86
87
88
89
90
def get_group_id(self) -> str:
    """
    同步获取当前实体的分组 ID。

    Returns:
        str: 分组 ID。
    """

async_get_entity_ids_in_same_group async

async_get_entity_ids_in_same_group() -> list[str]

异步获取同一分组内所有实体的 ID。

Returns:

Type Description
list[str]

list[str]: 实体 ID 列表。

Source code in src\tongsim\entity\ability\impl\interactable.py
92
93
94
95
96
97
98
async def async_get_entity_ids_in_same_group(self) -> list[str]:
    """
    异步获取同一分组内所有实体的 ID。

    Returns:
        list[str]: 实体 ID 列表。
    """

get_entity_ids_in_same_group

get_entity_ids_in_same_group() -> list[str]

同步获取同一分组内所有实体的 ID。

Returns:

Type Description
list[str]

list[str]: 实体 ID 列表。

Source code in src\tongsim\entity\ability\impl\interactable.py
100
101
102
103
104
105
106
def get_entity_ids_in_same_group(self) -> list[str]:
    """
    同步获取同一分组内所有实体的 ID。

    Returns:
        list[str]: 实体 ID 列表。
    """

async_set_group_id async

async_set_group_id(new_group_id: str) -> bool

异步设置当前实体的分组 ID。

Parameters:

Name Type Description Default
new_group_id str

新的分组 ID。

required

Returns:

Name Type Description
bool bool

是否设置成功。

Source code in src\tongsim\entity\ability\impl\interactable.py
108
109
110
111
112
113
114
115
116
117
async def async_set_group_id(self, new_group_id: str) -> bool:
    """
    异步设置当前实体的分组 ID。

    Args:
        new_group_id (str): 新的分组 ID。

    Returns:
        bool: 是否设置成功。
    """

set_group_id

set_group_id(new_group_id: str) -> bool

同步设置当前实体的分组 ID。

Parameters:

Name Type Description Default
new_group_id str

新的分组 ID。

required

Returns:

Name Type Description
bool bool

是否设置成功。

Source code in src\tongsim\entity\ability\impl\interactable.py
119
120
121
122
123
124
125
126
127
128
def set_group_id(self, new_group_id: str) -> bool:
    """
    同步设置当前实体的分组 ID。

    Args:
        new_group_id (str): 新的分组 ID。

    Returns:
        bool: 是否设置成功。
    """

is_working

is_working() -> bool

同步获取当前实体是否正在运作(例如电器是否正在工作)。

Returns:

Name Type Description
bool bool

True 表示正在工作,False 表示未工作。

Source code in src\tongsim\entity\ability\impl\interactable.py
130
131
132
133
134
135
136
def is_working(self) -> bool:
    """
    同步获取当前实体是否正在运作(例如电器是否正在工作)。

    Returns:
        bool: True 表示正在工作,False 表示未工作。
    """

async_is_working async

async_is_working() -> bool

异步获取当前实体是否正在运作(例如电器是否正在工作)。

Returns:

Name Type Description
bool bool

True 表示正在工作,False 表示未工作。

Source code in src\tongsim\entity\ability\impl\interactable.py
138
139
140
141
142
143
144
async def async_is_working(self) -> bool:
    """
    异步获取当前实体是否正在运作(例如电器是否正在工作)。

    Returns:
        bool: True 表示正在工作,False 表示未工作。
    """

async_get_place_point async

async_get_place_point() -> Vector3

异步获取当前实体的配置的放置点。依赖资产配置,若资产配置缺失,则返回物体锚点。 举例: - 获取 饮水机接水时 的 水杯放置位置 - 获取 够不着的水龙头交互时 的 凳子放置位置

Returns:

Name Type Description
Vector3 Vector3

交互点的世界坐标。

Source code in src\tongsim\entity\ability\impl\interactable.py
146
147
148
149
150
151
152
153
154
155
async def async_get_place_point(self) -> Vector3:
    """
    异步获取当前实体的配置的放置点。依赖资产配置,若资产配置缺失,则返回物体锚点。
    举例:
    - 获取 饮水机接水时 的 水杯放置位置
    - 获取 够不着的水龙头交互时 的 凳子放置位置

    Returns:
        Vector3: 交互点的世界坐标。
    """

get_place_point

get_place_point() -> Vector3

同步获取当前实体的配置的放置点。依赖资产配置,若资产配置缺失,则返回物体锚点。 举例: - 获取 饮水机接水时 的 水杯放置位置 - 获取 够不着的水龙头交互时 的 凳子放置位置

Returns:

Name Type Description
Vector3 Vector3

交互点的世界坐标。

Source code in src\tongsim\entity\ability\impl\interactable.py
157
158
159
160
161
162
163
164
165
166
def get_place_point(self) -> Vector3:
    """
    同步获取当前实体的配置的放置点。依赖资产配置,若资产配置缺失,则返回物体锚点。
    举例:
    - 获取 饮水机接水时 的 水杯放置位置
    - 获取 够不着的水龙头交互时 的 凳子放置位置

    Returns:
        Vector3: 交互点的世界坐标。
    """

async_set_ui_text async

async_set_ui_text(text: str) -> bool

设置一个物体显示的文本,如支持文本显示功能 举例: - 设置密码锁显示文本

Parameters:

Name Type Description Default
text str

需要显示的文本。

required

Returns:

Name Type Description
bool bool

成功与否。

Source code in src\tongsim\entity\ability\impl\interactable.py
168
169
170
171
172
173
174
175
176
177
178
179
async def async_set_ui_text(self, text: str) -> bool:
    """
    设置一个物体显示的文本,如支持文本显示功能
    举例:
    - 设置密码锁显示文本

    Args:
        text (str): 需要显示的文本。

    Returns:
        bool: 成功与否。
    """

set_ui_text

set_ui_text(text: str) -> bool

设置一个物体显示的文本,如支持文本显示功能 举例: - 设置密码锁显示文本

Parameters:

Name Type Description Default
text str

需要显示的文本。

required

Returns:

Name Type Description
bool bool

成功与否。

Source code in src\tongsim\entity\ability\impl\interactable.py
181
182
183
184
185
186
187
188
189
190
191
192
def set_ui_text(self, text: str) -> bool:
    """
    设置一个物体显示的文本,如支持文本显示功能
    举例:
    - 设置密码锁显示文本

    Args:
        text (str): 需要显示的文本。

    Returns:
        bool: 成功与否。
    """