コード例 #1
0
        /// <summary>
        /// 创建游戏框架模块。
        /// </summary>
        /// <param name="moduleType">要创建的游戏框架模块类型。</param>
        /// <returns>要创建的游戏框架模块。</returns>
        private GameModule CreateModule(Type moduleType)
        {
            Debug.Log($"Create module interface={moduleType.FullName}");

            var implType = moduleType.IsInterface
                ? AssemblyCollection.GetTypes()
                           .Where(t => t.GetInterfaces().Any(i => i == moduleType))
                           .FirstOrDefault()
                : moduleType;

            if (implType == null)
            {
                throw new GameException($"Can not found implement type , interface='{moduleType.FullName}'.");
            }

            var hasDefaultCtor = implType.GetConstructors().Any(c => c.GetParameters().Length == 0);

            var module = (GameModule)(hasDefaultCtor
                ? Activator.CreateInstance(implType)
                : Activator.CreateInstance(implType, this));

            if (module == null)
            {
                throw new GameException($"Can not create module '{moduleType.FullName}'.");
            }

            modules.Add(module);
            modules.Sort((a, b) => b.Priority.CompareTo(a.Priority));

            return(module);
        }
コード例 #2
0
        public PresenterBase Get(string typeName)
        {
            var type = typeCaches.ContainsKey(typeName)
                ? typeCaches[typeName]
                : AssemblyCollection.GetType(typeName);

            return(Get(type));
        }
コード例 #3
0
        public PresenterManager(GameContext gameContext)
        {
            _eventManager = gameContext.GetModule <IEventManager>();
            var types = AssemblyCollection.GetTypes(t => t.IsSubclassOf(typeof(PresenterBase)) && !t.IsAbstract);

            foreach (var type in types)
            {
                var attr = type.GetCustomAttribute <AliasAttribute>();
                var name = attr?.Name ?? type.Name;
                typeCaches[name] = type;
            }
        }
コード例 #4
0
 public IScriptScope GetOrCreate(string scopeName)
 {
     if (!scopes.ContainsKey(scopeName))
     {
         var engine = new Engine(options =>
         {
             options.AllowClr(AssemblyCollection.GetAssemblies());
             options.LimitRecursion(sbyte.MaxValue);
         });
         scopes[scopeName] = new ScriptScope(scopeName, engine);
     }
     return(scopes[scopeName]);
 }
コード例 #5
0
        public IEnumerator InitializeAsync(string settingPath)
        {
            var types = AssemblyCollection.GetTypes(t => t.IsSubclassOf(typeof(AudioGroup)));

            foreach (var type in types)
            {
                var child = new GameObject(type.Name, type);
                child.transform.SetParent(root.transform);
                var handle = Addressables.LoadAssetAsync <AudioManagerSetting>($"{settingPath}/{type.Name}.asset");
                yield return(handle);

                var group = child.GetComponent <AudioGroup>();
                yield return(group.InitializeAsync(handle.Result));

                groups.Add(type, child.GetComponent <AudioGroup>());
            }
        }
コード例 #6
0
        public IEnumerator InitializeAsync(string rootPath, string variant = null)
        {
            var handle = Addressables.LoadAssetAsync <GameObject>(rootPath);

            yield return(handle);

            Root = GameObject.Instantiate(handle.Result);
            GameObject.DontDestroyOnLoad(Root);

            var waitables = new List <IObservable <Unit> >();

            foreach (var type in AssemblyCollection.GetTypes(t => t.IsSubclassOf(typeof(BaseUI)) && !t.IsAbstract))
            {
                waitables.Add(LoadPrefabAsync(type, variant).ToObservable());
            }

            yield return(Observable.WhenAll(waitables).ToAwaitableEnumerator());
        }
コード例 #7
0
        /// <summary>
        /// 初始化流程管理器。
        /// </summary>
        /// <param name="fsmManager">有限状态机管理器。</param>
        /// <param name="gameStages">流程管理器包含的流程。</param>
        public StageManager(GameContext context)
        {
            var fsmManager = context.GetModule <IFsmManager>();

            if (fsmManager == null)
            {
                throw new GameException("FSM manager is invalid.");
            }

            _fsmManager = fsmManager;

            var stages = AssemblyCollection
                         .GetTypes()
                         .Where(t => t.IsSubclassOf(typeof(StageBase)))
                         .Select(t => (StageBase)Activator.CreateInstance(t))
                         .ToArray();

            _stageFsm = _fsmManager.CreateFsm(this, stages);
        }
コード例 #8
0
        public IEnumerator InitializeAsync(string path)
        {
            var configTypes = AssemblyCollection
                              .GetTypes()
                              .Where(t => !t.IsAbstract && !t.IsInterface && typeof(IConfigReference).IsAssignableFrom(t))
                              .Select(t => (type: t, Key: $"{path}/{t.Name}.asset"))
                              .GroupBy(g => g.Key, v => v)
                              .ToDictionary(k => k.Key, v => v.FirstOrDefault().type);

            ConfigTypes = configTypes.Values.ToList();

            var tasks = new List <Task>();

            foreach (var pair in configTypes)
            {
                tasks.Add(LoadAssetAsync(pair.Key, pair.Value));
            }
            var completeTask = Task.WhenAll(tasks);

            yield return(new WaitUntil(() => completeTask.IsCompleted || completeTask.IsFaulted));
        }