Commit 362a8575 by alsunj

Merge branch 'feat/openable-gate' into 'main'

added gate with a door that is syncronized around network

See merge request alsunj/loputoo!7
parents 38024f9f 43aa083a
using System.Numerics;
using DG.Tweening;
using Unity.Netcode;
using UnityEngine;
using Vector3 = UnityEngine.Vector3;
using UnityEditor;
public class Chest : NetworkBehaviour, IInteractable
{
private GameObject chestLid;
private GameObject _chestLid;
private bool chestFound = false;
private bool _chestFound;
[ServerRpc(RequireOwnership = false)]
private void CmdOpenChestForEveryoneServerRpc()
......@@ -25,8 +23,8 @@ public class Chest : NetworkBehaviour, IInteractable
private void Awake()
{
chestLid = transform.Find("chest/chest_lid").gameObject;
if (chestLid == null)
_chestLid = transform.Find("chest/chest_lid").gameObject;
if (_chestLid == null)
{
Debug.LogError("ChestLid not found!");
}
......@@ -34,35 +32,35 @@ public class Chest : NetworkBehaviour, IInteractable
private void ChestFound()
{
chestLid.transform.DORotate(chestLid.transform.eulerAngles +
new Vector3(-130, 0, 0), 1f)
_chestLid.transform.DORotate(_chestLid.transform.eulerAngles +
new Vector3(-130, 0, 0), 1f)
.SetEase(Ease.OutBounce);
CmdOpenChestForEveryoneServerRpc();
}
private void ChestFoundForOtherClients()
{
chestLid.transform.DORotate(chestLid.transform.eulerAngles +
new Vector3(-130, 0, 0), 1f)
_chestLid.transform.DORotate(_chestLid.transform.eulerAngles +
new Vector3(-130, 0, 0), 1f)
.SetEase(Ease.OutBounce);
}
public void Interact()
{
if (!chestFound)
if (!_chestFound)
{
ChestFound();
chestFound = true;
_chestFound = true;
}
}
public void Interacted()
{
if (!chestFound)
if (!_chestFound)
{
ChestFoundForOtherClients();
chestFound = true;
_chestFound = true;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: b5b6ffef974e07748b4d098c29d3d8e9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using DG.Tweening;
using Unity.Netcode;
using UnityEngine;
public class Door : NetworkBehaviour, IInteractable
{
private GameObject _door;
private NetworkVariable<bool> _doorOpened = new NetworkVariable<bool>(false);
private void Awake()
{
_door = transform.Find("wall_doorway_door").gameObject;
if (_door == null)
{
Debug.LogError("Door not found!");
}
}
[ServerRpc(RequireOwnership = false)]
private void CmdOpenDoorForEveryoneServerRpc()
{
RpcOpenDoorForEveryoneClientRpc();
}
[ClientRpc]
private void RpcOpenDoorForEveryoneClientRpc()
{
Interacted();
}
[ServerRpc(RequireOwnership = false)]
private void CmdCloseDoorForEveryoneServerRpc()
{
RpcCloseDoorForEveryoneClientRpc();
}
[ClientRpc]
private void RpcCloseDoorForEveryoneClientRpc()
{
Interacted();
}
private void DoorOpened()
{
_door.transform.DORotate(
new Vector3(0, 90, 0), 1f)
.SetEase(Ease.OutBounce);
CmdOpenDoorForEveryoneServerRpc();
}
private void DoorOpenedForOtherClients()
{
_door.transform.DORotate(
new Vector3(0, 90, 0), 1f)
.SetEase(Ease.OutBounce);
}
private void DoorClosed()
{
_door.transform.DORotate(
new Vector3(0, 0, 0), 1f)
.SetEase(Ease.OutBounce);
CmdCloseDoorForEveryoneServerRpc();
}
private void DoorClosedForOtherClients()
{
_door.transform.DORotate(
new Vector3(0, 0, 0), 1f)
.SetEase(Ease.OutBounce);
}
public void Interact()
{
RequestOpenDoorServerRpc();
}
[ServerRpc(RequireOwnership = false)]
private void RequestOpenDoorServerRpc()
{
if (!_doorOpened.Value)
{
DoorOpened();
_doorOpened.Value = true;
}
else
{
DoorClosed();
_doorOpened.Value = false;
}
}
public void Interacted()
{
if (!_doorOpened.Value)
{
DoorOpenedForOtherClients();
}
else
{
DoorClosedForOtherClients();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 8b1dab2eab11c8a47a37ae0eadf44baa
\ No newline at end of file
......@@ -333,6 +333,11 @@ public class PlayerController : NetworkBehaviour
chest.Interact();
break;
case Door door:
RotatePlayerTowardsTarget(hitCollider);
_playerManager.playerEvents.PlayerInteract();
door.Interact();
break;
}
}
}
......
......@@ -216,7 +216,7 @@ AnimatorController:
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_DefaultBool: 1
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment