Exemple #1
0
        /// <summary>
        /// 获取游戏模块
        /// </summary>
        /// <typeparam name="T">模块类</typeparam>
        public static T GetModule <T>() where T : class, IModule
        {
            System.Type type = typeof(T);
            for (int i = 0; i < _coms.Count; i++)
            {
                if (_coms[i].Module.GetType() == type)
                {
                    return(_coms[i].Module as T);
                }
            }

            MotionLog.Warning($"Not found game module {type}");
            return(null);
        }
        /// <summary>
        /// 初始化框架
        /// </summary>
        public static void Initialize(MonoBehaviour behaviour, Action <ELogLevel, string> logCallback)
        {
            if (behaviour == null)
            {
                throw new Exception("MotionFramework behaviour is null.");
            }
            if (_behaviour != null)
            {
                throw new Exception($"{nameof(MotionEngine)} is already initialized.");
            }

            UnityEngine.Object.DontDestroyOnLoad(behaviour.gameObject);
            _behaviour = behaviour;

            // 注册日志回调
            if (logCallback != null)
            {
                MotionLog.RegisterCallback(logCallback);
            }

            behaviour.StartCoroutine(CheckFrame());
        }
Exemple #3
0
		/// <summary>
		/// 创建游戏模块
		/// </summary>
		/// <typeparam name="T">模块类</typeparam>
		/// <param name="createParam">创建参数</param>
		/// <param name="priority">运行时的优先级,优先级越大越早执行。如果没有设置优先级,那么会按照添加顺序执行</param>
		public static T CreateModule<T>(System.Object createParam, int priority = 0) where T : class, IModule
		{
			if (priority < 0)
				throw new Exception("The priority can not be negative");

			if (Contains(typeof(T)))
				throw new Exception($"Game module {typeof(T)} is already existed");

			// 如果没有设置优先级
			if (priority == 0)
			{
				int minPriority = GetMinPriority();
				priority = --minPriority;
			}

			MotionLog.Log($"Create game module : {typeof(T)}");
			T module = Activator.CreateInstance<T>();
			ModuleWrapper wrapper = new ModuleWrapper(module, priority);
			wrapper.Module.OnCreate(createParam);
			_coms.Add(wrapper);
			_isDirty = true;
			return module;
		}