#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 示例脚本 - 演示如何编写脚本 """ from core.script_system import ScriptBase class ExampleScript(ScriptBase): """示例脚本类""" def __init__(self): super().__init__() self.counter = 0 self.rotation_speed = 30.0 # 度/秒 def start(self): """脚本开始时调用""" self.log("示例脚本开始运行!") self.log(f"挂载到对象: {self.gameObject.getName()}") def update(self, dt): """每帧更新""" self.counter += 1 # 每60帧输出一次信息 if self.counter % 60 == 0: self.log(f"运行了 {self.counter} 帧") # 让对象旋转 if self.transform: current_h = self.transform.getH() new_h = current_h + self.rotation_speed * dt self.transform.setH(new_h) def on_destroy(self): """脚本销毁时调用""" self.log("示例脚本被销毁") def on_enable(self): """脚本启用时调用""" self.log("示例脚本被启用") def on_disable(self): """脚本禁用时调用""" self.log("示例脚本被禁用")