You could create a new kind of shared object (with a new prefab): "CubeWithHandles"
Create a main geometry, a cube for example
Add a "PhotonView" and a "PhotonTransformView" to this object
Add 6 anchors as smaller cubes (1 in the center of each face of the cube) children of the main cube
They will be static anchors for the handles, their isobarycenter must be the centre of the main object
They must neither have a rigid body or a collider
Create a new "Handle" prefab, that will beintanciated 6 times and associated to the 6 anchors
It must be just a litlle bit bigger than its respective anchor
Its RigidBody isKinematic should be set to true to avoid physical interactions
Add a "PhotonView" and a "PhotonTransformView" to this Handle
Add a "XR Grab Interactable" component to this Handle
Associate the "Grabable.cs" script to each of this Handle
And do all what you have done previously for the grabable objects about events management...
Instanciate and add 6 handles as cubes children of the anchors
Create a new script "InteractiveCubeWithHandles.cs" that extends "MonoBehaviourPun"
Declare 6 GameObject public fields!
public GameObject topHandle ;
public GameObject bottomHandle ;
public GameObject leftHandle ;
public GameObject rightHandle ;
public GameObject frontHandle ;
public GameObject backHandle ;
Write an "Update" method that calles a method that computes the position of the object as the average of the 6 handles!
void Update () {
if (photonView.IsMine) {
ComputePosition () ;
}
}
void ComputePosition () {
transform.position = (topHandle.transform.position +
bottomHandle.transform.position +
leftHandle.transform.position +
rightHandle.transform.position +
frontHandle.transform.position +
backHandle.transform.position) / 6 ;
}
In the editor, associate interactively (with drag'n drop interactions) the 6 handles to these 6 parameters
Test your system with at least 2 clients
When you release one handle after a collaborative interaction, it does not come back to its initial position...
Make the handles come back to their initial positions
Create a new "GrabableHandle.cs" script that extends "Grabable.cs"
So that your existing interaction tools will still be able to manipulate the handles
Override the "LocalReleased" method:
public override void LocalRelease () {
if (caught) {
base.LocalRelease () ;
transform.localPosition = new Vector3 (0, 0, 0) ;
transform.localRotation = Quaternion.identity ;
}
}
To do that, maybe you will have to declare "protected" the "caught" attribute of the "Grabable.cs" script
Replace the "Grabable.cs" script of the "Handle" prefab by the new "GrabableHandle.cs" script
Optimize the code for a better efficiency when there is only one active handle:
Count how many handles are active
In the "Update" method, call the "ComputePosition" method only if there is at least 1 active handle
Each time there is a "first" active handle, ask for the ownership of the cube and of all the handles
This other version should propose a duplicated behavior
With no "PhotonTransformView"
With no test if "photonView.IsMine" before computing the position
With a systematic call to the "ComputePosition" when "starting" the object, for users who join lately the shared universe