static bool CoppaComplianceMet(IEditorGameService editorGameService, ProjectState projectState)
        {
#if ENABLE_EDITOR_GAME_SERVICES
            return(editorGameService == null || !editorGameService.RequiresCoppaCompliance || projectState.CoppaCompliance != CoppaCompliance.CoppaUndefined);
#else
            return(false);
#endif
        }
        internal static bool IsUserAllowedToEditServiceToggle(IEditorGameService editorGameService, ProjectState projectState, UserRole userRole)
        {
#if ENABLE_EDITOR_GAME_SERVICES
            return(IsCoppaComplianceMet(editorGameService, projectState.CoppaCompliance) &&
                   (userRole == UserRole.Manager || userRole == UserRole.Owner));
#else
            return(false);
#endif
        }
Example #3
0
 /// <remarks>A standard if else is used here instead of the ternary conditional operator to prevent an implicit conversion error in the 2020 editor.</remarks>
 public void Init(IEditorGameService editorGameService)
 {
     if (editorGameService.Enabler.IsEnabled())
     {
         m_CurrentVisuals = new EnabledVisuals();
     }
     else
     {
         m_CurrentVisuals = new DisabledVisuals();
     }
 }
Example #4
0
        /// <summary>
        /// Get the instance of a <see cref="IEditorGameService"/> type.
        /// </summary>
        /// <param name="serviceIdentifier">The identifier for a service</param>
        /// <returns>Return the instance of the given <see cref="IEditorGameService"/> type if it has been registered.</returns>
        public IEditorGameService GetEditorGameService <TIdentifier>()
            where TIdentifier : struct, IEditorGameServiceIdentifier
        {
            IEditorGameService output = null;

            var serviceIdentifier = new TIdentifier();

            if (Services.ContainsKey(serviceIdentifier.GetKey()))
            {
                output = Services[serviceIdentifier.GetKey()];
            }

            return(output);
        }
Example #5
0
 internal void RegisterService(IEditorGameService editorGameService)
 {
     if (IsIdentifierValid(editorGameService))
     {
         if (Services.ContainsKey(editorGameService.Identifier.GetKey()))
         {
             throw new DuplicateNameException($"The Identifier key {editorGameService.Identifier.GetKey()} already exists in the registry. Cannot register the service.");
         }
         else
         {
             Services.Add(editorGameService.Identifier.GetKey(), editorGameService);
         }
     }
 }
Example #6
0
        internal static bool IsIdentifierValid(IEditorGameService editorGameService)
        {
            if (editorGameService.Identifier == null)
            {
                throw new NoNullAllowedException($"The Identifier for the service {editorGameService.Name} is null. Cannot register the service.");
            }

            if (string.IsNullOrEmpty(editorGameService.Identifier.GetKey()))
            {
                throw new ArgumentException($"The Identifier key for the service {editorGameService.Name} is null or empty. Cannot register the service.");
            }

            return(true);
        }
Example #7
0
        /// <summary>
        /// Opens the dashboard of the <see cref="IEditorGameService"/>
        /// </summary>
        /// <param name="editorGameService">The <see cref="IEditorGameService"/> who's dashboard should open</param>
        public static void OpenDashboard(this IEditorGameService editorGameService)
        {
            if (!editorGameService.HasDashboard)
            {
                throw new InvalidOperationException($"The service '{editorGameService.Name}' is not configured to use a Dashboard. " +
                                                    $"Make sure the service returns 'true' in 'HasDashboard' implementation.");
            }

            var formattedUrl = editorGameService.GetFormattedDashboardUrl();

            if (Uri.IsWellFormedUriString(formattedUrl, UriKind.Absolute))
            {
                EditorGameServiceAnalyticsSender.SendProjectSettingsGoToDashboardEvent(editorGameService.Identifier.GetKey());
                Application.OpenURL(formattedUrl);
            }
            else
            {
                throw new UriFormatException($"Dashboard Url for service '{editorGameService.Name}' is not properly formatted." +
                                             $" Attempted to use url '{formattedUrl}'. Make sure the service returns a proper url in 'GetFormattedDashboardUrl()' implementation.");
            }
        }
Example #8
0
        /// <summary>
        /// Recursively sorts the dependencies of the provided <paramref name="service"/> in deepest order first.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="visited"></param>
        /// <param name="serviceRegistry"></param>
        /// <returns></returns>
        private static IEnumerable <IEditorGameService> OrderByDependency(IEditorGameService service, ISet <IEditorGameService> visited, EditorGameServiceRegistry serviceRegistry)
        {
            if (!visited.Add(service))
            {
                yield break;
            }

            foreach (var dependencyType in service.Dependencies)
            {
                var dependency = serviceRegistry.Get(dependencyType);
                if (dependency == null)
                {
                    throw new InvalidOperationException($"The service [{service.GetType().Name}] requires a service of type [{dependencyType.Name}].");
                }

                foreach (var item in OrderByDependency(dependency, visited, serviceRegistry))
                {
                    yield return(item);
                }
            }
            yield return(service);
        }
Example #9
0
        internal static bool TryGetServiceFromType(Type type, out IEditorGameService service)
        {
            var output = false;

            service = null;

            try
            {
                service = (IEditorGameService)Activator.CreateInstance(type);
                output  = IsIdentifierValid(service);
            }
            catch (MissingMethodException)
            {
                output = false;
            }

            if (!output)
            {
                service = null;
            }

            return(output);
        }
 internal static bool IsCoppaComplianceMet(IEditorGameService editorGameService, CoppaCompliance currentCoppaStatus)
 {
     return(editorGameService == null || !editorGameService.RequiresCoppaCompliance ||
            currentCoppaStatus != CoppaCompliance.CoppaUndefined);
 }
Example #11
0
 internal static bool IsServiceInactive(IEditorGameService editorGameService)
 {
     return(editorGameService.Enabler != null && !editorGameService.Enabler.IsEnabled());
 }