-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from teogor/feature/unity-controller
Code Refactoring and Documentation Updates
- Loading branch information
Showing
15 changed files
with
290 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
app/src/main/kotlin/dev/teogor/drifter/demo/unity/AndroidHandler.kt
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
app/src/main/kotlin/dev/teogor/drifter/demo/unity/UnityController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.unity | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import dev.teogor.drifter.demo.unity.models.CycleOption | ||
import dev.teogor.drifter.demo.unity.models.UnityActionParams | ||
import dev.teogor.drifter.demo.unity.models.UnityActions | ||
import dev.teogor.drifter.demo.unity.models.toJsonObject | ||
import dev.teogor.drifter.integration.core.UnityControllerBase | ||
|
||
class UnityController : UnityControllerBase( | ||
receiver = "BridgeController", | ||
) { | ||
|
||
fun setEditorMode(isEditorMode: Boolean) { | ||
val params = UnityActionParams(isEditorMode = isEditorMode) | ||
invokeAction( | ||
UnityActions.SetEditorMode, | ||
params.toJsonObject(), | ||
) | ||
} | ||
|
||
fun setEditorColor(waterColor: Color, animated: Boolean = true) { | ||
val params = UnityActionParams(waterColor = waterColor, animated = animated) | ||
invokeAction( | ||
UnityActions.SetWaterColor, | ||
params.toJsonObject(), | ||
) | ||
} | ||
|
||
fun setEditorCycleOption(cycleOption: CycleOption) { | ||
val params = UnityActionParams(cycleOption = cycleOption) | ||
invokeAction( | ||
UnityActions.SetCycleOption, | ||
params.toJsonObject(), | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/kotlin/dev/teogor/drifter/demo/unity/models/CycleOption.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.teogor.drifter.demo.unity.models | ||
|
||
enum class CycleOption { | ||
Day, | ||
Night, | ||
Auto; | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/kotlin/dev/teogor/drifter/demo/unity/models/StorageKeys.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.teogor.drifter.demo.unity.models | ||
|
||
object StorageKeys { | ||
const val WaterColor = "storage_water_color" | ||
const val CycleOption = "storage_cycle_option" | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/kotlin/dev/teogor/drifter/demo/unity/models/UnityActionParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.teogor.drifter.demo.unity.models | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.toArgb | ||
import org.json.JSONObject | ||
|
||
data class UnityActionParams( | ||
val isEditorMode: Boolean? = null, | ||
val waterColor: Color? = null, | ||
val animated: Boolean? = null, | ||
val cycleOption: CycleOption? = null | ||
) | ||
|
||
fun UnityActionParams.toJsonObject(): JSONObject { | ||
val json = JSONObject() | ||
isEditorMode?.let { json.put("isEditorMode", it) } | ||
waterColor?.let { json.put("waterColor", it.toArgb()) } | ||
animated?.let { json.put("animated", it) } | ||
cycleOption?.let { json.put("cycleOption", it) } | ||
return json | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/kotlin/dev/teogor/drifter/demo/unity/models/UnityActions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.teogor.drifter.demo.unity.models | ||
|
||
object UnityActions { | ||
const val SetEditorMode = "SetEditorMode" | ||
const val SetWaterColor = "SetWaterColor" | ||
const val SetCycleOption = "SetCycleOption" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.