Example #1
0
        public Task Reload(TaskListener listener = null)
        {
            return(Task.Run(() =>
            {
                dependencies.Inject(offlineUser);
                userStore.Reload();

                listener?.SetFinished();
            }));
        }
Example #2
0
        protected override IGameSession CreateSession(IGraphicObject container, IDependencyContainer dependency)
        {
            var session = new BeatsStandardSession(container);

            dependency.Inject(session);
            return(session);
        }
Example #3
0
        /// <summary>
        /// Creates a new instance of the RootMain and returns it.
        /// </summary>
        public static new Root3D Create(IDependencyContainer dependency)
        {
            var root = new GameObject("Root3D").AddComponent <Root3D>();

            if (dependency != null)
            {
                dependency.Inject(root);

                if (!dependency.Contains <IRoot>())
                {
                    dependency.CacheAs <IRoot>(root);
                }
            }
            return(root);
        }
Example #4
0
        private void Init(IModeManager modeManager, IDependencyContainer dependency)
        {
            // Create user statistics for missing game modes using mode manager.
            foreach (var mode in modeManager.PlayableServices())
            {
                if (!statistics.ContainsKey(mode.GameMode))
                {
                    statistics[mode.GameMode] = new UserStatistics()
                    {
                        GameMode = mode.GameMode
                    };
                }
            }

            // Inject dependencies to all user statistics.
            foreach (var s in statistics.Values)
            {
                s.User = this;
                dependency.Inject(s);
            }
        }
Example #5
0
        private static void CollectFactories()
        {
            if (FactoryLookup.Count > 0)
            {
                return;
            }

            var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
                        .Where(x => typeof(IWidgetFactory).IsAssignableFrom(x));

            foreach (var factoryType in types)
            {
                if (!factoryType.IsAbstract && !factoryType.IsInterface)
                {
                    var atts = factoryType.GetCustomAttributes(typeof(CustomWidgetFactoryAttribute), true);
                    if (atts.Length <= 0)
                    {
                        continue;
                    }

                    if (!(atts[0] is CustomWidgetFactoryAttribute att))
                    {
                        continue;
                    }

//                        Debug.Log("Collect " + att.WidgetType);
                    if (!(Activator.CreateInstance(factoryType) is IWidgetFactory factoryInstance))
                    {
                        continue;
                    }

                    _container.Inject(factoryInstance);
                    factoryInstance.SetupFactory();
                    RegisterFactory(att.WidgetType, factoryInstance);
                }
            }
        }
Example #6
0
 public static void Inject <T>(T existing)
 {
     resolver.Inject <T>(existing);
 }
Example #7
0
        public void CreateInstance(IUIManager manager, string widgetPath, int assignedId, UIMessage message,
                                   Action <Widget> onCreated)
        {
            if (!_caches.ContainsKey(widgetPath))
            {
                for (var i = 0; i < _databases.Count; i++)
                {
                    var database = _databases[i];
                    if (!database.Value.ContainsKey(widgetPath))
                    {
                        continue;
                    }

                    var result = database.Value[widgetPath];
                    _caches.Add(widgetPath, result);
                }
            }


            if (!_caches.ContainsKey(widgetPath))

            {
                Debug.LogError($"Can't found widget@{widgetPath}");
                return;
            }

            var widgetPrefab = _caches[widgetPath];

            if (widgetPrefab == null)
            {
                for (var i = 0; i < _databases.Count; i++)
                {
                    var database = _databases[i];
                    if (!database.Value.ContainsKey(widgetPath))
                    {
                        continue;
                    }

                    Debug.LogError(
                        $"Can't instantiate widget[{widgetPath}], it reference a [NULL] prefab in database[{database.name}].");
                }

                return;
            }

            var instance = Object.Instantiate(widgetPrefab);

            instance.SetManagerInfo(assignedId, widgetPath, manager);
            var instanceType = instance.GetType();

            if (_controllerRef.ContainsKey(instanceType))
            {
                var controllerType     = _controllerRef[instanceType];
                var controllerInstance =
                    Activator.CreateInstance(controllerType) as IWidgetController;

                if (controllerInstance == null)
                {
                    Debug.LogError($"Create [{controllerType}] instance failed.");
                    return;
                }

                _container.Inject(controllerInstance);
                try
                {
                    controllerInstance.SetControllerInfo(instance, manager, message);
                    controllerInstance.Initialize();
                }
                catch (Exception e) { Debug.LogException(e); }

                // cache reference
                instance.Controller = controllerInstance;
            }

            onCreated?.Invoke(instance);
        }