public void TestMultipleMessageTypes() { var messenger = new Messenger(); var recipient = new OldTestRecipient(); messenger.Register(recipient, typeof(OldTestMessage)); messenger.Register(recipient, typeof(GenericMessage<InvalidOperationException>)); messenger.Register(recipient, typeof(GenericMessage<MissingMethodException>)); Assert.IsNull(recipient.Content); Assert.IsNull(recipient.ObjectContent1); Assert.IsNull(recipient.ObjectContent2); var testObject1 = new InvalidOperationException(); var genericMessage = new GenericMessage<InvalidOperationException>(this, testObject1); messenger.Broadcast(genericMessage); Assert.AreEqual(this, recipient.Sender); Assert.IsNull(recipient.Content); Assert.AreEqual(testObject1, recipient.ObjectContent1); Assert.IsNull(recipient.ObjectContent2); var testObject2 = new MissingMethodException(); var genericMessage2 = new GenericMessage<MissingMethodException>(this, testObject2); messenger.Broadcast(genericMessage2); Assert.AreEqual(this, recipient.Sender); Assert.IsNull(recipient.Content); Assert.AreEqual(testObject1, recipient.ObjectContent1); Assert.AreEqual(testObject2, recipient.ObjectContent2); const string TestString = "Hello world"; var message = new OldTestMessage(this, TestString); messenger.Broadcast(message); Assert.AreEqual(this, recipient.Sender); Assert.AreEqual(TestString, recipient.Content); Assert.AreEqual(testObject1, recipient.ObjectContent1); Assert.AreEqual(testObject2, recipient.ObjectContent2); }
void SendErrorSound() { Messenger.Broadcast <string>(EventCode.PLAY_AUDIO, "NodeError"); }
// Update is called once per frame void Update() { if (gameStarted && !rexDefeated) { // If button was released this frame bool buttonReleased = false; // If button was pressed this frame bool buttonPressed = false; // Check to see if the player has traveled far enough to hit Mama Rex if (this.transform.localPosition.z > (startingPosition.z + carMaxDistanceZ)) { // Get other character z distance Vector3 otherCharacterDistance = otherPlayer.GetComponent <LRCarMovement>().getCarEndPosition(); float otherCharacterZDistance = otherCharacterDistance.z; // Hit rex tie breaker logic: // If other character is first player and their Z is >= this player's Z // 1. Apply penalty to player two // 2. Don't trigger event below if (playerNumber == 1 && (otherPlayer.transform.position.z >= this.transform.position.z)) { // Apply Z distance penalty to player two // This will prevent tie edge conditions on hit rex this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, (this.transform.position.z - hitTieBreakerPenalty)); } else { // Trigger hit rex event if (playerNumber == 0) { Messenger.Broadcast(GameEvent.P1_HIT_REX); } else { Messenger.Broadcast(GameEvent.P2_HIT_REX); } } } // Check to see if the player's key is down if (Input.GetButton(ButtonName)) { playerKeyDown = true; if (Input.GetButtonDown(ButtonName)) { buttonPressed = true; } } else { playerKeyDown = false; if (Input.GetButtonUp(ButtonName)) { buttonReleased = true; } } if (buttonPressed) { ButtonPressed(); } if (buttonReleased) { ButtonReleased(); } // Check whether Rex is currently in hit state. // If so, we won't want to move the car forward below. rexInHitState = rexBehavior.GetRexInHitState(); // If the player's key isn't down && not invincible && not in end sequence, move forward if (!playerKeyDown && !carInvinvincible && !rexDefeated && !rexInHitState) { // Update player's z value each second if not stopped newZ = this.transform.localPosition.z + (carSpeed * .1f * Time.deltaTime); // Set new position for car this.transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, newZ); } } }
public void KillGoblin(GoblinEntity goblin) { EntityManager.DestroyGoblin(goblin); Messenger.Broadcast("playGoblinDeath"); }
private void OnHideWeapon() { Messenger.Broadcast(GameEvent.WEAPON_ARE_HIDDEN); opportunityToShoot = false; }
// Effect - What the charm does. public override void Effect() { Debug.Log("Equipped " + type + "!"); marble.maxHP += 5; Messenger <int, int> .Broadcast("UpdateHealth", marble.health, marble.maxHP); }
// MESSAGING public virtual void broadcastCharacterMessage(GameAIDirectorData actor) { Messenger <GameAIDirectorData> .Broadcast(GameAIDirectorMessages.gameAIDirectorSpawnActor, actor); }
public void UpdateLabel() { Messenger.Broadcast(GameEvent.SCORE_INCREASED); }
//---------------------------------------------------------------------------- private void OnHideLoadingUIByType() { isInLoading = false; Messenger.Broadcast(DgMsgID.DgUI_HideUI, "UILoadingCtrl"); }
public void UseProp(GamePropsId propId) { Messenger.Broadcast(ConstValue.MSG_USE_PROP, propId); }
void OnTriggerEnter2D(Collider2D col) { Destroy(gameObject); Messenger.Broadcast(GameEvent.STONE_COLLECTED); }
private void OnTriggerEnter(Collider other) { Messenger.Broadcast(GameEvent.PLAYER_SPOTTED); }
public override void OnPointerExit(PointerEventData eventData) { Messenger <int> .Broadcast(MessageDefines.OnBlockPointExit, id); }
public override void OnPointerDown(PointerEventData eventData) { Debug.Log("OnPointerDown"); Messenger <int> .Broadcast(MessageDefines.OnBlockButtonDown, id); }
public void OnSpeedValue(float speed) { PlayerPrefs.SetFloat("speed", speed); Messenger <float> .Broadcast(GameEvent.SPEED_CHANGED, speed); }
public void BroadcastRecordingEvents(string code) { Messenger.Broadcast(code); BroadcastRecordingStatusChanged(code); }
public void ResetCell(Cell cell) { cell.Reset(); Messenger <Cell> .Broadcast(Cell.EVENT_CELL_UPDATED, cell); }
void Update() { if (canAttack) { if (isTracking) { Vector3 Direction = (transform.position - Target.transform.position).normalized; Vector3 targetPos = new Vector3(); if (Direction.x != 0) { targetPos = Target.transform.position + new Vector3(Mathf.Sign(Direction.x), 0, 0); } else if (Direction.y != 0) { targetPos = Target.transform.position + new Vector3(0, Mathf.Sign(Direction.y), 0); } //Vector3 appliedBuffer = Direction * hitRange; Vector3 Distance = targetPos - transform.position; Vector2 Velocity = new Vector3(); if (movementState == 1) { Velocity = Distance.normalized * chaseSpeed; } else if (movementState == 0) { Velocity = Distance.normalized * (chaseSpeed * 3 / 5); } if (Mathf.Abs(Distance.x) > 0.1f || Mathf.Abs(Distance.y) > 0.1f) { rbody.MovePosition(rbody.position + (Velocity * Time.deltaTime)); } } if (withinHitRange) { if (Cooldown <= 0) { StartCoroutine(throwPunch(attackDamage, 0.4f)); } else { Cooldown -= Time.deltaTime; } } } if (brawlTier == 1) { if (punchCombo == 1) { comboSpan += Time.deltaTime; } else if (punchCombo == 2) { if (comboSpan <= 0.9f) { Health -= playerDamage * 2.5f; Debug.Log("Combo"); } else { Health -= playerDamage * 2; } punchCombo = 0; Debug.Log(Health); if (Health <= 0) { StartCoroutine(deathRoutine()); } } } else if (brawlTier == 2) { if (punchCombo == 2) { if (attackTally < 2) { attackTally++; if (attackTally == 1) { Debug.Log("First attack received"); Messenger.Broadcast("firstAttack"); } } } } if (statusRef != null && brawlTier == 2) { if (statusRef.onFire && !local_onFire) { local_onFire = true; burnTimerOn = true; burnTime = 0; StartCoroutine(igniteBoss()); } if (burnTimerOn) { burnTime += Time.deltaTime; if (burnTime >= burnLimit) { Debug.Log("Enemy killed; burn limit reached"); burnTimerOn = false; Messenger <int> .Broadcast("finalEventType", 1); Destroy(gameObject); } } } }
public void KillCell(Cell cell) { cell.KillCell(); Messenger <Cell> .Broadcast(Cell.EVENT_CELL_UPDATED, cell); }
//NPC-SIDE QUEST-MANAGER INTERFACE PACKAGE: public void qPack_AI(string caller) { if (qStatus.onQuest == 0) { //SET TO ZERO AFTER COMPLETION qStatus.onQuest = 1; } if (caller == "qNPC_I") { Debug.Log("T"); if (qStatus.onQuest == 1) { if (qStatus.qPhase [0] == 0) { //Issue quest 1: qStatus.onQuest = 2; Messenger <int> .AddListener("contBtnRtrn", compileDecision); StartCoroutine(firstStage(wasSuccessful => { if (wasSuccessful != null) { Debug.Log("Returned to start"); success_stgI = wasSuccessful; if (success_stgI) { Debug.Log("Quest1 Successfully Completed"); qStatus.onQuest = 0; Messenger <int> .RemoveListener("contBtnRtrn", compileDecision); } } })); } } } else if (caller == "qNPC_II") { if (qStatus.onQuest == 1) { if (/*qStatus.qPhase [0] == 2 &&*/ qStatus.qPhase [1] == 0) { //Issue quest 2: //ADD MOVEMENT SCRIPT PARAMETER TO HALT MOVEMENT UPON ENGAGEMENT OF QUEST qStatus.onQuest = 2; Messenger <int> .AddListener("contBtnRtrn", compileDecision); Messenger <bool> .AddListener("LERtrn", LEGate); StartCoroutine(secondStage(wasSuccessful => { if (wasSuccessful != null) { Debug.Log("Returned to start"); success_stgII = wasSuccessful; if (success_stgII) { Debug.Log("Quest2 Successfully Completed"); qStatus.onQuest = 0; Messenger <int> .RemoveListener("contBtnRtrn", compileDecision); Messenger <bool> .RemoveListener("LERtrn", LEGate); } } })); } } } else if (caller == "qNPC_III") { if (qStatus.onQuest == 1) { if (/*qStatus.qPhase[1] == 2 &&*/ qStatus.qPhase [2] == 0) { qStatus.onQuest = 2; Messenger <int> .AddListener("contBtnRtrn", compileDecision); StartCoroutine(thirdStage(wasSuccessful => { if (wasSuccessful != null) { Debug.Log("Returned to start"); Messenger <bool, int> .Broadcast("MnPackAssignment", true, 0); Messenger <bool, int> .Broadcast("(un)lockCellar", true, 1); } })); } } } else if (caller == "qNPC_IV") { if (qStatus.onQuest == 1) { if (/*qStatus.qPhase[2] == 2 &&*/ qStatus.qPhase [3] == 0) { qStatus.onQuest = 2; StartCoroutine(fourthStage(wasSuccessful => { if (wasSuccessful != null) { Debug.Log("Returned to start"); } })); } } } else if (caller == "qNPC_Tester") { Debug.Log("Engaged Test NPC, NPC Inactive"); qStatus.onQuest = 2; Messenger <int> .AddListener("contBtnRtrn", compileDecision); //StartCoroutine (testerStage()); } }
void OnInputUp() { Messenger <InputState, int> .Broadcast(MessageDefines.OnPostSquareInput, InputState.OnInputUP, -1); }
/// <summary> /// Adds or removes points to the game for the player /// </summary> /// <param name="value"></param> public void OnPointsChange(int value) { currentPoints_ += value; Messenger <int> .Broadcast(UIMsg.SetPoints.ToString(), currentPoints_, MessengerMode.DONT_REQUIRE_LISTENER); }
void OnBlockButtonDown(int id) { isTouched = true; Messenger <InputState, int> .Broadcast(MessageDefines.OnPostSquareInput, InputState.OnBlockButtonDown, id); }
private void OnWeaponReady() { Messenger.Broadcast(GameEvent.WEAPON_READY); anim.SetBool("Hide", false); opportunityToShoot = true; }
public static void UpdateColors() { Messenger.Broadcast(UIColorsMessages.uiColorsUpdate); }
// Update is called once per frame public override void AIUpdate() { // loop through every goblin foreach (GoblinEntity goblinEntity in EntityManager.GetGoblins()) { var tile = goblinEntity.GetTile(); var location = goblinEntity.GetLocation(); var pickleLocation = Vector2.zero; // If we are currently on a path, keep traversing that path. if (_currentPath != null) { // Check to make sure the pickle is still there.. if (!PickleManager.IsPicklePresent(_currentPath.Last())) { _currentPath = null; } else { EntityManager.MoveEntityTo(goblinEntity, _currentPath[0]); _currentPath.RemoveAt(0); // If the path is empty, nuke it. if (_currentPath.Count == 0) { _currentPath = null; } } } else if (PickleManager.IsPicklePresent(location)) // Are we at a pickle? // Eat it! { PickleManager.EatPickleAtLocation(location); } else if (IsPickleNearby(location, PickleSightRange, out pickleLocation)) // Is there a pickle in range? // Find it! { _currentPath = new List <Vector2>(); _currentPath.AddRange(_pathfinder.Navigate(tile.Position, pickleLocation)); AIUpdate(); } else if (tile.CanSetOnFire()) // Can we set something on fire? // Set it on fire! { if (Random.Range(0F, 1F) < GoblinIgniteTilePercent) { if (Random.Range(0f, 1f) < GoblinSpeechPercent) { if (Random.Range(0f, 1f) < GoblinLaughPercentage) { Messenger.Broadcast("playRandomGoblinLaugh"); } else { Messenger.Broadcast("playRandomGoblinLyric"); } } FireManager.StartFire(tile.Position, FireStage.Kindling); } } else { // Move randomly looking for mischief var legalMoves = EntityManager.getLegalMoves(location); float countOfLegalMoves = (float)legalMoves.Count; int randomMove = Mathf.FloorToInt(Random.Range(0F, countOfLegalMoves)); EntityManager.MoveEntityTo(goblinEntity, legalMoves[randomMove]); } } }
public override void Finish() { base.Finish(); Messenger.Broadcast(MessengerConst.OnCutsceneEnd); }
//---------------------------------------------------------------------------- private void InitAndShowMainInterface() { Messenger.Broadcast(DgMsgID.DgUI_ShowNew, "UIMainInterfaceCtrl"); }
public void OnDrag(PointerEventData eventData) { GetComponent <RectTransform>().pivot.Set(0, 0); transform.position = Input.mousePosition; Messenger.Broadcast <Transform>("calender_pin_drag", transform); }
public void TestMultipleRecipientsWithObjects() { var messenger = new Messenger(); var recipient1 = new OldTestRecipient(); var recipient2 = new OldTestRecipient(); var recipient3 = new OldTestRecipient(); messenger.Register(recipient1, typeof(GenericMessage<InvalidOperationException>)); messenger.Register(recipient2, typeof(GenericMessage<InvalidOperationException>)); messenger.Register(recipient3, typeof(GenericMessage<InvalidOperationException>)); Assert.IsNull(recipient1.Sender); Assert.IsNull(recipient1.Content); Assert.IsNull(recipient2.Content); Assert.IsNull(recipient2.Sender); Assert.IsNull(recipient3.Content); Assert.IsNull(recipient3.Sender); var testContent = new InvalidOperationException(); var message = new GenericMessage<InvalidOperationException>(this, testContent); messenger.Broadcast(message); Assert.AreEqual(this, recipient1.Sender); Assert.AreEqual(testContent, recipient1.ObjectContent1); Assert.AreEqual(this, recipient2.Sender); Assert.AreEqual(testContent, recipient2.ObjectContent1); Assert.AreEqual(this, recipient3.Sender); Assert.AreEqual(testContent, recipient3.ObjectContent1); }
public void OnPointerUp(PointerEventData eventData) { transform.localScale = new Vector3(1f, 1f, 1f); Messenger.Broadcast <Transform>("calender_pin_down", transform); }
public void TestMultipleRecipients() { var messenger = new Messenger(); var recipient1 = new OldTestRecipient(); var recipient2 = new OldTestRecipient(); var recipient3 = new OldTestRecipient(); messenger.Register(recipient1, typeof(OldTestMessage)); messenger.Register(recipient2, typeof(OldTestMessage)); messenger.Register(recipient3, typeof(OldTestMessage)); Assert.IsNull(recipient1.Sender); Assert.IsNull(recipient1.Content); Assert.IsNull(recipient2.Content); Assert.IsNull(recipient2.Sender); Assert.IsNull(recipient3.Content); Assert.IsNull(recipient3.Sender); const string TestString = "Hello world"; var message = new OldTestMessage(this, TestString); messenger.Broadcast(message); Assert.AreEqual(TestString, recipient1.Content); Assert.AreEqual(this, recipient1.Sender); Assert.AreEqual(TestString, recipient2.Content); Assert.AreEqual(this, recipient2.Sender); Assert.AreEqual(TestString, recipient3.Content); Assert.AreEqual(this, recipient3.Sender); }
// MESSAGE STATE STATUS public void BroadcastRecordingStatusChanged(string status) { Messenger <string> .Broadcast(BroadcastNetworksMessages.broadcastRecordingStatusChanged, status); }