using UnityEngine; using UnityEngine.XR; using Fusion; // اضافه کردن فضای نام Fusion using TMPro; using Fusion.Addons.ConnectionManagerAddon; namespace BNG { public class Chair : NetworkBehaviour { public Transform player; public Transform sitMan; private UnityEngine.XR.InputDevice leftController; // استفاده از Networked Variable برای همگام‌سازی مقدار fill [Networked] public bool networkedFill { get; set; } public RTLTMPro.RTLTextMeshPro text; void Start() { if (!text) text =GetComponentInChildren(); leftController = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand); player = GameObject.FindGameObjectWithTag("Player").transform; } public bool near; void Update() { // bool near = Vector3.Distance(transform.position, player.transform.position) < distance; // تنظیم رنگ با آلفای 0.6 //Color nearColor = near ? Color.yellow : Color.white; //nearColor.a = 0.6f; // تنظیم مقدار آلفا به 0.6 //text.color = nearColor; // if (!ConnectionManager.instance.runner.IsRunning || (player.GetComponent().sit && !networkedFill)) // return; // text.gameObject.SetActive(!networkedFill); //if (near) //{ // if ((leftController.TryGetFeatureValue(UnityEngine.XR.CommonUsages.primaryButton, out bool isPressed) && isPressed) || Input.GetKeyDown(KeyCode.T)) // { // } //} } public void SetSit() { if (!ConnectionManager.instance.runner.IsRunning || (player.GetComponent().sit && !networkedFill)) return; Debug.Log("X button was pressed!"); if (!player.GetComponent().sit) { sitMan = player; player.position = new Vector3(transform.position.x, player.position.y, transform.position.z); player.GetComponent().sit = true; player.GetComponent().chair = this; SetFill(true); // وقتی که پر شود } else if (networkedFill && sitMan == player&& !ConnectionManager.instance.presentation) { Invoke("standUp", 0.3f); } } public void standUp(){ sitMan=null; SetFill(false); // وقتی که خالی شود player.GetComponent().sit = false; } // متد برای تنظیم مقدار fill و همگام‌سازی آن با دیگر کلاینت‌ها void SetFill(bool value) { // if (HasInputAuthority) // بررسی این که آیا مالک این شیء هستید یا خیر { networkedFill = value; // مقدار شبکه‌ای را تنظیم می‌کند } } } }