using FishNet.Connection; using FishNet.Object; using FishNet.Observing; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine; namespace FishNet.Component.Observing { /// /// When this observer condition is placed on an object, a client must be within the specified grid accuracy to view the object. /// [CreateAssetMenu(menuName = "FishNet/Observers/Grid Condition", fileName = "New Grid Condition")] public class GridCondition : 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. [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool ConditionMet(NetworkConnection connection, bool currentlyAdded, out bool notProcessed) { //If here then checks are being processed. notProcessed = false; return connection.HashGridEntry.NearbyEntries.Contains(base.NetworkObject.HashGridEntry); } /// /// How a condition is handled. /// /// public override ObserverConditionType GetConditionType() => ObserverConditionType.Timed; /// /// Clones referenced ObserverCondition. This must be populated with your conditions settings. /// /// public override ObserverCondition Clone() { GridCondition copy = ScriptableObject.CreateInstance(); return copy; } } }