private static bool FindActiveInternal <BEACONTYPE>(BEACONTYPE label, out ILabelBeacon foundBeacon) { var beacons = UnityEngine.Object.FindObjectsOfType <MonoBehaviour>().OfType <ILabelBeacon>(); //Debug.Log($"Find active {beacons.Count()}"); ILabelBeacon testBeacon = null; bool found = false; foreach (var b in beacons) { //Debug.Log($"Checking {b.Label} {b.GetType()} vs {label}"); if (b.Label is BEACONTYPE t && t.Equals(label)) { if (found) { throw new BeaconException($"Multiple beacons with label {label} found. This is considered an error."); } testBeacon = b; found = true; //Debug.Log($"WE FOUND IT"); } } if (!found) { foundBeacon = null; return(false); } else { foundBeacon = testBeacon; return(true); } }
/// <summary> /// Find an **active** beacon in the scene. /// </summary> /// <returns>`false` when not found.</returns> /// <exception cref="Exception"> /// Thrown when found multiple beacons with the same <paramref name="label"/>. /// </exception> public static bool FindActive <BEACONTYPE>(BEACONTYPE label, out ILabelBeacon foundBeacon) where BEACONTYPE : Enum => FindActiveInternal(label, out foundBeacon);