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(); // آزاد کردن مالکیت از بازیکن قبلی 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().RequestStateAuthority(); base.OnGrab(grabber); grabed = true; Rigidbody rb = GetComponent(); // if (rb) // rb.useGravity = false; if (markerNetwork == null) { markerNetwork = GetComponent(); } markerNetwork?.StartDrawing(); gameObject. SendMessage("StartDrawing"); } public override void OnRelease() { base.OnRelease(); grabed = false; print("not grab"); markerNetwork?.StopDrawing(); gameObject.SendMessage("StopDrawing"); Rigidbody rb = GetComponent(); //RequestStateAuthority // if (rb) // rb.useGravity = true; } public void OnCollisionEnter(Collision collision) { if (!grabed && collision.gameObject.tag.Equals("remover")) { if(Live) GetComponent(). ResetPositionAndRotation(); if (!Live) { if (Object) Runner.Despawn(Object); } /* NetworkObject netObj = GetComponent(); netObj.ReleaseStateAuthority(); netObj.RemoveInputAuthority();*/ } } public void Update() { mine = GetComponent().HasInputAuthority; } public bool mine; public bool Live; } }