XRoom_Unity/Assets/MarkerGrab.cs
2025-05-31 10:20:20 +03:30

89 lines
2.6 KiB
C#

using Fusion;
using UnityEngine;
namespace BNG
{
public class MarkerGrab : GrabbableEvents
{
private MarkerNetwork markerNetwork;
public bool grabed;
[Rpc(RpcSources.All,RpcTargets.All)]
public void RPC_SetAllow(PlayerRef p)
{
/* if (Runner.IsServer)
{
NetworkObject netObj = GetComponent<NetworkObject>();
// آزاد کردن مالکیت از بازیکن قبلی
netObj.ReleaseStateAuthority();
netObj.RemoveInputAuthority();
// دادن مالکیت وضعیت به بازیکن جدید
netObj.AssignInputAuthority(p);
print("GIVE STATE AUTHORITY TO " + p.PlayerId);
}*/
}
public override void OnGrab(Grabber grabber)
{
// Object.RequestStateAuthority();
// RPC_SetAllow(Runner.LocalPlayer);
GetComponent<NetworkObject>().RequestStateAuthority();
base.OnGrab(grabber);
grabed = true;
Rigidbody rb = GetComponent<Rigidbody>();
// if (rb)
// rb.useGravity = false;
if (markerNetwork == null)
{
markerNetwork = GetComponent<MarkerNetwork>();
}
markerNetwork?.StartDrawing();
gameObject. SendMessage("StartDrawing");
}
public override void OnRelease()
{
base.OnRelease();
grabed = false;
print("not grab");
markerNetwork?.StopDrawing();
gameObject.SendMessage("StopDrawing");
Rigidbody rb = GetComponent<Rigidbody>();
//RequestStateAuthority
// if (rb)
// rb.useGravity = true;
}
public void OnCollisionEnter(Collision collision)
{
if (!grabed && collision.gameObject.tag.Equals("remover"))
{
if(Live)
GetComponent<ResetPositionAndRotationByHost>(). ResetPositionAndRotation();
if (!Live)
{
if (Object)
Runner.Despawn(Object);
}
/* NetworkObject netObj = GetComponent<NetworkObject>();
netObj.ReleaseStateAuthority();
netObj.RemoveInputAuthority();*/
}
}
public void Update()
{
mine = GetComponent<NetworkObject>().HasInputAuthority;
}
public bool mine;
public bool Live;
}
}