Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for onDettached onAttach UnityWidget #729

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f599efa
refactor: refactored unity controller to a global singleton that live…
juicycleff Dec 16, 2022
c6309ee
refactor: refactored unity controller to a global singleton that live…
juicycleff Dec 16, 2022
2bbca9e
refactor: refactored unity controller to a global singleton that live…
juicycleff Dec 20, 2022
d5c02e7
chore: improved api
juicycleff Dec 21, 2022
89640b6
Make ReadMe examples null-safe & fix errors.
timbotimbo Dec 15, 2022
c6babc5
Make example project null safe.
timbotimbo Dec 15, 2022
0f2c80e
Fix most linter warnings.
timbotimbo Dec 24, 2022
f02d47c
fix: fixed type crash
juicycleff Dec 29, 2022
a3dfd50
feat: added test mode api
juicycleff Dec 29, 2022
88747a1
fix(ios): fixed unity focus pause on ios
juicycleff Dec 30, 2022
c72e363
fix(ios): fixed unity focus pause on ios
juicycleff Dec 30, 2022
b233e52
Merge pull request #737 from timbotimbo/global_controller_nullsafe
juicycleff Dec 30, 2022
8fcf846
Fix dispose not called
Ortes Feb 16, 2023
057632a
Add support for onDettached onAttach UnityWidget
Ortes Dec 13, 2022
a642c09
Fix call order created init + detached on dispose
Ortes Dec 19, 2022
67eab4d
Fix compile error after rebase
Ortes Jan 9, 2023
2b288d5
Fix controller singleton
Ortes Jan 10, 2023
b6b1a30
Fix order switch case enum
Ortes Feb 9, 2023
0f1f36f
Format
Ortes Feb 9, 2023
98fe219
Remove non overriding member
Ortes Feb 9, 2023
0ddbba2
Add support on attached on detached iOS
Ortes Feb 16, 2023
8e86d37
Fix key not used in UnityWidget
Ortes Apr 29, 2023
b8eb7ff
Merge branch 'master' into support-for-on-detached-on-attached
timbotimbo May 21, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2022.3.0-alpha1

* Added support for global flutter unity controller that outlives the UnityWidget

## 2022.2.0

* Enable AndroidView due to native view improvement in flutter 3.3.0
Expand Down
3 changes: 3 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ dependencies {

compileOnly rootProject.findProject(":flutter_plugin_android_lifecycle")

implementation "io.reactivex.rxjava3:rxjava:3.1.4"
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

// FOR DEV ONLY
// implementation(name: 'flutter', ext:'jar')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.xraph.plugin.flutter_unity_widget

import io.flutter.plugin.common.EventChannel
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.subjects.PublishSubject
import org.json.JSONObject

class DataStreamEventNotifier {
companion object {
val notifier: PublishSubject<DataStreamEvent> = PublishSubject.create()
}
}

data class DataStreamEvent(val eventType: String, val data: Any) {
fun toMap(): Map<String, Any> {
return mapOf("eventType" to eventType, "data" to data)
}

fun toJsonString(): String {
return JSONObject(toMap()).toString()
}
}

enum class DataStreamEventTypes {
OnUnityViewCreated,
OnUnityPlayerReInitialize,
OnViewReattached,
OnUnityPlayerCreated,
OnUnityPlayerUnloaded,
OnUnityPlayerQuited,
OnUnitySceneLoaded,
OnUnityMessage,
OnViewAttached,
OnViewDetached,
}

class DataStreamHandler: EventChannel.StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink) {
DataStreamEventNotifier.notifier.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread()).subscribe {
events.success(it.toMap())
}
}

override fun onCancel(arguments: Any?) {
DataStreamEventNotifier.notifier.unsubscribeOn(AndroidSchedulers.mainThread())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ class FlutterUnityWidgetBuilder : FlutterUnityWidgetOptionsSink {
fun build(
id: Int,
context: Context?,
binaryMessenger: BinaryMessenger,
lifecycle: LifecycleProvider
): FlutterUnityWidgetController {
UnityPlayerUtils.options = options
val controller = FlutterUnityWidgetController(
id,
context,
binaryMessenger,
lifecycle
)
controller.bootstrap()
Expand Down
Loading