Skip to content

Commit

Permalink
Merge pull request #20 from teogor/feature/unity-modularization
Browse files Browse the repository at this point in the history
Modularize Unity Support for Version-Specific Functionality
  • Loading branch information
teogor authored Feb 24, 2024
2 parents eb99210 + 635fea6 commit b5d3fc8
Show file tree
Hide file tree
Showing 58 changed files with 857 additions and 137 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ dependencies {

implementation(projects.drifterCommon)
implementation(projects.drifterCompose)
implementation(projects.drifterCore)
implementation(projects.unity.v202237f1)
implementation(projects.drifterIntegration)
implementation(projects.drifterWallpaper)

implementation(platform(libs.ceres.bom))
implementation(libs.ceres.core.register)

implementation(libs.gson)
implementation(libs.core.ktx)
implementation(libs.lifecycle.runtime.ktx)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
android:required="false" />

<application
android:name=".Application"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/kotlin/dev/teogor/drifter/demo/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 teogor (Teodor Grigor)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.teogor.drifter.demo

import android.app.Application
import dev.teogor.ceres.core.register.RegistryStartup
import dev.teogor.drifter.unity.withUnity202237f1Factory

/**
* Android Application class for Ceres application.
*
* This class extends the Android [Application] class.
*/
class Application : Application() {

override fun onCreate() {
super.onCreate()

RegistryStartup.provides(withUnity202237f1Factory())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import dev.teogor.drifter.compose.OnLifecycleEvent
import dev.teogor.ceres.core.common.utils.OnLifecycleEvent
import dev.teogor.drifter.compose.UvpComposable
import dev.teogor.drifter.demo.ui.theme.UnityViewTheme
import dev.teogor.drifter.wallpaper.LiveWallpaperUtility
Expand Down
2 changes: 1 addition & 1 deletion drifter-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
}

dependencies {
implementation(projects.drifterCore)
implementation(projects.unity.common)
implementation(projects.drifterIntegration)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package dev.teogor.drifter.common

import com.unity3d.player.UnityPlayer
import dev.teogor.drifter.unity.common.UnityEngine
import org.json.JSONObject

/**
Expand All @@ -37,6 +37,6 @@ open class UnityMessageSender(private val receiver: String) {
* @param data The JSON data to send as arguments to the method.
*/
fun sendMessage(methodName: String, data: JSONObject) {
UnityPlayer.UnitySendMessage(receiver, methodName, data.toString())
UnityEngine.sendMessage(receiver, methodName, data.toString())
}
}
5 changes: 4 additions & 1 deletion drifter-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ android {
}

dependencies {
implementation(projects.drifterCore)
implementation(platform(libs.ceres.bom))
api(libs.ceres.core.common)

implementation(projects.unity.common)
implementation(projects.drifterIntegration)
implementation(projects.drifterWallpaper)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import dev.teogor.ceres.core.common.utils.OnLifecycleEvent
import dev.teogor.drifter.compose.components.UnityPlayerView

@Composable
Expand Down
4 changes: 2 additions & 2 deletions drifter-integration/api/drifter-integration.api
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public final class dev/teogor/drifter/integration/BuildConfig {
public fun <init> ()V
}

public abstract class dev/teogor/drifter/integration/activities/OverrideUnityActivity : com/unity3d/player/UnityPlayerActivity {
public abstract class dev/teogor/drifter/integration/activities/OverrideUnityActivity : dev/teogor/drifter/unity/common/BaseUnityPlayerActivity {
public static final field Companion Ldev/teogor/drifter/integration/activities/OverrideUnityActivity$Companion;
public fun <init> ()V
protected fun onCreate (Landroid/os/Bundle;)V
Expand Down Expand Up @@ -219,7 +219,7 @@ public final class dev/teogor/drifter/integration/player/UnityPlayerWrapper {
public static final field Companion Ldev/teogor/drifter/integration/player/UnityPlayerWrapper$Companion;
public fun <init> (Landroid/content/ContextWrapper;)V
public final fun getApplicationContext ()Landroid/content/Context;
public final fun getUnityPlayer ()Lcom/unity3d/player/UnityPlayer;
public final fun getUnityPlayer ()Ldev/teogor/drifter/unity/common/IUnityPlayer;
public final fun handleSurfaceDestroyed (Landroid/view/SurfaceHolder;)V
public final fun injectConfigurationChange (Landroid/content/res/Configuration;)V
public final fun injectInputEvent (Landroid/view/InputEvent;)Z
Expand Down
2 changes: 1 addition & 1 deletion drifter-integration/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ android {
}

dependencies {
implementation(projects.drifterCore)
api(projects.unity.common)

implementation(libs.androidx.startup.runtime)
implementation(libs.gson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package dev.teogor.drifter.integration.activities

import android.os.Bundle
import com.unity3d.player.UnityPlayerActivity
import dev.teogor.drifter.unity.common.BaseUnityPlayerActivity

abstract class OverrideUnityActivity : UnityPlayerActivity() {
abstract class OverrideUnityActivity : BaseUnityPlayerActivity() {
protected abstract fun showMainActivity(setToColor: String?)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package dev.teogor.drifter.integration.core

import com.unity3d.player.UnityPlayer
import dev.teogor.drifter.unity.common.LocalUnityEngine
import org.json.JSONObject

@Deprecated(
Expand All @@ -31,6 +31,6 @@ open class UnityControllerBase(
) {

fun invokeAction(methodName: String, data: JSONObject) {
UnityPlayer.UnitySendMessage(receiver, methodName, data.toString())
LocalUnityEngine.current.sendMessage(receiver, methodName, data.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package dev.teogor.drifter.integration.core

import com.unity3d.player.UnityPlayer
import dev.teogor.drifter.integration.utilities.asString
import dev.teogor.drifter.unity.common.LocalUnityEngine

class UnityDispatcher(
val gameObject: String,
Expand All @@ -26,7 +26,7 @@ class UnityDispatcher(
) {

init {
UnityPlayer.UnitySendMessage(
LocalUnityEngine.current.sendMessage(
gameObject,
functionName,
functionParameter.asString,
Expand Down
Loading

0 comments on commit b5d3fc8

Please sign in to comment.