/// <summary> /// This function increases the variable that keeps track of how many buildings are build. /// </summary> /// <param name="building">Takes in the building type of which building the amount has been increased.</param> public static void IncreaseAmountBuilding(BuildingTypes building) { BuildingType actualBuilding = BuildingType.none; if (building == BuildingTypes.Bakery) { actualBuilding = BuildingType.bakery; } else if (building.ToString().Contains("House")) { actualBuilding = BuildingType.house; } else { actualBuilding = BuildingType.none; } switch (actualBuilding) { case BuildingType.bakery: TotalAmountBakery++; ResourceManager.CalculateNewResourceAmount(ResourceType.bread); break; case BuildingType.house: TotalAmountHouses++; ResourceManager.CalculateNewResourceAmount(ResourceType.villagers); OnHouseBuild?.Invoke(); break; case BuildingType.none: break; } }
IEnumerator StepCoroutine() { yield return(disappearTimer); onDisappear?.Invoke(); disappear = true; yield return(reappearTimer); onReappear?.Invoke(); disappear = false; isDisappearing = false; }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Player")) { _onLevelEnd.Invoke(); } }
public override void Fadein() { gameObject.SetActive(true); targets[activeId].Fadein(); onFadein?.Invoke(); active = true; }
public static void Run() { Console.WriteLine("Setup observable"); // To consume SimpleEvent as an IObservable: var eventAsObservable = Observable.FromEventPattern <EventArgs>( ev => SimpleEvent += ev, ev => SimpleEvent -= ev); // SimpleEvent is null until we subscribe Console.WriteLine(SimpleEvent == null ? "SimpleEvent == null" : "SimpleEvent != null"); Console.WriteLine("Subscribe"); //Create two event subscribers var s = eventAsObservable.Subscribe(args => Console.WriteLine("Received event for s subscriber")); var t = eventAsObservable.Subscribe(args => Console.WriteLine("Received event for t subscriber")); // After subscribing the event handler has been added Console.WriteLine(SimpleEvent == null ? "SimpleEvent == null" : "SimpleEvent != null"); Console.WriteLine("Raise event"); SimpleEvent?.Invoke(null, EventArgs.Empty); // Allow some time before unsubscribing or event may not happen Thread.Sleep(100); Console.WriteLine("Unsubscribe"); s.Dispose(); t.Dispose(); // After unsubscribing the event handler has been removed Console.WriteLine(SimpleEvent == null ? "SimpleEvent == null" : "SimpleEvent != null"); }
protected override void OnUI() { if (GUILayout.Button(buttonText)) { output?.Invoke(); } }
void OnPendingLoadScene() { if (SceneSystem.SceneToLoad == sceneToLoad) { onPendingLoadScene?.Invoke(); } }
public async void Fill(string[] turnOrder, SimpleEvent callback = null) { Image image; AsyncOperationHandle <GameObject> goHandler; AsyncOperationHandle <Sprite> spriteHandler; int portraitIndex; for (int i = 0; i < turnOrder.Length; i++) { portraitIndex = GameManager.Instance.Players.Find(x => x.id == turnOrder[i]).avatar; spriteHandler = Addressables.LoadAssetAsync <Sprite>($"portrait{portraitIndex}"); goHandler = Addressables.InstantiateAsync("playerPortrait", _transform); Task[] tasks = new Task[2] { goHandler.Task, spriteHandler.Task }; await Task.WhenAll(tasks); image = goHandler.Result.GetComponent <Image>(); image.sprite = spriteHandler.Result; playersImages.Add(image); } hideAvatars(); DOTween.To(() => activeImage.transform.localScale, x => activeImage.transform.localScale = x, new Vector3(1.2f, 1.2f, 1), 0.5f) .SetLoops(-1, LoopType.Yoyo).SetEase(Ease.InOutSine).SetId("playerTurn").Pause(); callback?.Invoke(); }
private void Update() { if (_currentFadeTime != -1 && _targetAlpha == 1) { FadingIn(); } if (_currentFadeTime != -1 && _targetAlpha == 0) { FadingOut(); } if (_textComponent.color.a >= 1 && _imageComponent.color.a >= 1 && _lifetime != -1) { DecreaseLifetime(); } if (_textComponent.color.a <= 0 && _imageComponent.color.a <= 0 && _lifetime == -1 && finishDelay > 0) { DecreaseFinishDelay(); } else if (finishDelay <= 0) { OnFinish?.Invoke(); Destroy(gameObject); } if (_lifetime <= 0 && _lifetime != -1) { FadeOut(); _lifetime = -1; } }
private void FadingIn() { Color newTextColor = _textComponent.color; Color newImageColor = _imageComponent.color; Color newCharacterImageColor = _characterImageComponent.color; _currentFadeTime += Time.deltaTime / _fadeTime; newTextColor.a = Mathf.Lerp(_startAlpha, _targetAlpha, _currentFadeTime); newImageColor.a = Mathf.Lerp(_startAlpha, _targetAlpha, _currentFadeTime); newCharacterImageColor.a = Mathf.Lerp(_startAlpha, _targetAlpha, _currentFadeTime); if (_textComponent.color.a >= 1 && _imageComponent.color.a >= 1 && _characterImageComponent.color.a >= 1) { newTextColor.a = 1; newImageColor.a = 1; newCharacterImageColor.a = 1; _currentFadeTime = -1; _targetAlpha = -1; OnFullyVisible?.Invoke(); } _textComponent.color = newTextColor; _imageComponent.color = newImageColor; _characterImageComponent.color = newCharacterImageColor; }
private void GetMeshes() { var _noPlayerSkins = PlayerPrefs.GetInt("PlayerAvalibleSkins"); for (var i = 0; i < _noPlayerSkins; i++) { var _skinIndex = PlayerPrefs.GetInt("PlayerAvalibleSkin" + i); if (!_playerMeshes.Contains(_skinIndex)) { ; } _playerMeshes.Add(_skinIndex); } if (_playerMeshes.Count == 0) { _playerMeshes.Add(0); } var restoredCurrentMesh = PlayerPrefs.GetInt("PlayerCurrentSkin"); if (_availableMeshes.meshes[restoredCurrentMesh] != null) { _currentMesh.Value = _availableMeshes.meshes[restoredCurrentMesh].id; } else { _currentMesh.Value = 0; } _onPlayerDataLoad.Invoke(); onSystemInitialized.Invoke(); Debug.Log("Player data restored"); }
private void CheckGameOver() { if (_scaleFactor < 0.1f) { _onGameOver.Invoke(); } }
public void StartGame() { _gameTopSection.DOAnchorPos(Vector2.zero, 0.25f); _menu.DOAnchorPos(new Vector2(-1300, 0), 0.25f); _touchArea.SetActive(true); UpdateStep(); _onGameStart.Invoke(); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject == GameManager.Singleton.pc.gameObject) { GameManager.Singleton.pc.bornPos = transform.position; OnActive?.Invoke(); } }
public override void Fadeout() { foreach (var f in targets) { f.Fadeout(); } active = false; onFadeout?.Invoke(); }
public void Run() { while (!HaultToken) { count += 1; Console.WriteLine($"Invoke {count}"); SimpleEvent?.Invoke(this, new EventArgs()); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject == GameManager.Singleton.pc.gameObject) { GameManager.Singleton.pc.SaveData(sceneIndex); OnChangeScene?.Invoke(); StartCoroutine(LoadAsyncScreen()); } }
//更改内容 IEnumerator ChangeDialog() { state = BubbleState.waiting; yield return(new WaitForSeconds(Random.Range(minDialogInterval, maxDialogInterval))); targetString = data.contents[Random.Range(0, data.contents.Count)].dialogText; state = BubbleState.typing; OnShow?.Invoke(); }
//Input public void StepForward(float input) { stepper += input; while (stepper > stepThreadhold) { stepper -= stepThreadhold; output?.Invoke(); } }
private void ArrestEnemies(int noEnemies) { if (noEnemies == _platforms.Sum((e) => e.NoActiveEnemies)) { print("Do confetti effect!" + noEnemies); _onLevelSuccess.Invoke(); _policeman.SetActive(true); Camera.main.transform.DOMove(_policeman.transform.position - new Vector3(0, -2, 5), 0.5f); } }
public override void Fadein() { gameObject.SetActive(true); foreach (var f in targets) { f.Fadein(); } active = true; onFadein?.Invoke(); }
private void UpdateCurrentPlaltform() { _currentPlatformIndex = _platforms.Count(e => e.NoActiveEnemies == e.GetNoEnemies); _levelProgress.Value = (float)_currentPlatformIndex / _platforms.Count; _onPlatformEnd.Invoke(_currentPlatformIndex); if (_currentPlatformIndex == _platforms.Count) { _onPlatformEnd.Invoke(++_currentPlatformIndex); _onLevelEnd.Invoke(); } }
// // Define the event method protected virtual void OnSimpleEventA(int dataInt, CustomData dataCus) { // // Only in invoke if a lister is attached ie the delegate is not null SimpleEvent?.Invoke(dataInt, dataCus); Console.Write("Running Event A : {0} : {1} {2}", dataInt, dataCus.CustomDataInt, Environment.NewLine); OnSimpleEventExplicit(dataInt, dataCus); }
void Awake() { NetworkSystem.OnConnection += () => OnConnection?.Invoke(); NetworkSystem.OnDisconnection += () => OnDisconnection?.Invoke(); NetworkSystem.OnServerConnection += c => OnServerConnection?.Invoke(); NetworkSystem.OnServerDisconnection += c => OnServerDisconnection?.Invoke(); NetworkSystem.OnUDPReceive += val => OnUDPReceive?.Invoke(val.message); NetworkSystem.OnUDPProcess += val => OnUDPProcess?.Invoke(val.message); NetworkSystem.OnReceive += val => OnReceive?.Invoke(val); NetworkSystem.OnProcess += (val, c) => OnProcess?.Invoke(val); }
public void RestartButtonPressed() { _currentStep.Value = 0; _totalSteps.Value = 10; _currentLevel.Value = 1; _nextLevel.Value = 2; _onGameRestartEvent.Invoke(); _reward.SetActive(false); HideLevelEnd(); ShowMenu(); }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Player")) { for (int i = 0; i < _enemies.Count; i++) { _enemies[i].CanBeAttacked = true; } _onPlayerAttackBegin.Invoke(); } }
private void CheckIfEnemyHarmful(Enemy enemy) { if (enemy.IsHarmful) { Debug.Log("Enemy was harmful. Congrats!"); } else { _onWrongTarget.Invoke(); Debug.Log("Enemy was not harmful. Head will scale down!"); } }
public void Close(float closeTime = 0) { OnClose?.Invoke(); if (closeTime != 0) { StartCoroutine(ClosePanel(closeTime)); } else { gameObject.SetActive(false); } }
//Input public void Invoke(float val) { if (value < threadhold && val >= threadhold) { onOverThreadhold?.Invoke(); } if (value < threadhold && val <= threadhold) { onBelowThreadhold?.Invoke(); } value = val; }
// Update is called once per frame void Update() { if (state == BubbleState.off) { StartCoroutine(ChangeDialog()); } if (state == BubbleState.typing) { UpdateContentString(); } if (state == BubbleState.show) { dialogTimer += Time.deltaTime; if (dialogTimer >= dialogTime) { dialogTimer = 0; state = BubbleState.off; OnOff?.Invoke(); } } }