Skip to content

Commit

Permalink
Sync lock position across all players.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca Haux committed Nov 6, 2018
1 parent cc964ff commit bb2fc7e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,20 @@ private void CmdSendSharedSavedPosition(GameObject target, Vector3 newPos, Quate
target.GetComponent<SyncLocalTransformUNET>().RpcSetSavedTransform(newPos, newRot, newScale);
}

public void SendLockTransform(GameObject target, string lockState)
{
if (isLocalPlayer)
{
CmdSendLockTransform(target, lockState);
}
}

[Command(channel = Channels.DefaultUnreliable)]
private void CmdSendLockTransform(GameObject target, string lockState)
{
target.GetComponent<SyncLocalTransformUNET>().RpcSetLockTransform(lockState);
}

public void SendToggleGroup(GameObject target, int groupNumber)
{
if (isLocalPlayer)
Expand Down
11 changes: 1 addition & 10 deletions Assets/Scripts/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,7 @@ public void Save() {
}

public void Lock() {
if (lockText.GetComponent<Text>().text == "Lock")
{
lockText.GetComponent<Text>().text = "Unlock";
skel.GetComponent<TwoHandManipulatable>().enabled = false;
}
else {
lockText.GetComponent<Text>().text = "Lock";
skel.GetComponent<TwoHandManipulatable>().enabled = true;
}

gameObject.GetComponent<SyncLocalTransformUNET>().LockTransform(lockText.GetComponent<Text>().text);
}

public void SetSavedTransform(Vector3 newPos, Quaternion newRot, Vector3 newScale) {
Expand Down
22 changes: 22 additions & 0 deletions Assets/Scripts/SyncLocalTransformUNET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

namespace HoloToolkit.Unity.SharingWithUNET
{
Expand Down Expand Up @@ -60,6 +61,27 @@ public void RpcSetSavedTransform(Vector3 position, Quaternion rotation, Vector3
GetComponent<Position>().SetSavedTransform(position, rotation, scale);
}

public void LockTransform(string lockState) {
PlayerController.Instance.SendLockTransform(gameObject, lockState);
}

[ClientRpc(channel = Channels.DefaultUnreliable)]
public void RpcSetLockTransform(string lockState)
{
Position posComponent = GetComponent<Position>();

if (lockState == "Lock")
{
posComponent.lockText.GetComponent<Text>().text = "Unlock";
posComponent.skel.GetComponent<TwoHandManipulatable>().enabled = false;
}
else
{
posComponent.lockText.GetComponent<Text>().text = "Lock";
posComponent.skel.GetComponent<TwoHandManipulatable>().enabled = true;
}
}

public void Start()
{
lastPos = transform.localPosition;
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ PlayerSettings:
m_RenderingPath: 1
m_MobileRenderingPath: 1
metroPackageName: DICOMviewer
metroPackageVersion: 1.0.74.0
metroPackageVersion: 1.0.75.0
metroCertificatePath: Assets\WSATestCertificate.pfx
metroCertificatePassword:
metroCertificateSubject: DefaultCompany
Expand Down

0 comments on commit bb2fc7e

Please sign in to comment.