using FishNet.Connection; using FishNet.Observing; using UnityEngine; using UnityEngine.SceneManagement; namespace FishNet.Component.Observing { /// /// When this observer condition is placed on an object, a client must be within the same scene to view the object. /// [CreateAssetMenu(menuName = "FishNet/Observers/Scene Condition", fileName = "New Scene Condition")] public class SceneCondition : ObserverCondition { /// /// Returns if the object which this condition resides should be visible to connection. /// /// Connection which the condition is being checked for. /// True if the connection currently has visibility of this object. /// True if the condition was not processed. This can be used to skip processing for performance. While output as true this condition result assumes the previous ConditionMet value. public override bool ConditionMet(NetworkConnection connection, bool currentlyAdded, out bool notProcessed) { notProcessed = false; if (base.NetworkObject == null || connection == null) return false; /* When there is no owner only then is the gameobject * scene checked. That's the only way to know at this point. */ return connection.Scenes.Contains(base.NetworkObject.gameObject.scene); } /// /// How a condition is handled. /// /// public override ObserverConditionType GetConditionType() => ObserverConditionType.Normal; } }