/* * This file is part of the CatLib package. * * (c) CatLib * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * Document: http://catlib.io/ */ using UnityEngine; namespace CatLib { /// /// 框架入口 /// [DisallowMultipleComponent] [HelpURL("https://catlib.io/lasted")] public abstract class Framework : MonoBehaviour { /// /// 调试等级 /// public DebugLevels DebugLevel = DebugLevels.Production; /// /// CatLib Unity Application /// private Application application; /// /// CatLib Unity Application /// public IApplication Application { get { return application; } } /// /// 当框架启动完成时 /// protected abstract void OnStartCompleted(); /// /// Unity Awake /// protected virtual void Awake() { DontDestroyOnLoad(gameObject); application = CreateApplication(DebugLevel); BeforeBootstrap(application); application.Bootstrap(GetBootstraps()); } /// /// Unity Start /// protected virtual void Start() { application.Init(); } /// /// 创建新的Application实例 /// /// 调试等级 /// Application实例 protected virtual Application CreateApplication(DebugLevels debugLevel) { return new UnityApplication(this) { DebugLevel = DebugLevel }; } /// /// 在引导开始之前 /// /// 应用程序 protected virtual void BeforeBootstrap(IApplication application) { application.On(ApplicationEvents.OnStartCompleted, OnStartCompleted); } /// /// 获取引导程序 /// /// 引导脚本 protected virtual IBootstrap[] GetBootstraps() { return Arr.Merge(GetComponents(), Bootstraps.GetBoostraps(this)); } /// /// 当被释放时 /// protected virtual void OnDestroy() { if (application != null) { application.Terminate(); } } } }