def init_app(plat, package_name, app_path, sleep_time, serialno=None): dev = None if plat.lower().find('android') >= 0: if serialno: if re.search('127.0.0.1:\d+', serialno): dev = connect_device('Android:///{}?cap_method=JAVACAP&ori_method=ADBORI'.format(serialno)) else: dev = connect_device('Android:///{}'.format(serialno)) else: dev = connect_device('Android:///') wake() install_android_app(current_device().adb, app_path) stop_app(package_name) start_app(package_name) sleep(sleep_time / 1.5) elif plat == 'PC_editor': w = Windows() dev = UnityEditorWindow() w.keyevent('^P') # Ctrl+P运行 sleep(sleep_time / 2) dev.stop_app = w.app # 用于获取进程id,结束进程用 elif plat == 'PC_win': w = Windows() w.start_app(app_path) sleep(sleep_time) w.connect(process=w.app.process) dev = connect_device("Windows:///?class_name=UnityWndClass") dev.stop_app = w.app # elif plat == 'iOS': # pass # elif plat == 'MAC_editor': # pass return dev
def init_app(plat=SD.PLAT, package_name=SD.PACKAGE_NAME, app_path=SD.APP_PATH[SD.PLAT], sleep_time=SD.SLEEP_TIME, serialno=SD.SERIALNO): dev = None if plat == 'android': if SD.USE_ATX_SERVER2: atx_server2 = AtxServer2() device_info = atx_server2.get_usable_device_info() SD.UDID = device_info['udid'] serialno = device_info['source']['remoteConnectAddress'] if serialno and serialno.strip() != '': if re.search(r'127.0.0.1:\d+', serialno): logger.debug('模拟器用JAVACAP和ADBORI') dev = connect_device(f'Android:///{serialno}?cap_method=JAVACAP&ori_method=ADBORI') else: logger.debug(f'指定连接serialno: {serialno}') dev = connect_device(f'Android:///{serialno}') else: dev = connect_device('Android:///') wake() install_android_app(current_device().adb, app_path) stop_app(package_name) logger.debug(f'启动app:{package_name}') start_app(package_name) sleep(sleep_time / 1.5) elif plat == 'pc_editor': w = Windows() dev = UnityEditorWindow() w.keyevent('^P') # Ctrl+P运行 sleep(sleep_time / 2) dev.stop_app = w.app # 用于获取进程id,结束进程用 elif plat == 'pc_win': w = Windows() w.start_app(app_path) sleep(sleep_time) w.connect(process=w.app.process) dev = connect_device("Windows:///?class_name=UnityWndClass") dev.stop_app = w.app # elif plat == 'ios': # pass # elif plat == 'mac_editor': # pass return dev
def __init__(self, addr=DEFAULT_ADDR, unity_editor=False, connect_default_device=True, device=None, **options): if 'action_interval' not in options: options['action_interval'] = 0.5 if unity_editor: dev = UnityEditorWindow() else: dev = device if dev is None and connect_default_device and not current_device(): # currently only connect to Android as default # can apply auto detection in the future dev = connect_device("Android:///") super(UnityPoco, self).__init__(addr[1], dev, **options) self.vr = UnityVRSupport(self.agent.rpc)
# -*- encoding=utf8 -*- from poco.drivers.unity3d import UnityPoco # Unity用のインポート. # Windows用の初期化処理. from poco.drivers.unity3d.device import UnityEditorWindow # UnityEditor用のインポート. dev = UnityEditorWindow() # デバイスにUnityEditorを指定. addr = ('', 5001) # 接続先のIPアドレスを指定. poco = UnityPoco(addr, device=dev) import time # Unity用のPocoを生成 poco("Button1").click() time.sleep(1.0)