diff --git a/GodotVisionExample.xcodeproj/project.pbxproj b/GodotVisionExample.xcodeproj/project.pbxproj index a26f9c5..886a6dd 100644 --- a/GodotVisionExample.xcodeproj/project.pbxproj +++ b/GodotVisionExample.xcodeproj/project.pbxproj @@ -343,7 +343,7 @@ ); LIBRARY_SEARCH_PATHS = "$(inherited)"; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.example.GodotVision; + PRODUCT_BUNDLE_IDENTIFIER = vision.godot.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "xros xrsimulator"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -377,7 +377,7 @@ ); LIBRARY_SEARCH_PATHS = "$(inherited)"; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.example.GodotVision; + PRODUCT_BUNDLE_IDENTIFIER = vision.godot.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "xros xrsimulator"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -424,7 +424,7 @@ repositoryURL = "https://github.com/kevinw/GodotVision.git"; requirement = { kind = revision; - revision = 118e06ea721f457d6582327abd98f750c6435dc1; + revision = 5dc0e9f5c2cc1a660dd7e21f6f55a382dfc1fe62; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/GodotVisionExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/GodotVisionExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1ced1f1..422b732 100644 --- a/GodotVisionExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/GodotVisionExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,7 +6,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/kevinw/GodotVision.git", "state" : { - "revision" : "118e06ea721f457d6582327abd98f750c6435dc1" + "revision" : "5dc0e9f5c2cc1a660dd7e21f6f55a382dfc1fe62" } }, { diff --git a/Godot_Project/addons/godot_vision/GodotVision_autoload.gd b/Godot_Project/addons/godot_vision/GodotVision_autoload.gd index 5d13b7c..f2c7da6 100644 --- a/Godot_Project/addons/godot_vision/GodotVision_autoload.gd +++ b/Godot_Project/addons/godot_vision/GodotVision_autoload.gd @@ -1,8 +1,7 @@ extends Node class_name GodotVision_autoload - - +@onready var share_play: SharePlay = $SharePlay var scene_tree: SceneTree func running_on_vision(): @@ -11,14 +10,14 @@ func running_on_vision(): func _enter_tree(): if !running_on_vision(): scene_tree = get_tree() - scene_tree.node_added.connect(on_node_added) + scene_tree.node_added.connect(_on_node_added) func _exit_tree(): if !running_on_vision(): - scene_tree.node_added.disconnect(on_node_added) + scene_tree.node_added.disconnect(_on_node_added) scene_tree = null -func on_node_added(node: Node): +func _on_node_added(node: Node): if node.has_signal("spatial_drag"): var col := node as CollisionObject3D if col: diff --git a/Godot_Project/addons/godot_vision/GodotVision_autoload.tscn b/Godot_Project/addons/godot_vision/GodotVision_autoload.tscn index ecc155c..77ba168 100644 --- a/Godot_Project/addons/godot_vision/GodotVision_autoload.tscn +++ b/Godot_Project/addons/godot_vision/GodotVision_autoload.tscn @@ -1,6 +1,10 @@ -[gd_scene load_steps=2 format=3 uid="uid://c5vucxnx28wt3"] +[gd_scene load_steps=3 format=3 uid="uid://c5vucxnx28wt3"] [ext_resource type="Script" path="res://addons/godot_vision/GodotVision_autoload.gd" id="1_w221q"] +[ext_resource type="Script" path="res://addons/godot_vision/SharePlay.gd" id="2_61mna"] [node name="GodotVision_autoload" type="Node"] script = ExtResource("1_w221q") + +[node name="SharePlay" type="Node" parent="."] +script = ExtResource("2_61mna") diff --git a/Godot_Project/addons/godot_vision/SharePlay.gd b/Godot_Project/addons/godot_vision/SharePlay.gd new file mode 100644 index 0000000..268fcc7 --- /dev/null +++ b/Godot_Project/addons/godot_vision/SharePlay.gd @@ -0,0 +1,19 @@ +extends Node +class_name SharePlay + +# called by GodotVision +signal peer_connected(peer_id: String, player_info: Dictionary) +signal peer_disconnected(peer_id) +signal message_received(from_peer: String, message: Dictionary) + +# emitted by us to GodotVision +signal join_activity() + +var automatically_share_input: bool = false + + +func broadcast_message(message: Dictionary): + pass + +func auto_join_activity(): + join_activity.emit() diff --git a/Godot_Project/addons/godot_vision/auto_join_shareplay.gd b/Godot_Project/addons/godot_vision/auto_join_shareplay.gd new file mode 100644 index 0000000..4aeca06 --- /dev/null +++ b/Godot_Project/addons/godot_vision/auto_join_shareplay.gd @@ -0,0 +1,19 @@ +extends Node3D +class_name AutoJoinSharePlay + +@export var auto_join = true +@export var auto_share_input = true + +func _ready(): + if auto_join: + await get_tree().create_timer(0.5).timeout + call_deferred("join") + +func join(): + var share_play := GodotVision.share_play + if not share_play: + return + + share_play.automatically_share_input = auto_share_input + share_play.auto_join_activity() + diff --git a/Godot_Project/examples/multiplayer_example/multiplayer_example.tscn b/Godot_Project/examples/multiplayer_example/multiplayer_example.tscn new file mode 100644 index 0000000..985f5e1 --- /dev/null +++ b/Godot_Project/examples/multiplayer_example/multiplayer_example.tscn @@ -0,0 +1,115 @@ +[gd_scene load_steps=10 format=3 uid="uid://cbbu56gcmmc6n"] + +[ext_resource type="Script" path="res://addons/godot_vision/auto_join_shareplay.gd" id="1_4pdjb"] +[ext_resource type="PackedScene" uid="uid://biunegs8tkvn0" path="res://addons/godot_vision/VisionVolumeCamera.tscn" id="2_xe0xt"] +[ext_resource type="Script" path="res://examples/hello/scripts/draggable.gd" id="3_1q28r"] +[ext_resource type="Script" path="res://examples/hello/change_text_on_drag.gd" id="4_knt32"] + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_wwgva"] +height = 0.455507 +radius = 1.0 + +[sub_resource type="BoxShape3D" id="BoxShape3D_r2cps"] +size = Vector3(1.5, 1, 1) + +[sub_resource type="BoxMesh" id="BoxMesh_2jjjg"] +size = Vector3(1.5, 1, 1) + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0aq11"] +albedo_color = Color(0.803922, 0, 0.803922, 1) + +[sub_resource type="TextMesh" id="TextMesh_6pa4w"] +material = SubResource("StandardMaterial3D_0aq11") +text = "Drag Me" + +[node name="MultiplayerExample" type="Node3D"] + +[node name="AutoJoinSharePlay" type="Node3D" parent="."] +visible = false +script = ExtResource("1_4pdjb") +auto_join = null +auto_share_input = null +activity_name = "vision.godot.multiplayer-example" + +[node name="VisionVolumeCamera" parent="." instance=ExtResource("2_xe0xt")] + +[node name="AnimatableBody3D" type="AnimatableBody3D" parent="."] +transform = Transform3D(3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0) +input_capture_on_drag = true +script = ExtResource("3_1q28r") +metadata/hover_effect = true + +[node name="CollisionShape3D" type="CollisionShape3D" parent="AnimatableBody3D"] +shape = SubResource("CylinderShape3D_wwgva") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(0.345503, -0.268328, -0.899237, 0.613376, 0.789791, -2.58101e-08, 0.71021, -0.55157, 0.437461, 0, 0, 0) + +[node name="Drag Me Button" type="AnimatableBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.32111, -1.90392, -0.700861) +collision_mask = 0 +script = ExtResource("3_1q28r") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Drag Me Button"] +shape = SubResource("BoxShape3D_r2cps") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Drag Me Button"] +mesh = SubResource("BoxMesh_2jjjg") + +[node name="Label" type="MeshInstance3D" parent="Drag Me Button"] +transform = Transform3D(1.97583, 0, 0, 0, 1.97583, 0, 0, 0, 1.97583, 0, 0, 0.603814) +mesh = SubResource("TextMesh_6pa4w") +script = ExtResource("4_knt32") + +[node name="Drag Me Button2" type="AnimatableBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.18767, -1.90392, -0.700861) +collision_mask = 0 +script = ExtResource("3_1q28r") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Drag Me Button2"] +shape = SubResource("BoxShape3D_r2cps") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Drag Me Button2"] +mesh = SubResource("BoxMesh_2jjjg") + +[node name="Label" type="MeshInstance3D" parent="Drag Me Button2"] +transform = Transform3D(1.97583, 0, 0, 0, 1.97583, 0, 0, 0, 1.97583, 0, 0, 0.603814) +mesh = SubResource("TextMesh_6pa4w") +script = ExtResource("4_knt32") + +[node name="Drag Me Button3" type="AnimatableBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.86196, -1.90392, -0.700861) +collision_mask = 0 +script = ExtResource("3_1q28r") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Drag Me Button3"] +shape = SubResource("BoxShape3D_r2cps") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Drag Me Button3"] +mesh = SubResource("BoxMesh_2jjjg") + +[node name="Label" type="MeshInstance3D" parent="Drag Me Button3"] +transform = Transform3D(1.97583, 0, 0, 0, 1.97583, 0, 0, 0, 1.97583, 0, 0, 0.603814) +mesh = SubResource("TextMesh_6pa4w") +script = ExtResource("4_knt32") + +[node name="Drag Me Button4" type="AnimatableBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.89629, -1.90392, -0.700861) +collision_mask = 0 +script = ExtResource("3_1q28r") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Drag Me Button4"] +shape = SubResource("BoxShape3D_r2cps") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Drag Me Button4"] +mesh = SubResource("BoxMesh_2jjjg") + +[node name="Label" type="MeshInstance3D" parent="Drag Me Button4"] +transform = Transform3D(1.97583, 0, 0, 0, 1.97583, 0, 0, 0, 1.97583, 0, 0, 0.603814) +mesh = SubResource("TextMesh_6pa4w") +script = ExtResource("4_knt32") + +[connection signal="spatial_drag" from="Drag Me Button" to="Drag Me Button/Label" method="_on_drag_me_button_spatial_drag"] +[connection signal="spatial_drag" from="Drag Me Button2" to="Drag Me Button2/Label" method="_on_drag_me_button_spatial_drag"] +[connection signal="spatial_drag" from="Drag Me Button3" to="Drag Me Button3/Label" method="_on_drag_me_button_spatial_drag"] +[connection signal="spatial_drag" from="Drag Me Button4" to="Drag Me Button4/Label" method="_on_drag_me_button_spatial_drag"]