FinalIK Interactions Integration (AC Action)

Note: This AC action is meant to allow the usage of the "Interaction" features in FinalIK through AC's visual scripting. To use it replace the text in a .cs file named FinalIK\_RunInteraction with this text, or create a new blank text file, then paste the text and rename the file FinalIK\_RunInteraction.cs. Then drop the file into the folder named actions inside the Adventure creator folder.

> In Unity, put the Fully Biped IK and Interaction System scripts on the character, then you are good to go. Go to Custom : Final IK : Run interaction and put the object in the action. And in the object the right affector.
>
>

This is the code:

```
using UnityEngine;

using System.Collections;

using System.Collections.Generic;

using RootMotion.FinalIK;

#if UNITY_EDITOR

using UnityEditor;

#endif

 namespace AC

 {

 	[System.Serializable]

 	public class FinalIK_RunInteraction : Action

 	{

 		public bool isPlayer;

 		public InteractionSystem interactionSystem;

		public int interactionSystemConstantID = 0;

		public int interactionSystemParameterID = -1;

		public InteractionObject interactionObject;

		public int interactionObjectConstantID = 0;

		public int interactionObjectParameterID = -1;

 		public FullBodyBipedEffector effector;

 		public bool canInterrupt;

 		public FinalIK_RunInteraction ()

 		{

 			this.isDisplayed = true;

 			category = ActionCategory.Custom;

 			title = "Final IK - Run interaction";

 			description = "Starts an interaction using the Final IK Interaction System";

 			isPlayer = true;

 			canInterrupt = true;

 		}

		override public void AssignValues (List<ActionParameter> parameters)

		{

			if (!isPlayer)

				interactionSystem = AssignFile <InteractionSystem> (parameters, interactionSystemParameterID, interactionSystemConstantID, interactionSystem);

			interactionObject = AssignFile <InteractionObject> (parameters, interactionObjectParameterID, interactionObjectConstantID, interactionObject);

		}

 		override public float Run ()

 		{

 			if (isPlayer)

 			{

 				interactionSystem = KickStarter.player.GetComponent<InteractionSystem>();

 				if (interactionSystem == null)

 				{

 					Debug.LogWarning("FinalIK_RunInteraction: No InteractionSystem found on Player.");

 					return 0f;

 				}

 			}

 			else if (interactionSystem == null)

 			{

 				Debug.LogWarning("FinalIK_RunInteraction: No InteractionSystem defined.");

 				return 0f;

 			}

 			if (interactionObject == null)

 			{

 				Debug.LogWarning("FinalIK_RunInteraction: No InteractionObject defined.");

 				return 0f;

 			}

 			interactionSystem.StartInteraction(effector, interactionObject, canInterrupt);

 			return 0f;

 		}

 		override public void Skip()

 		{}

 		#if UNITY_EDITOR

		override public void ShowGUI (List<ActionParameter> parameters)

 		{

 			isPlayer = EditorGUILayout.Toggle ("Is player?", isPlayer);

 			if (!isPlayer)

 			{

				interactionSystemParameterID = Action.ChooseParameterGUI ("Character:", parameters, interactionSystemParameterID, ParameterType.GameObject);

				if (interactionSystemParameterID >= 0)

				{

					interactionSystemConstantID = 0;

					interactionSystem = null;

				}

				else

				{

					interactionSystem = (InteractionSystem) EditorGUILayout.ObjectField ("Character:", interactionSystem, typeof(InteractionSystem), true);

					interactionSystemConstantID = FieldToID (interactionSystem, interactionSystemConstantID);

					interactionSystem = IDToField (interactionSystem, interactionSystemConstantID, false);

				}

 			}

 			effector = (FullBodyBipedEffector)EditorGUILayout.EnumPopup ("Effector:", effector);

			interactionObjectParameterID = Action.ChooseParameterGUI ("Interaction object:", parameters, interactionObjectParameterID, ParameterType.GameObject);

			if (interactionObjectParameterID >= 0)

			{

				interactionObjectConstantID = 0;

				interactionObject = null;

			}

			else

			{

				interactionObject = (InteractionObject) EditorGUILayout.ObjectField ("Interaction object:", interactionObject, typeof(InteractionObject), true);

				interactionObjectConstantID = FieldToID (interactionObject, interactionObjectConstantID);

				interactionObject = IDToField (interactionObject, interactionObjectConstantID, false);

			}

 			canInterrupt = EditorGUILayout.Toggle ("Can interrupt?", canInterrupt);

 			AfterRunningOption ();

 		}

		override public string SetLabel ()

		{

			string labelAdd = "";

			if (interactionObject)

			{

				if (isPlayer)

				{

					labelAdd = " (Player to " + interactionObject.name + ")";

				}

				else if (interactionSystem)

				{

					labelAdd = " (" + interactionSystem.name + " to " + interactionObject.name + ")";

				}

			}

			return labelAdd;

		}

 		#endif

 	}

 }

```

-Code provided by Snebjorn and edited by PurpleShine-

-Quotes edited by Alverik-