diff --git a/lib/modules/viewer/backend/unity3d-connector.jsx b/lib/modules/viewer/backend/unity3d-connector.jsx
index 09bb8e9..5ced67b 100644
--- a/lib/modules/viewer/backend/unity3d-connector.jsx
+++ b/lib/modules/viewer/backend/unity3d-connector.jsx
@@ -3,6 +3,7 @@ import React from 'react'
import autoBind from 'react-autobind'
import _ from 'lodash'
import linkState from 'react-link-state'
+import {Tabs, Tab} from 'react-bootstrap'
import IconButton from '../../util/IconButton'
import {TinyLabeledInput, Checkbox} from '../../util/Form'
@@ -28,6 +29,11 @@ class DevicesTracker extends AdbDevices {
}
+const PLATFORM_ANDROID = 1
+const PLATFORM_WINDOWS = 2
+const PLATFORM_IOS = 3
+
+
export class Unity3dDeviceConnector extends React.Component {
constructor(props) {
super(props)
@@ -37,6 +43,9 @@ export class Unity3dDeviceConnector extends React.Component {
ip: initialState.ip || 'localhost',
port: initialState.port || '5001',
useAdbForward: initialState.useAdbForward || false,
+ connectUnityWindowsAppUnityEditorMode: initialState.connectUnityWindowsAppUnityEditorMode || false,
+ windowsTitleRe: initialState.windowsTitleRe || '^.*unity3d game.*$',
+ platformSelectionKey: initialState.platformSelectionKey || 1,
// adb forward 模式下才有用
devices: {},
@@ -56,22 +65,30 @@ export class Unity3dDeviceConnector extends React.Component {
return
}
- if (this.state.useAdbForward) {
+ let platform = ''
+ let options = {}
+ if (this.state.platformSelectionKey === PLATFORM_ANDROID) {
+ platform = 'android'
+ if (this.state.useAdbForward) {
+ ip = 'localhost'
+ this.adbClient.forward(this.state.selectedDeviceSerialNo, `tcp:${port}`, `tcp:${port}`)
+ .then(() => {
+ this.props.onConnectDevice(view)
+ })
+ }
+ } else if (this.state.platformSelectionKey === PLATFORM_WINDOWS) {
ip = 'localhost'
- }
-
- let view =
-
- if (this.state.useAdbForward) {
- this.adbClient.forward(this.state.selectedDeviceSerialNo, `tcp:${port}`, `tcp:${port}`)
- .then(() => {
- this.props.onConnectDevice(view)
- })
+ platform = 'windows'
+ options.titleRe = this.state.windowsTitleRe
+ options.isUnityEditor = this.state.connectUnityWindowsAppUnityEditorMode
} else {
- this.props.onConnectDevice(view)
+ platform = 'any'
}
localStorage.setItem('Unity3dDeviceConnector.default.initialState', JSON.stringify(this.state))
+
+ let view =
+ this.props.onConnectDevice(view)
}
prepareDeviceTracker() {
@@ -82,6 +99,9 @@ export class Unity3dDeviceConnector extends React.Component {
this.deviceTracker = null
}
}
+ handleSelectPlatform(key) {
+ this.setState({platformSelectionKey: key})
+ }
componentDidUpdate() {
this.prepareDeviceTracker()
@@ -108,22 +128,40 @@ export class Unity3dDeviceConnector extends React.Component {
return
- {!this.state.useAdbForward &&
+ {!(this.state.useAdbForward || this.state.platformSelectionKey === PLATFORM_WINDOWS) &&
}
- {this.state.useAdbForward &&
+ {(this.state.useAdbForward || this.state.platformSelectionKey === PLATFORM_WINDOWS) &&
}
-
-
- {this.state.useAdbForward &&
- {devlist.length > 0 &&
-
Select one of the following devices to forward port.
-
{devlist}
-
}
- {devlist.length === 0 && Error: No device available. Connect at lease one Android device to this PC/mac or input the IP address of your mobile device.
}
- }
+
+
+
+
+
+ {this.state.useAdbForward &&
+ {devlist.length > 0 &&
+
Select one of the following devices to forward port.
+
{devlist}
+
}
+ {devlist.length === 0 &&
Error: No device available. Connect at lease one Android device to this PC/mac or input the IP address of your mobile device.
}
+
}
+
+
+
+
+ {!this.state.connectUnityWindowsAppUnityEditorMode &&
+
+ }
+
+
+
+ No need to configuration
+
+
+
+
diff --git a/lib/modules/viewer/backend/unity3d.jsx b/lib/modules/viewer/backend/unity3d.jsx
index 267038a..38e17ff 100644
--- a/lib/modules/viewer/backend/unity3d.jsx
+++ b/lib/modules/viewer/backend/unity3d.jsx
@@ -101,16 +101,27 @@ export class Unity3dInspectorView extends InspectorViewBase {
this.pocoProc.stdin.write('\n')
}
+ connectAirtestDevice(devUri) {
+ let code = `
+from airtest.core.api import connect_device
+connect_device('${devUri}')
+`
+ this.execPy(code)
+ }
+
refresh(width) {
- toastr["info"]('Please wait for the screen initializing.')
- let isWindowsMode = !this.props.useAdbForward && (this.props.ip === 'localhost' || this.props.ip.startsWith('127.0'))
+ let isUnityEditor = this.props.platform === 'windows' && this.props.options.isUnityEditor
+ // 只有windows版的非editor mode 才需要主动connect到device
+ if (this.props.platform === 'windows' && !this.props.options.isUnityEditor) {
+ this.connectAirtestDevice(`Windows:///?title_re=${this.props.options.titleRe}`)
+ }
let code = `
def get_hierarchy_and_screen():
# cache poco instance globally to speed up
poco = globals().get('poco')
if poco is None:
- poco = UnityPoco(("${this.props.ip}", ${this.props.port}), ${isWindowsMode ? 'True' : 'False'})
+ poco = UnityPoco(("${this.props.ip}", ${this.props.port}), ${isUnityEditor ? 'True' : 'False'}, connect_default_device=False)
globals()['poco'] = poco
try:
@@ -158,13 +169,13 @@ get_hierarchy_and_screen()
this.execPy(code)
}
getSDKVersion() {
- let isWindowsMode = !this.props.useAdbForward && (this.props.ip === 'localhost' || this.props.ip.startsWith('127.0'))
+ let isUnityEditor = this.props.platform === 'windows' && this.props.options.isUnityEditor
let code = `
def get_sdk_version():
# cache poco instance globally to speed up
poco = globals().get('poco')
if poco is None:
- poco = UnityPoco(("${this.props.ip}", ${this.props.port}), ${isWindowsMode ? 'True' : 'False'})
+ poco = UnityPoco(("${this.props.ip}", ${this.props.port}), ${isUnityEditor ? 'True' : 'False'}, connect_default_device=False)
globals()['poco'] = poco
try:
diff --git a/lib/modules/viewer/index.jsx b/lib/modules/viewer/index.jsx
index 3c1af80..52d8e16 100644
--- a/lib/modules/viewer/index.jsx
+++ b/lib/modules/viewer/index.jsx
@@ -53,6 +53,7 @@ class MainConnector extends React.Component {
{!this.state.inspectorViewInstance &&
Poco Hierarchy Viewer
+
version: 1.0.0
mode:
diff --git a/static/css/layout.css b/static/css/layout.css
index f605a3a..f99f4aa 100644
--- a/static/css/layout.css
+++ b/static/css/layout.css
@@ -910,3 +910,9 @@ h1, h2, h3, h4, h5, h6, p {
font-feature-settings: 'liga';
}
+.nav-tabs {
+ background-color: #444;
+}
+.nav-tabs > li.active {
+ background-color: #666;
+}