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

refactor: refactored unity controller to a global singleton #733

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 28 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
name: genopets
name: main

permissions:
id-token: write # Enable OIDC
pull-requests: write
contents: write
packages: write
issues: write

on: [pull_request, push]

jobs:
build:
lint-test:
runs-on: ubuntu-latest

steps:
Expand All @@ -28,3 +35,22 @@ jobs:

- name: Run tests
run: flutter test --no-pub --coverage --test-randomize-ordering-seed random

prerelease:
runs-on: ubuntu-latest
needs:
- lint-test
if: github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v2

- name: Run Release
uses: google-github-actions/release-please-action@v3
with:
release-type: dart
package-name: flutter-unity-widget
default-branch: main
signoff: "Rex Raphael <rex.raphael@outlook.com>"
token: ${{ secrets.GIT_TOKEN }}

17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ build/
android/UnityLibrary/

#example/
example/unity/DemoApp/Builds/
example/unity/DemoApp/Library/
example/unity/DemoApp/Logs/
example/unity/DemoApp/Temp/
**/Builds/**
examples/unity/*/Builds/
examples/unity/*/Library/
examples/unity/*/Logs/
examples/unity/*/Temp/

# Android related
**/android/**/gradle-wrapper.jar
Expand Down Expand Up @@ -83,7 +84,7 @@ example/unity/DemoApp/Temp/
!**/ios/**/default.perspectivev3
!/unitypackages/flutter_tools/test/data/dart_dependencies_test/**/.packages

example/unity/DemoApp/test
example/ios/UnityLibrary
example/android/unityLibrary
example/web/unityLibrary
examples/*/unity/DemoApp/test
examples/*/ios/UnityLibrary
examples/*/android/unityLibrary
examples/*/web/unityLibrary
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,46 @@
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,
}

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
Loading