public void Start() { _datastore = GetComponent <Datastore>(); Observable.EveryUpdate() .Where(_ => { var checkedKeys = watchedKeys.Where(keyCode => Input.GetKeyDown(keyCode)).ToList(); if (checkedKeys.Count > 0) { pressedKeys = checkedKeys; return(true); } return(false); }) .Subscribe(_ => { pressedKeys.ForEach(keyCode => { _datastore.inputEvents.Publish( new KeyEvent() { keyCode = keyCode, heldKeys = heldKeys, }); }); }); Observable.EveryUpdate() .Where(_ => { var pressedDownKeys = watchedHeldKeys .Where(keyCode => Input.GetKeyDown(keyCode)) .Select(key => condensedHeldKeys[key]) .Distinct().ToList(); var liftedUpKeys = watchedHeldKeys .Where(keyCode => Input.GetKeyUp(keyCode)) .Select(key => condensedHeldKeys[key]) .Distinct().ToList(); if (pressedDownKeys.Count > 0 || liftedUpKeys.Count > 0) { var condensedKeys = heldKeys.Except(liftedUpKeys).Concat(pressedDownKeys).ToList(); if (heldKeys != condensedKeys) { heldKeys = condensedKeys; return(true); } } return(false); }) .Subscribe(_ => { _datastore.inputEvents.Publish( new KeyEvent() { heldKeys = heldKeys, } ); }); }
public void Start() { _prefabs = GetComponent <Prefabs>(); _datastore = GetComponent <Datastore>(); _datastore.inputEvents.Receive <KeyEvent>() .Where(e => e.keyCode == KeyCode.R || e.keyCode == KeyCode.E) .Subscribe(e => { if (e.keyCode == KeyCode.R) { _datastore.leftFormation.RotateClockwise(); } else { _datastore.leftFormation.RotateCounterClockwise(); } _datastore.battlefieldEvents.Publish(new RotateFormationEvent { formation = _datastore.leftFormation }); UpdateMonPositions(); }); battlefield = GameObject.Find("Battlefield"); spawnArea = battlefield.transform.Find("SpawnArea").gameObject; _datastore.leftFormation = new BattleFormation(); InstantiateFormation(_prefabs.duoFormation, FormationTypes.DuoFormation); _datastore.leftFormation.type.AsObservable().Subscribe(newType => { if (newType == FormationTypes.DuoFormation) { InstantiateFormation(_prefabs.duoFormation, newType); } else if (newType == FormationTypes.TrioFormation) { InstantiateFormation(_prefabs.trioFormation, newType); } else if (newType == FormationTypes.QuartetFormation) { InstantiateFormation(_prefabs.quartetFormation, newType); } else if (newType == FormationTypes.QuintetFormation) { InstantiateFormation(_prefabs.quintetFormation, newType); } }); _datastore.rightFormation = new BattleFormation(); MockInstantiateOpposingFormation(_prefabs.trioFormation, FormationTypes.TrioFormation); MockStartBattle(); }