Adventure Creator Wikia
Advertisement

This page covers how to integrate AC with Animal Controller https://assetstore.unity.com/packages/tools/animation/animal-controller-148877

  • If using Cinemachine, attach AC's Basic Camera to the CM Brain GameObject, set its Tag to Untagged, and remove the Audio Listener component
  • Use the Scene Manager to convert the scene into an AC scene, and assign the CM Brain as the scene's Default camera
  • Attach AC's Player component to your Animal Controller Player character, setting the Animation engine to Custom, and Motion control to Manual
  • For any NPC you wish AC to control, attach the NPC component and make the same field changes as above
  • Copy/paste the script below into a new C# file named AnimalControllerIntegration
  • Attach the Animal Controller Integration component to your character, and assign the fields in its Inspector
  • The Point Click field is only necessary if you wish to use Animal Controller's Point And Click movement
  • If the AI object is disabled, enable it and assign the AI Control component in the Inspector - this will be disabled automatically by the integration
  • At runtime, the integration script will now prevent input during cutscenes, and have the character respond to AC movement commands

AnimalControllerIntegration.cs:

using UnityEngine;
using MalbersAnimations.Controller.AI;
using MalbersAnimations;

namespace AC
{

	public class AnimalControllerIntegration : MonoBehaviour
	{

		#region Variables

		[SerializeField] private Char acCharacter = null;
		[SerializeField] private MInput mInput = null;
		[SerializeField] private MAnimalAIControl aiControl = null;
		[SerializeField] private PointClick pointClick = null;

		#endregion


		#region UnityStandards

		private void OnValidate ()
		{
			if (acCharacter == null) acCharacter = GetComponent<Char> ();
			if (mInput == null) mInput = GetComponent<MInput> ();
			if (aiControl == null) aiControl = GetComponentInChildren<MAnimalAIControl> ();
			if (pointClick == null) pointClick = GetComponentInChildren<PointClick> ();
		}


		private void OnEnable ()
		{
			EventManager.OnEnterGameState += OnEnterGameState;
			EventManager.OnCharacterSetPath += OnCharacterSetPath;
		}


		private void OnDisable ()
		{
			EventManager.OnEnterGameState -= OnEnterGameState;
			EventManager.OnCharacterSetPath -= OnCharacterSetPath;
		}


		private void Update ()
		{
			if (aiControl && aiControl.DestinationPosition == aiControl.NullVector)
			{
				acCharacter.EndPath ();
			}
		}

		#endregion


		#region CustomEvents

		private void OnEnterGameState (GameState gameState)
		{
			bool allowInput = acCharacter.IsActivePlayer () && gameState == GameState.Normal;
			if (mInput) mInput.SetEnable (allowInput);
			if (pointClick) pointClick.SetEnable (allowInput);
			if (aiControl) aiControl.SetEnable (!allowInput);
		}


		private void OnCharacterSetPath (Char character, Paths path)
		{
			if (aiControl && character == acCharacter)
			{
				aiControl.SetDestinationClearTarget (path.Destination);
			}
		}

		#endregion

	}

}
Advertisement