Skip to content

Commit 4e52c90

Browse files
author
jeffgaogao
committed
docs(TcgSdk): update demo
1 parent ddd35ff commit 4e52c90

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Demo/TCRDemo/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ target 'TCRDemo' do
55
use_frameworks!
66
pod 'TCRSDK', :git => "https://github.com/tencentyun/cloudgame-ios-sdk.git"
77
pod 'TCRPROXYSDK', :git => 'https://github.com/tencentyun/cloudgame-ios-sdk.git', :tag => 'TCRPROXYSDK/1.0.0'
8+
pod 'TCRVKey', :git => "https://github.com/tencentyun/cloudgame-ios-sdk.git"
89
end

Demo/TCRDemo/TCGDemo/TCGDemoGamePlayVC.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import <AVFoundation/AVFoundation.h>
1616
#import "AudioQueuePlay.h"
1717
#import "TCGDemoAudioCapturor.h"
18+
#import <TCRVkey/TCRVKeyGamepad.h>
1819
#import <CoreMotion/CoreMotion.h>
1920
#import "video_capture/TCGCameraVideoCapturer.h"
2021
#import <TCRPROXYSDK/Proxy.h>
@@ -50,6 +51,7 @@ @interface TCGDemoGamePlayVC () <TcrSessionObserver, TCGDemoTextFieldDelegate, C
5051
@property (nonatomic, strong) PcTouchView *pcTouchView;
5152
@property (nonatomic, strong) MobileTouchView *mobileTouchView;
5253
@property (nonatomic, assign) BOOL isFirstRender;
54+
@property (nonatomic, strong) TCRVKeyGamepad *gamepad;
5355
@property (nonatomic, assign) BOOL isMobile;
5456
@property (strong, nonatomic) CMMotionManager *motionManager;
5557
@property (nonatomic, strong) TCGCameraVideoCapturer *videoCapturer;
@@ -152,6 +154,7 @@ - (void)viewDidLoad {
152154
[self.renderView addSubview:self.mobileTouchView];
153155
[TcrSdkInstance setLogger:self withMinLevel:TCRLogLevelInfo];
154156
[self.session setRenderView:_renderView];
157+
[self.renderView addSubview:self.gamepad];
155158
[self.renderView setTcrRenderViewObserver:self];
156159
// [self.session setVideoSink:self];
157160
// self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
@@ -251,6 +254,11 @@ - (void)initControlViews {
251254
[[MobileTouchView alloc] initWithFrame:CGRectMake(0, 0, self.videoRenderFrame.size.width, self.videoRenderFrame.size.height)
252255
session:self.session];
253256
self.mobileTouchView.hidden = NO;
257+
258+
// 虚拟按键视图加载
259+
self.gamepad = [[TCRVKeyGamepad alloc] initWithFrame:self.view.frame session:self.session];
260+
[self.gamepad showKeyGamepad:[self readJsonFromFile:@"tcg_default_ps4"]];
261+
self.gamepad.hidden = YES;
254262
}
255263

256264
- (void)initSettingView {
@@ -372,6 +380,7 @@ - (void)keyboardWillHide:(NSNotification *)notificationP {
372380
}
373381

374382
#pragma mark--- TCGDemoSettingViewDelegate ---
383+
375384
- (void)onStartProxy{
376385
[[Proxy sharedInstance] startProxy];
377386
NSLog(@"onStartProxy");
@@ -513,6 +522,16 @@ - (void)onEnableLocalAudio:(BOOL)enable {
513522
[self.session setEnableLocalAudio:enable];
514523
}
515524

525+
- (void)openGamepad:(BOOL)isOpen {
526+
if (isOpen) {
527+
[[self.session getGamepad] connectGamepad];
528+
self.gamepad.hidden = NO;
529+
} else {
530+
[[self.session getGamepad] disconnectGamepad];
531+
self.gamepad.hidden = YES;
532+
}
533+
}
534+
516535
- (void)onEnableLocalVideo:(BOOL)enable {
517536
if (_enableSendCustomVideo) {
518537
if (enable) {

Demo/TCRDemo/TCGDemo/TCGDemoSettingView.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ @interface TCGDemoSettingView ()
3434
@property (nonatomic, strong) UIButton *enableLocalVideoBtn;
3535
@property (nonatomic, strong) UIButton *switchCamera;
3636
@property (nonatomic, strong) UIButton *patseTextBtn;
37+
@property (nonatomic, strong) UIButton *toggleGamepadBtn;
3738
@property (nonatomic, strong) UIButton *changeResBtn;
3839
@property (nonatomic, strong) UIButton *createDCBtn;
3940
@property (nonatomic, strong) UIButton *sendDCDataBtn;
@@ -133,13 +134,15 @@ - (void)initSubViews {
133134
self.startProxyBtn = [self createBtnFrame:CGRectMake(left + 10, 380, 70, 25) title:@"开始代理"];
134135
self.stopProxyBtn = [self createBtnFrame:CGRectMake(left + 90, 380, 70, 25) title:@"停止代理"];
135136

137+
136138
self.capsLockBtn = [self createBtnFrame:CGRectMake(left + 90, 220, 70, 25) title:@"查询大写"];
137139
self.touchViewBtn = [self createBtnFrame:CGRectMake(left + 90, 260, 70, 25) title:@"禁用触屏"];
138140
self.changeResBtn = [self createBtnFrame:CGRectMake(left + 90, 300, 70, 25) title:@"改变分辨率"];
139141

140142
self.enableLocalVideoBtn = [self createBtnFrame:CGRectMake(left + 170, 220, 70, 25) title:@"开摄像头"];
141143
self.sensorBtn = [self createBtnFrame:CGRectMake(left + 170, 260, 70, 25) title:@"开传感器"];
142144
self.createDCBtn = [self createBtnFrame:CGRectMake(left + 170, 300, 70, 25) title:@"创建数据通道"];
145+
self.toggleGamepadBtn = [self createBtnFrame:CGRectMake(left + 250, 220, 70, 25) title:@"开启手柄"];
143146

144147
self.restartBtn = [self createBtnFrame:CGRectMake(selfWidth - 80, 80, 70, 25) title:@"重启游戏"];
145148
self.pauseBtn = [self createBtnFrame:CGRectMake(selfWidth - 80, 120, 70, 25) title:@"挂起游戏"];
@@ -177,6 +180,7 @@ - (void)initSubViews {
177180
[self addSubview:self.bitrateBtn];
178181
[self addSubview:self.enableLocalAudioBtn];
179182
[self addSubview:self.enableLocalVideoBtn];
183+
[self addSubview:self.toggleGamepadBtn];
180184
[self addSubview:self.switchCamera];
181185
[self addSubview:self.changeResBtn];
182186
[self addSubview:self.patseTextBtn];
@@ -336,6 +340,15 @@ - (void)controlBtnClick:(id)sender {
336340
[self.delegate onStartProxy];
337341
} else if (sender == self.stopProxyBtn) {
338342
[self.delegate onStopProxy];
343+
} else if (sender == self.toggleGamepadBtn) {
344+
NSString *titleText = @"关闭手柄";
345+
BOOL enable = YES;
346+
if ([self.toggleGamepadBtn.titleLabel.text isEqualToString:titleText]) {
347+
titleText = @"开启手柄";
348+
enable = NO;
349+
}
350+
[self.toggleGamepadBtn setTitle:titleText forState:UIControlStateNormal];
351+
[self.delegate openGamepad:enable];
339352
}
340353
}
341354

0 commit comments

Comments
 (0)