OnSchemeEnded: Difference between revisions
Tayfunwiki (talk | contribs) (Created page with "== <code>onSchemeEnded</code> Event in Actor Class == === Overview === The <code>onSchemeEnded</code> event is a critical component of the <code>Actor</code> class, triggered upon the conclusion of a scheme. It's instrumental in games where the outcomes of schemes drive narrative developments, character interactions, or gameplay changes. === Description of <code>SchemeResult</code> Enum === * Enum Type: <code>SchemeResult</code> * Values: ** <code>None</code>: Indicat...") |
Tayfunwiki (talk | contribs) No edit summary |
||
Line 8: | Line 8: | ||
* Enum Type: <code>SchemeResult</code> | * Enum Type: <code>SchemeResult</code> | ||
* Values: | * Values: | ||
** <code>None</code>: Indicates no specific result | ** <code>None</code>: Indicates no specific result. | ||
** <code>Success</code>: Represents a successful completion of the scheme. | ** <code>Success</code>: Represents a successful completion of the scheme. | ||
** <code>Failed</code>: Signifies that the scheme did not achieve its intended outcome. | ** <code>Failed</code>: Signifies that the scheme did not achieve its intended outcome. |
Latest revision as of 14:41, 24 December 2023
onSchemeEnded
Event in Actor Class
Overview
The onSchemeEnded
event is a critical component of the Actor
class, triggered upon the conclusion of a scheme. It's instrumental in games where the outcomes of schemes drive narrative developments, character interactions, or gameplay changes.
Description of SchemeResult
Enum
- Enum Type:
SchemeResult
- Values:
None
: Indicates no specific result.Success
: Represents a successful completion of the scheme.Failed
: Signifies that the scheme did not achieve its intended outcome.
Description of onSchemeEnded
Event
- Event Type:
Action<Scheme, SchemeResult>
- Functionality: Activates when a scheme involving the actor ends, providing insights into both the scheme and its outcome. The event handler receives the scheme that ended and its result as defined by the
SchemeResult
enum. This setup allows for tailored reactions based on the nature and success or failure of the scheme.
Usage
The event is used to trigger specific actions or logic in response to the conclusion of schemes, such as updating game states, adjusting character statuses, or advancing the storyline based on the scheme's result.
Subscribing to the Event
Subscribe to the onSchemeEnded
event within a MonoBehaviour script to handle the end of schemes. Ensure to unsubscribe from the event appropriately to maintain optimal performance and prevent memory leaks.
Example of Usage
public class SchemeOutcomeHandler : MonoBehaviour {
public Actor actor;
void Start() {
if (actor != null) {
actor.onSchemeEnded += OnSchemeEnded;
}
}
private void OnSchemeEnded(Scheme scheme, SchemeResult result) {
Debug.Log($"Scheme {scheme.SchemeName} ended with result: {result}");
// Custom logic based on the scheme's outcome
}
void OnDestroy() {
if (actor != null) {
actor.onSchemeEnded -= OnSchemeEnded;
}
}
}
In this Unity script example, the SchemeOutcomeHandler
is attached to a GameObject and listens for the onSchemeEnded
event from an Actor
. When a scheme ends, it triggers the OnSchemeEnded
method, allowing for responses tailored to the specific outcome of the scheme.
Remarks
- The
onSchemeEnded
event withSchemeResult
allows for nuanced and strategic gameplay, enhancing player engagement through responsive and outcome-based scenarios. - Understanding and utilizing the different outcomes in
SchemeResult
is key to creating a dynamic and interactive game environment. - This event is particularly crucial in narrative-rich and strategy-focused games where the consequences of player actions significantly impact the game's progression.