Adventure Creator Wikia
Advertisement

The following is AC's legacy FaceFX integration, condensed into a single standalong script.

To use it:

  1. Create a new C# script named FaceFXIntegration, and copy/paste the code below
  2. Attach the script to your AC character, and assign the character in the component's "Speaker" field
  3. Also attach the Face FX base component to the character's hierarchy
  4. Gather your speech text in the Speech Manager
  5. When the character speaks, it will attempt to play a FaceFX file of the format "Default_Speaker_LineID", where Speaker is the name of the character, and LineID is the ID number of the line, as listed in the Speech Manager.
using UnityEngine;
using AC;

public class FaceFXIntegration : MonoBehaviour
{

	#region Variables

	[SerializeField] private AC.Char speaker = null;

	#endregion


	#region UnityStandards

	private void OnEnable ()
	{
		EventManager.OnStartSpeech_Alt += OnStartSpeech;
		EventManager.OnStopSpeech_Alt += OnStopSpeech;
	}


	private void OnDisable ()
	{
		EventManager.OnStartSpeech_Alt -= OnStartSpeech;
		EventManager.OnStopSpeech_Alt -= OnStopSpeech;
	}

	#endregion


	#region CustomEvents

	private void OnStartSpeech (Speech speech)
	{
		if (speech.GetSpeakingCharacter () == speaker)
		{
			FaceFXControllerScript_Base faceFXController = speaker.GetComponentInChildren<FaceFXControllerScript_Base> ();
			if (speaker.speechAudioSource && speaker.speechAudioSource.clip && faceFXController)
			{
				speaker.isLipSyncing = true;
				speech.hasAudio = true;
				faceFXController.PlayAnim ("Default_" + speech.log.speakerName + speech.log.lineID, speaker.speechAudioSource.clip);
			}
		}
	}


	private void OnStopSpeech (Speech speech)
	{
		if (speech.GetSpeakingCharacter () == speaker && faceFXController)
		{
			FaceFXControllerScript_Base faceFXController = speaker.GetComponentInChildren<FaceFXControllerScript_Base> ();
			if (faceFXController)
			{
				faceFXController.StopAnim ();
			}
		}
	}

	#endregion

}
Advertisement