X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions live/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
-dontwarn okio.**

-keep class io.trtc.tuikit.atomicx.karaoke.** { *; }
-keep class com.trtc.uikit.gamekit.UnityHostBridge { *; }

# TRTC SDK Viesion >= 12.5.0
-dontwarn com.tencent.rtmp.video.BaseBridge$BaseBridgeCallback
Expand Down
1 change: 1 addition & 0 deletions live/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include ':app'
include ':debug'
include ':tuilivekit'
include ':tuigamekit'

include(":atomic")
project(':atomic').projectDir = new File(settingsDir, '../atomic_x')
1 change: 1 addition & 0 deletions live/tuigamekit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions live/tuigamekit/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id 'com.android.library'
}

android {
namespace 'com.trtc.uikit.gamekit'
compileSdk 34

defaultConfig {
minSdk 21

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}

dependencies {
implementation 'io.trtc.uikit:rtc-game-box:1.0.0'
api rootProject.getProperties().containsKey("roomEngineSdk") ? rootProject.ext.roomEngineSdk : "io.trtc.uikit:rtc_room_engine:3.1.0.824"
api rootProject.getProperties().containsKey("liteavSdk") ? rootProject.ext.liteavSdk : "com.tencent.liteav:LiteAVSDK_Professional:12.5.0.17567"
api rootProject.getProperties().containsKey("common") ? rootProject.ext.common : "io.trtc.uikit:common:3.1.0.946"
}
Empty file.
23 changes: 23 additions & 0 deletions live/tuigamekit/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep class com.trtc.uikit.gamekit.UnityHostBridge { *; }
4 changes: 4 additions & 0 deletions live/tuigamekit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.trtc.uikit.gamekit;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.tencent.cloud.tuikit.engine.common.TUICommonDefine;
import com.tencent.cloud.tuikit.engine.room.TUIRoomDefine;
import com.tencent.cloud.tuikit.engine.room.TUIRoomEngine;
import com.trtc.uikit.gamekit.common.GameKitLogger;
import com.trtc.uikit.gamekit.gameview.GameView;

import org.json.JSONObject;

public final class LiteGameEngine {
private static final GameKitLogger LOGGER = GameKitLogger.getGameKitLogger(LiteGameEngine.class.getName());
public static class GameID {
public static String NONE = "";
public static String GOBANG = "Gobang";
public static String FLYINGCHESS = "FlyingChess";
}

public static class ActionType {
public static String ACTION_GAME_START = "ACTION_GAME_START";
public static String ACTION_GAME_STOP = "ACTION_GAME_STOP";
public static String ACTION_USER_ENTER = "ACTION_USER_ENTER";
public static String ACTION_USER_EXIT = "ACTION_USER_EXIT";
}

public static final String customMessageBusinessId = "LiteavGameKit";

private String runningGameId = "";
private static volatile LiteGameEngine sInstance;
private LiteGameEngine() {
}

public static LiteGameEngine getInstance() {
if (sInstance == null) {
synchronized (LiteGameEngine.class) {
if (sInstance == null) {
sInstance = new LiteGameEngine();
}
}
}
return sInstance;
}

public static void destroyInstance() {
synchronized (LiteGameEngine.class) {
if (sInstance != null) {
sInstance = null;
}
}
}
public String getRunningGameId() {
return runningGameId;
}
public void startGame(String gameId, boolean isHost, String userId, String nickName, String avatarUrl) {
if (runningGameId.equals(gameId))
{
return;
}
runningGameId = gameId;
try {

JSONObject actionDataObj = new JSONObject();
actionDataObj.put("IsHost", isHost);
actionDataObj.put("PlayerId", userId);
actionDataObj.put("Nickname", nickName);
actionDataObj.put("AvatarUrl", avatarUrl);

JSONObject messageObj = new JSONObject();
messageObj.put("gameId", gameId);
messageObj.put("actionType", ActionType.ACTION_GAME_START);
messageObj.put("actionData", actionDataObj.toString());
if (gameId.equals(LiteGameEngine.GameID.GOBANG)) {
LiteGameUnityPlayer.UnitySendMessage("GameManager", "StartGobangGame", messageObj.toString());
} else if (gameId.equals(LiteGameEngine.GameID.FLYINGCHESS)) {
LiteGameUnityPlayer.UnitySendMessage("GameManager", "StartFlyingChessGame", messageObj.toString());
}

} catch (Exception e) {
LOGGER.warn( "StartGameInternal fail");
}
}

public void startLauncher() {
runningGameId = "";
LiteGameUnityPlayer.UnitySendMessage("GameManager", "StartLauncher", "");
}

public void sendMessageToUnity(String message) {
LiteGameUnityPlayer.UnitySendMessage("GameManager", "OnReceivedMessage", message);
}

public void broadcastGameQuitMessage()
{
try {
JSONObject message = new JSONObject();
message.put("gameId", runningGameId);
message.put("actionType", ActionType.ACTION_GAME_STOP);
message.put("actionData", "{}");
broadcastMessage(message.toString());
} catch (Exception e) {
LOGGER.warn( "Send game stop message fail");
}
}

public void broadcastMessage(String message) {
TUIRoomDefine.RoomCustomMessage customMessage = new TUIRoomDefine.RoomCustomMessage();
customMessage.businessId = LiteGameEngine.customMessageBusinessId;
customMessage.data = message;
TUIRoomEngine.sharedInstance().sendCustomMessage(customMessage, new TUIRoomDefine.SendCustomMessageCallback() {
@Override
public void onSuccess(TUIRoomDefine.RoomCustomMessage message) {
//Log.i(TAG, "SendMessage to room success");
}

@Override
public void onError(TUICommonDefine.Error error, String message) {
LOGGER.warn( "SendMessage to room error:" + error + " message:" + message);
}
});
}

public void onRemoteUserEnterRoom(String userId, String userName, String avatarUrl) {
try {
JSONObject actionDataObj = new JSONObject();
actionDataObj.put("PlayerId", userId);
actionDataObj.put("Nickname", userName);
actionDataObj.put("AvatarUrl", avatarUrl);

JSONObject outer = new JSONObject();
outer.put("gameId", runningGameId);
outer.put("actionType", ActionType.ACTION_USER_ENTER);
outer.put("actionData", actionDataObj.toString());
sendMessageToUnity(outer.toString());
} catch (Exception e) {
LOGGER.warn( "onRemoteUserEnterRoom message send fail");
}
}

public void onRemoteUserLeaveRoom(String userId, String userName, String avatarUrl) {
try {
JSONObject actionDataObj = new JSONObject();
actionDataObj.put("PlayerId", userId);
actionDataObj.put("Nickname", userName);
actionDataObj.put("AvatarUrl", avatarUrl);

// 外层对象,并把内层对象作为字符串放入 actionData
JSONObject outer = new JSONObject();
outer.put("gameId", runningGameId);
outer.put("actionType", ActionType.ACTION_USER_EXIT);
outer.put("actionData", actionDataObj.toString());
sendMessageToUnity(outer.toString());
} catch (Exception e) {
LOGGER.warn("onRemoteUserLeaveRoom message send fail");
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.trtc.uikit.gamekit;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import com.unity3d.player.IUnityPlayerLifecycleEvents;
import com.unity3d.player.UnityPlayer;

public class LiteGameUnityPlayer extends UnityPlayer {
private static LiteGameUnityPlayer sUnityPlayer;
private boolean isFirstFrameRendered = false;
private OnRenderFirstFrameListener onRenderFirstFrameListener;

public interface OnRenderFirstFrameListener {
void onFirstFrameRendered();
}
public LiteGameUnityPlayer(Context context) {
super(context);
}

public LiteGameUnityPlayer(Context context, IUnityPlayerLifecycleEvents iUnityPlayerLifecycleEvents) {
super(context, iUnityPlayerLifecycleEvents);
}

@Override
protected void kill() {
}

private void setFirstFrameRendered() {
isFirstFrameRendered = true;
if (onRenderFirstFrameListener != null) {
onRenderFirstFrameListener.onFirstFrameRendered();
}
}

public static synchronized LiteGameUnityPlayer getUnityPlayer(Context ctx) {
if (sUnityPlayer == null) {
sUnityPlayer = new LiteGameUnityPlayer(ctx.getApplicationContext());
}
return sUnityPlayer;
}

public static void detachFromParent() {
if (sUnityPlayer != null) {
View v = sUnityPlayer.getView();
if (v != null && v.getParent() != null) {
((ViewGroup) v.getParent()).removeView(v);
}
}
}

public static void onFirstFrameRendered() {
if (sUnityPlayer != null) {
sUnityPlayer.setFirstFrameRendered();
}
}
public static void UnitySendMessage(String gameOjbName, String methodName, String data) {
UnityPlayer.UnitySendMessage(gameOjbName, methodName, data);
}

public void setOnRenderFirstFrameListener(LiteGameUnityPlayer.OnRenderFirstFrameListener listener) {
onRenderFirstFrameListener = listener;
if (isFirstFrameRendered && onRenderFirstFrameListener != null) {
onRenderFirstFrameListener.onFirstFrameRendered();
}
}
}
Loading
X Tutup