public static bool InitializeWithScene() { GameSettingsComponent settingsComponent = GameObject.FindObjectOfType <GameSettingsComponent>(); if (settingsComponent == null) { return(false); } Settings = settingsComponent?.GameSettings; return(true); }
private void Awake() { if (instance == null) { instance = this; if (RemoveAfterLoad) { Destroy(gameObject); } return; } Debug.LogError("Error: multiple GameSettingsComponent scripts exist in scene"); }
public MeshRenderer( GraphicsDevice graphicsDevice, GameSettingsComponent settings, ContentManager contentManager, Model scene) { _graphicsDevice = graphicsDevice; _settings = settings; _scene = scene; _sceneTransforms = new Matrix[_scene.Bones.Count]; _scene.CopyAbsoluteBoneTransformsTo(_sceneTransforms); _cascadeSplits = new float[4]; _frustumCorners = new Vector3[8]; _shadowMapEffect = new ShadowMapEffect(graphicsDevice, contentManager.Load <Effect>("effects/ShadowMap")); _meshEffect = new MeshEffect(graphicsDevice, contentManager.Load <Effect>("effects/Mesh")); _boundingFrustum = new BoundingFrustum(Matrix.Identity); CreateShadowMaps(); }
protected override void Initialize() { _camera = new FirstPersonCamera(MathHelper.PiOver4 * 0.75f, Window.ClientBounds.Width / (float)Window.ClientBounds.Height, 0.25f, 250.0f); _camera.Position = new Vector3(20.0f, 5.0f, 65.0f); _camera.YRotation = MathHelper.PiOver4; _camera.XRotation = 0; Mouse.SetPosition(Window.ClientBounds.Width / 2, Window.ClientBounds.Height / 2); Components.Add(new FramesPerSecondComponent(this)); Components.Add(_gameSettings = new GameSettingsComponent(this)); var guiService = new GuiComponent(this); Components.Add(guiService); Services.AddService <IGuiService>(guiService); base.Initialize(); }
protected override void Initialize() { this.settings = new GameSettings(); GameSettingsComponent settingsComponent = new GameSettingsComponent(this, settings, graphics); this.Components.Add(settingsComponent); LoadingScreenComponent loading = new LoadingScreenComponent(this, settings); this.Components.Add(loading); MenuItemsComponent menuItems = new MenuItemsComponent( this, settings, new Vector2(this.viewport.Width * 0.45f, this.viewport.Height * 0.75f), Color.Blue, Color.Yellow, 72 ); menuItems.AddItem("Hrát", "new-game"); menuItems.AddItem("Nastavení", "settings"); menuItems.AddItem("O høe", "about"); menuItems.AddItem("Odejít", "exit"); MenuItemsComponent settingScreenItems = new MenuItemsComponent( this, settings, new Vector2(this.viewport.Width * 0.45f, this.viewport.Height * 0.75f), Color.Blue, Color.Yellow, 72 ); settingScreenItems.AddItem("Postava", "player-sprite"); settingScreenItems.AddItem("Hudba", "music-enabled"); settingScreenItems.AddItem("Zpìt do menu", "back"); ScrollingBackgroundComponent scrollingBackground = new ScrollingBackgroundComponent(this, settings); this.Components.Add(scrollingBackground); GameSettingsScreenComponent settingsScreenComponent = new GameSettingsScreenComponent(this, settings, settingScreenItems); this.Components.Add(settingsScreenComponent); AboutScreenComponent aboutScreenComponent = new AboutScreenComponent(this, settings); this.Components.Add(aboutScreenComponent); MenuComponent menu = new MenuComponent(this, settings, menuItems); this.Components.Add(menu); LevelComponent level = new LevelComponent(this, settings, scrollingBackground); this.Components.Add(level); this.loadingScreen = new GameWindow(this, loading); this.menuWindow = new GameWindow(this, menu, menuItems, settingsComponent, scrollingBackground); this.ingameWindow = new GameWindow(this, level, settingsComponent, scrollingBackground); this.settingsScreen = new GameWindow(this, settingsScreenComponent, settingScreenItems, settingsComponent, scrollingBackground); this.aboutScreen = new GameWindow(this, settingsComponent, scrollingBackground, aboutScreenComponent); foreach (GameComponent component in this.Components) { this.SwitchComponent(component, false); } // BASE GRAPHICS STUFF this.IsMouseVisible = false; //this.graphics.IsFullScreen = true; this.graphics.PreferredBackBufferHeight = 720; this.graphics.PreferredBackBufferWidth = 1280; this.graphics.ApplyChanges(); this.SwitchWindows(loadingScreen); base.Initialize(); }
protected override void OnUpdate() { //We must declare our local variables before using them within a job (.ForEach) var commandBuffer = m_BeginSimEcb.CreateCommandBuffer(); var rpcFromEntity = GetBufferFromEntity <OutgoingRpcDataStreamBufferComponent>(); var gameSettingsEntity = GetSingletonEntity <GameSettingsComponent>(); var getGameSettingsComponentData = GetComponentDataFromEntity <GameSettingsComponent>(); var clientData = GetSingleton <ClientDataComponent>(); //We will use this to send the player name to server Entities .ForEach((Entity entity, in SendClientGameRpc request, in ReceiveRpcCommandRequestComponent requestSource) => { //This destroys the incoming RPC so the code is only run once commandBuffer.DestroyEntity(entity); //Check for disconnects before moving forward if (!rpcFromEntity.HasComponent(requestSource.SourceConnection)) { return; } //Set the game size (unnecessary right now but we are including it to show how it is done) getGameSettingsComponentData[gameSettingsEntity] = new GameSettingsComponent { levelWidth = request.levelWidth, levelHeight = request.levelHeight, levelDepth = request.levelDepth, playerForce = request.playerForce, bulletVelocity = request.bulletVelocity }; //Here we create a new singleton entity for GameNameComponent //We could add this component to the singleton entity that has the GameSettingsComponent //but we will keep them separate in case we want to change workflows in the future and don't //want these components to be dependent on the same entity var gameNameEntity = commandBuffer.CreateEntity(); commandBuffer.AddComponent(gameNameEntity, new GameNameComponent { GameName = request.gameName }); //These update the NCE with NetworkStreamInGame (required to start receiving snapshots) and //PlayerSpawningStateComponent, which we will use when we spawn players commandBuffer.AddComponent(requestSource.SourceConnection, new PlayerSpawningStateComponent()); commandBuffer.AddComponent(requestSource.SourceConnection, default(NetworkStreamInGame)); //This tells the server "I loaded the level" //First we create an entity called levelReq that will have 2 necessary components //Next we add the RPC we want to send (SendServerGameLoadedRpc) and then we add //SendRpcCommandRequestComponent with our TargetConnection being the NCE with the server (which will send it to the server) var levelReq = commandBuffer.CreateEntity(); commandBuffer.AddComponent(levelReq, new SendServerGameLoadedRpc()); commandBuffer.AddComponent(levelReq, new SendRpcCommandRequestComponent { TargetConnection = requestSource.SourceConnection }); // this tells the server "This is my name and Id" which will be used for player score tracking var playerReq = commandBuffer.CreateEntity(); commandBuffer.AddComponent(playerReq, new SendServerPlayerNameRpc { playerName = clientData.PlayerName }); commandBuffer.AddComponent(playerReq, new SendRpcCommandRequestComponent { TargetConnection = requestSource.SourceConnection }); }).Schedule();