Skip to content

Commit

Permalink
Merge branch 'master' into empty-scene-server-crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 authored Jan 13, 2024
2 parents 074caf3 + 2b685e3 commit 91d0152
Show file tree
Hide file tree
Showing 4 changed files with 519 additions and 678 deletions.
50 changes: 33 additions & 17 deletions HKMP/Animation/Effects/HazardDeath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,36 @@ public override void Play(GameObject playerObject, bool[] effectInfo) {
// Destroy it after some time
Object.Destroy(spikeDeath, FadeOutDuration);
} else if (hazardWasAcid) {
// Spawn the acid death object relative to the player object
var acidDeathPrefab = HeroController.instance.acidDeathPrefab;
var acidDeath = acidDeathPrefab.Spawn(playerObject.transform.position);

var acidDeathFsm = acidDeath.LocateMyFSM("Knight Acid Death");

// Get the audio play action and change the spawn point of the audio to be the player object
var damagePlayAction = acidDeathFsm.GetAction<AudioPlayerOneShot>("Effects", 2);
damagePlayAction.spawnPoint.Value = playerObject;
// There is another one that plays the splash sound, also change the spawn point
var splashPlayAction = acidDeathFsm.GetAction<AudioPlayerOneShot>("Effects", 3);
// Also change the audio player, otherwise the sound will play at the local player
splashPlayAction.audioPlayer = damagePlayAction.audioPlayer;
splashPlayAction.spawnPoint.Value = playerObject;

// Remove the screen shake effect
acidDeathFsm.GetAction<SendEventByName>("Effects", 5).sendEvent.Value = "";

// Spawn the acid death object relative to the player object
var acidDeath = Object.Instantiate(
acidDeathPrefab,
playerObject.transform.position,
Quaternion.identity
);
var fsm = acidDeath.GetComponent<PlayMakerFSM>();

// Obtain the audio actions for the hero damage and acid splash sounds
var heroDmgAudioAction = fsm.GetAction<AudioPlayerOneShot>("Effects", 2);
var heroDmgClip = heroDmgAudioAction.audioClips[0];
var acidSplashAudioAction = fsm.GetAction<AudioPlayerOneShot>("Effects", 3);
var acidSplashClip = acidSplashAudioAction.audioClips[0];

// Get an audio source to play the sounds at the location of the remote player
var audioObj = AudioUtil.GetAudioSourceObject(playerObject);
var audioSource = audioObj.GetComponent<AudioSource>();
audioSource.PlayOneShot(heroDmgClip);
audioSource.PlayOneShot(acidSplashClip);

Object.Destroy(audioObj, acidSplashClip.length);

// Remove the actions with indices 1 through 5
// Each removal shuffles the actions down an index so we call the remove method with 1 each time
for (var i = 0; i < 5; i++) {
fsm.RemoveAction("Effects", 1);
}

// Start a coroutine to fade out the spike death object
MonoBehaviourUtil.Instance.StartCoroutine(FadeObjectOut(
acidDeath.GetComponent<MeshRenderer>(),
Expand Down Expand Up @@ -104,7 +116,11 @@ private IEnumerator FadeObjectOut(Renderer renderer, float duration) {
for (var t = 0f; t < duration; t += Time.deltaTime) {
var normalizedTime = t / duration;
var alpha = 1f - normalizedTime;


if (renderer == null || renderer.material == null) {
yield break;
}

var material = renderer.material;
var color = material.color;
material.color = new Color(color.r, color.g, color.b, alpha);
Expand Down
22 changes: 22 additions & 0 deletions HKMP/Util/FsmUtilExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ public static void InsertAction(PlayMakerFSM fsm, string stateName, FsmStateActi
public static void InsertMethod(this PlayMakerFSM fsm, string stateName, int index, Action method) {
InsertAction(fsm, stateName, new InvokeMethod(method), index);
}

/// <summary>
/// Removes an action from a specific state in a FSM.
/// </summary>
/// <param name="fsm">The FSM.</param>
/// <param name="stateName">The name of the state with the action to remove.</param>
/// <param name="index">The index of the action within the state.</param>
public static void RemoveAction(this PlayMakerFSM fsm, string stateName, int index) {
var state = fsm.GetState(stateName);

var origActions = state.Actions;
var actions = new FsmStateAction[origActions.Length - 1];
for (var i = 0; i < index; i++) {
actions[i] = origActions[i];
}

for (var i = index; i < actions.Length; i++) {
actions[i] = origActions[i + 1];
}

state.Actions = actions;
}
}

/// <summary>
Expand Down
Loading

0 comments on commit 91d0152

Please sign in to comment.