public static TurnManagerAttentionMessageData SendMessage(GameObject gameObject) { var data = new TurnManagerAttentionMessageData(); gameObject.SendMessage(MessageName, data, SendMessageOptions.RequireReceiver); return(data); }
private IEnumerator FinishTurnSequence() { // Wait till short-living projectiles and other temporary objects settle down. yield return(StartCoroutine(WaitForTransientObjects())); /* Cycle through all objects requiring attention (e.g. dying characters). * Let them perform some actions (e.g. dying animation) one by one. */ GameObject rockstar; var rockstarPos = Vector2.zero; float dramaStartTimestamp = Time.fixedTime; bool patienceHasEnded = false; while (TryGetClosestAttentionSeeker(rockstarPos, out rockstar)) { rockstarPos = rockstar.transform.position; // Watch delightful performance provided by rockstar. var messageData = TurnManagerAttentionMessageData.SendMessage(rockstar); if (!patienceHasEnded) { // Let camera fetch information abount currently attended object. AttentionTarget = rockstar; // Wait until it ends. do { float dramaTimeElapsed = Time.fixedTime - dramaStartTimestamp; patienceHasEnded = dramaTimeElapsed >= MaxDramaDuration; if (patienceHasEnded || messageData.PerformanceIsOver) { break; } yield return(this.WaitForFixedSeconds(0.25f)); } while (rockstar != null); // Object could be destroyed. AttentionTarget = null; } attentionSeekers.Remove(rockstar); } TransferControlToNextPlayer(); finishTurnSequencePlaying = false; }
private void ProcessDeadState() { // Respond to turn manager if it's waiting. if (turnManagerAttentionData != null) { TurnManager.Singleton.InvokeFixed(() => { turnManagerAttentionData.PerformanceIsOver = true; turnManagerAttentionData = null; }, WaitSettings.DeadStateExtraTime); } var owner = OwningPlayer; GameObject headstonePrefab = null; if (owner != null) { headstonePrefab = owner.HeadstonePrefab; } if (headstonePrefab != null) { var headstone = Instantiate(headstonePrefab, transform.position, Quaternion.identity) as GameObject; headstone.transform.parent = transform.parent; headstone.name += " of " + this.name; var body = headstone.rigidbody2D; if (body != null) { /* Inherit character velocity. * This is essential since character could stand on moving platform. */ body.velocity = rigidbody2D.velocity; body.AddForce(Vector2.up * HeadstoneThrowUpVelocity, ForceMode.VelocityChange); } /* Make this game object to be child of headstone. * Character will be placed at the position of its headstone * if it's happen to be resurrected. */ transform.parent = headstone.transform; } }
IEnumerator OnTurnManagerAttention(TurnManagerAttentionMessageData data) { var healthComp = HealthComponent; bool playClosingSpeech = false; turnManagerAttentionData = data; if (healthComp.HasPendingChanges) { // Give camera some time to focus on attended object. yield return(new WaitForSeconds(WaitSettings.TimeBeforeResumingHealthChanges)); healthComp.ResumeChanges(); // Wait for end of changes. yield return(new WaitForSeconds(WaitSettings.HealthChangesWaitTime)); if (healthComp.Health <= 0) { Die(); } else { playClosingSpeech = true; } } else { if (healthComp.Health <= 0) { Die(); } else { playClosingSpeech = true; } } if (playClosingSpeech) { // Play closing speech only for currently turning unit. if (TurnManager.Singleton.CurrentUnit == this.PlayerOwnedObject) { /* Play closing speech animation. * Specific speech and animation can be played * depending on results of the turn: good shot * can be concluded with "Hell yeah!" emotion, * whereas shot that hurts teammate will be * ended up with guilty look. */ switchIntoIdleState = true; idleActionStateName = AnimatorNames.ClosingSpeech; idleActionCameraEvent = CameraEvents.ClosingSpeech; /* Wait some time for character to be grounded and not moving * relative to the platform it's standing on. */ yield return(WaitTillStandingStill()); // Give CharacterMovement some time to initiate idle action. yield return(new WaitForSeconds(WaitSettings.TimeToInitiateIdleAction)); yield return(this.WaitForCondition( () => !animator.InState(idleActionStateName), WaitSettings.MaxIdleActionDuration )); idleActionStateName = null; idleActionCameraEvent = null; playingIdleState = false; // Character could die during the speech. if (healthComp.Health <= 0) { Die(); } else { data.PerformanceIsOver = true; } } else { data.PerformanceIsOver = true; } } }