public static TRegistered[] GetInstances()
            {
                if (!ApplicationIsPlaying)
                {
                    return(ErrorEditMode());
                }

                if (count == 0)
                {
                    return(Array.Empty <TRegistered>());
                }

#if MEDICINE_FUNSAFE_COLLECTIONS
                var instancesForEnumeration = instances;
                NonAlloc.Unsafe.OverwriteArrayLength(instances, count);
#else
                // copy instances to temporary buffer
                // this avoids issues with instances being disabled during enumeration
                var instancesForEnumeration = NonAlloc.GetArray <TRegistered>(length: count, clear: false);

                Array.Copy(
                    sourceArray: instances,
                    destinationArray: instancesForEnumeration,
                    length: count
                    );
#endif

                return(instancesForEnumeration);
            }
示例#2
0
            static TSingleton TryFindObjectByType()
            {
                var objectsOfType = NonAlloc.FindObjectsOfType <TSingleton>();

                return(objectsOfType.Length > 0
                    ? objectsOfType[0]
                    : null);
            }