/// <summary> /// 以Delegate委托方式注入初始数据 /// </summary> /// <param name="s"></param> /// <param name="data"></param> public virtual void Register(LSetting s, ScreenDelegate data) { if (s is MonoGameSetting mgs) { this._setting = mgs; } else { MonoGameSetting tmp = new MonoGameSetting(); tmp.Copy(s); tmp.fullscreen = true; this._setting = tmp; } this._mainDelegateData = data; }
protected override void Initialize() { LSystem.FreeStaticObject(); if (_xnalistener != null) { _xnalistener.Initialize(); } this.OnMain(); if (_setting == null) { _setting = new MonoGameSetting(); } LMode mode = _setting.showMode; if (mode == default) { mode = LMode.Fill; } float width = _setting.width; float height = _setting.height; // 是否按比例缩放屏幕 if (_setting.useRatioScaleFactor) { float scale = ScaleFactor(); width *= scale; height *= scale; _setting.width_zoom = (int)width; _setting.height_zoom = (int)height; _setting.UpdateScale(); mode = LMode.MaxRatio; } else if (!(PlatformInfo.MonoGamePlatform == MonoGamePlatform.DesktopGL || PlatformInfo.MonoGamePlatform == MonoGamePlatform.Windows || PlatformInfo.MonoGamePlatform == MonoGamePlatform.WindowsUniversal) && (_setting.width_zoom <= 0 || _setting.height_zoom <= 0)) { UpdateViewSize(_setting.Landscape(), _setting.width, _setting.height, mode); width = this.maxWidth; height = this.maxHeight; _setting.width_zoom = this.maxWidth; _setting.height_zoom = this.maxHeight; _setting.UpdateScale(); mode = LMode.Fill; } else { this.maxWidth = _setting.width; this.maxHeight = _setting.height; this.zoomWidth = _setting.width_zoom; this.zoomHeight = _setting.height_zoom; UpdateViewSizeData(mode); _setting.UpdateScale(); } Window.AllowUserResizing = _setting.allowUserResizing; Window.Title = _setting.appName; Window.OrientationChanged += OnOrientationChanged; Window.ClientSizeChanged += OnClientSizeChanged; #if WINDOWS || DEBUG IsMouseVisible = _setting.isMouseVisible; #endif IsFixedTimeStep = _setting.isFixedTimeStep; _graphics.PreparingDeviceSettings += (object s, PreparingDeviceSettingsEventArgs args) => { args.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; }; _graphics.DeviceReset += OnGraphicsDeviceReset; _graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8; _graphics.PreferredBackBufferFormat = _displayMode.Format; _graphics.PreferredBackBufferWidth = _setting.Width; _graphics.PreferredBackBufferHeight = _setting.Height; _graphics.IsFullScreen = _setting.fullscreen; _graphics.SynchronizeWithVerticalRetrace = _setting.synchronizeVerticalRetrace; _graphics.PreferMultiSampling = _setting.preferMultiSampling; if (_setting.Landscape()) { _graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; } else { _graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.PortraitDown; } _graphics.ApplyChanges(); base.Initialize(); this.SetFPS(_setting.fps); this.InitializeGame(); }