public override void OnEnable() { base.OnEnable(); RoomComponents.OnAdd().Subscribe(entity1 => { var roomComponent = entity1.GetComponent <RoomComponent>(); UserComponents.Entities.OnAdd().Subscribe(entity2 => { var userComponent = entity2.GetComponent <UserComponent>(); userComponent.IsRoomOwner.DistinctUntilChanged().Subscribe(_ => { UpdateRoomState(roomComponent); }).AddTo(this.Disposer).AddTo(userComponent.Disposer); }).AddTo(this.Disposer); UserComponents.Entities.OnRemove().Select(_ => true) .Merge(Observable.ReturnUnit().Select(_ => true)) .Subscribe(_ => { UpdateRoomState(roomComponent); }).AddTo(this.Disposer); roomComponent.StartButton.OnClickAsObservable().Subscribe(_ => { foreach (var entity3 in UserComponents.Entities) { var userComponent = entity3.GetComponent <UserComponent>(); if (userComponent.IsLocalPlayer) { LockstepUtility.AddInput(new EventInput().WithType(EventCode.GameStart).Add(userComponent.IsRoomOwner.Value)); break; } } }).AddTo(this.Disposer).AddTo(roomComponent.Disposer); roomComponent.ExitButton.OnClickAsObservable().Subscribe(_ => { foreach (var entity4 in UserComponents.Entities) { var userComponent = entity4.GetComponent <UserComponent>(); if (userComponent.IsLocalPlayer) { NetworkSystem.Publish(RequestCode.QuitRoom, userComponent.UserId.ToString()); break; } } }).AddTo(this.Disposer).AddTo(roomComponent.Disposer); }).AddTo(this.Disposer); }
private void UpdateInputs() { if (ThridPersonCameraComponents.Entities.Count <= 0) { return; } var virtualCamera = ThridPersonCameraComponents.Entities[0].GetComponent <CinemachineVirtualCamera>(); var viewComponent = ThridPersonCameraComponents.Entities[0].GetComponent <ViewComponent>(); LockstepUtility.AddInput(new EventInput() .WithType(EventCode.PlayerCamera) .Add((FixVector3)viewComponent.Transforms[0].position) .Add((FixVector3)viewComponent.Transforms[0].forward) .Add((Fix64)virtualCamera.m_Lens.FarClipPlane)); }
public override void OnEnable() { base.OnEnable(); EventSystem.OnEvent <SpawnUserEvent>(true).Subscribe(evt => { foreach (var entity in UserComponents.Entities) { var userComponent = entity.GetComponent <UserComponent>(); if (userComponent.UserId == evt.UserId) { userComponent.IsRoomOwner.Value = evt.IsRoomOwner; return; } } CreateUser(evt.IsLocalPlayer, evt.IsRoomOwner, evt.UserId, evt.Username, evt.TotalCount, evt.WinCount); }).AddTo(this.Disposer); NetworkSystem.Receive(RequestCode.QuitRoom).Subscribe(data => { foreach (var entity in UserComponents.Entities) { var userComponent = entity.GetComponent <UserComponent>(); var viewComponent = entity.GetComponent <ViewComponent>(); if (userComponent.UserId == int.Parse(data.StringValue)) { if (userComponent.IsLocalPlayer || userComponent.IsRoomOwner.Value) { ClearOtherPlayers(); } else { Destroy(viewComponent.Transforms[0].gameObject); } break; } } }).AddTo(this.Disposer); if (offline) { CreateUser(true, true, 0, "Offline Player", 0, 0); NetworkSystem.Mode = SessionMode.Offline; LockstepUtility.AddInput(new EventInput().WithType(EventCode.GameStart).Add(true)); } }
private void UpdateInputs() { LockstepUtility.AddInput(new EventInput().WithType(EventCode.HeartBeat)); var axisInput = new AxisInput(); axisInput.Horizontal = (Fix64)Input.GetAxis(InputParameters.Horizontal); axisInput.Vertical = (Fix64)Input.GetAxis(InputParameters.Vertical); LockstepUtility.AddInput(axisInput); var keyInput = new KeyInput() { KeyCodes = new List <int>() }; foreach (var obj in Enum.GetValues(typeof(KeyCode))) { if (Input.GetKey((KeyCode)obj)) { keyInput.KeyCodes.Add((int)obj); } } LockstepUtility.AddInput(keyInput); var mouseInput = new MouseInput() { MouseButtons = new List <int>() }; for (int i = 0; i < 3; i++) { if (Input.GetMouseButton(i)) { mouseInput.MouseButtons.Add(i); } } mouseInput.ScrollDelta = (FixVector2)Input.mouseScrollDelta; mouseInput.Position = (FixVector3)Input.mousePosition; mouseInput.Delta = new FixVector2((Fix64)Input.GetAxis(InputParameters.MouseX), (Fix64)Input.GetAxis(InputParameters.MouseY)); LockstepUtility.AddInput(mouseInput); }