namespace Fusion.Addons.InterestManagement { using System; using System.Collections.Generic; using UnityEngine; /// /// Base class for interest shapes. The purpose of this component is to hold configuration, /// get immediate visual feedback and convert to Fusion interest cell coordinate system. /// public abstract class InterestShape : MonoBehaviour { // PUBLIC MEMBERS /// /// Cached Transform component. /// public Transform Transform { get { if (ReferenceEquals(_transform, null) == true) { _transform = transform; } return transform; } } // PROTECTED MEMBERS /// /// Used for cache invalidation. /// protected static readonly long Version = DateTime.Now.Ticks; // PRIVATE MEMBERS private Transform _transform; // InterestShape INTERFACE /// /// Override this method to convert interest shape into interest cells. /// PlayerInterestView can be optionally used for further filtering. /// /// Player interest view with player information. /// Interest cells that should be set. /// Interest mode of the shape. public abstract void GetCells(PlayerInterestView playerView, HashSet cells, EInterestMode interestMode); /// /// Override this method to draw shape gizmos. /// /// Player interest view with player information. Can be null. public abstract void DrawGizmo(PlayerInterestView playerView); /// /// Combines interest cells based on interest mode. /// protected static void CombineCells(HashSet sourceCells, HashSet targetCells, EInterestMode interestMode) { if (interestMode == EInterestMode.Default || interestMode == EInterestMode.Override) { foreach (int cell in sourceCells) { targetCells.Add(cell); } } else if (interestMode == EInterestMode.Exclude) { foreach (int cell in sourceCells) { targetCells.Remove(cell); } } else { throw new NotSupportedException(nameof(interestMode)); } } #if UNITY_EDITOR [UnityEditor.DrawGizmo(UnityEditor.GizmoType.Active)] private static void DrawGizmo(InterestShape interestShape, UnityEditor.GizmoType gizmoType) { if ((gizmoType & UnityEditor.GizmoType.Active) != UnityEditor.GizmoType.Active) return; interestShape.DrawGizmo(default); } #endif } }