Skip to content

Commit

Permalink
multiplayer test scene
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinw committed Apr 25, 2024
1 parent 2f4f15e commit 37de939
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 10 deletions.
6 changes: 3 additions & 3 deletions GodotVisionExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -424,7 +424,7 @@
repositoryURL = "https://github.com/kevinw/GodotVision.git";
requirement = {
kind = revision;
revision = 118e06ea721f457d6582327abd98f750c6435dc1;
revision = 5dc0e9f5c2cc1a660dd7e21f6f55a382dfc1fe62;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/kevinw/GodotVision.git",
"state" : {
"revision" : "118e06ea721f457d6582327abd98f750c6435dc1"
"revision" : "5dc0e9f5c2cc1a660dd7e21f6f55a382dfc1fe62"
}
},
{
Expand Down
9 changes: 4 additions & 5 deletions Godot_Project/addons/godot_vision/GodotVision_autoload.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extends Node
class_name GodotVision_autoload



@onready var share_play: SharePlay = $SharePlay
var scene_tree: SceneTree

func running_on_vision():
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion Godot_Project/addons/godot_vision/GodotVision_autoload.tscn
Original file line number Diff line number Diff line change
@@ -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")
19 changes: 19 additions & 0 deletions Godot_Project/addons/godot_vision/SharePlay.gd
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions Godot_Project/addons/godot_vision/auto_join_shareplay.gd
Original file line number Diff line number Diff line change
@@ -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()

115 changes: 115 additions & 0 deletions Godot_Project/examples/multiplayer_example/multiplayer_example.tscn
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 37de939

Please sign in to comment.