Adventure Creator Wikia
No edit summary
Tag: Visual edit
No edit summary
Tag: Visual edit
(2 intermediate revisions by the same user not shown)
Line 12: Line 12:
 
using Opsive.UltimateCharacterController.Input;<br>
 
using Opsive.UltimateCharacterController.Input;<br>
 
using Opsive.UltimateCharacterController.Character;<br>
 
using Opsive.UltimateCharacterController.Character;<br>
using Opsive.UltimateCharacterController.Events;<br>
+
using Opsive.Shared.Events;<br>
  +
<br>
 
<br>
 
<br>
 
[RequireComponent (typeof (UltimateCharacterLocomotion))]<br>
 
[RequireComponent (typeof (UltimateCharacterLocomotion))]<br>
 
public class AdventureCreatorControllerHandler : MonoBehaviour<br>
 
public class AdventureCreatorControllerHandler : MonoBehaviour<br>
 
{<br>
 
{<br>
  +
<br>
 
<br>
 
<br>
 
#region Variables<br>
 
#region Variables<br>
Line 23: Line 25:
 
private UltimateCharacterLocomotion ultimateCharacterLocomotion;<br>
 
private UltimateCharacterLocomotion ultimateCharacterLocomotion;<br>
 
private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;<br>
 
private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;<br>
private Player player;<br>
+
private AC.Player player;<br>
 
<br>
 
<br>
 
#endregion<br>
 
#endregion<br>
Line 53: Line 55:
 
EventManager.OnEnterGameState -= OnEnterGameState;<br>
 
EventManager.OnEnterGameState -= OnEnterGameState;<br>
 
}<br>
 
}<br>
  +
<br>
 
<br>
 
<br>
 
private void Start ()<br>
 
private void Start ()<br>
 
{<br>
 
{<br>
<code>OnEnterGameState (GameState.Normal);</code><br>
+
OnEnterGameState (GameState.Normal);<br>
}
+
}<br>
<br><br>
+
<br>
  +
<br>
 
private void Update ()<br>
 
private void Update ()<br>
 
{<br>
 
{<br>
Line 66: Line 70:
 
? defaultMouseSensitivity<br>
 
? defaultMouseSensitivity<br>
 
: Vector2.zero;<br>
 
: Vector2.zero;<br>
  +
<br>
  +
if (KickStarter.stateHandler.IsInGameplay ())<br>
  +
{<br>
  +
if (KickStarter.playerInput.CanDirectControlPlayer ())<br>
  +
{<br>
  +
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", true);<br>
  +
player.motionControl = MotionControl.Manual;<br>
  +
}<br>
  +
else<br>
  +
{<br>
  +
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", false);<br>
  +
player.motionControl = MotionControl.Automatic;<br>
  +
}<br>
  +
}<br>
 
}<br>
 
}<br>
 
}<br>
 
}<br>
Line 98: Line 116:
 
}
 
}
   
 
   
 
 

Revision as of 08:40, 19 April 2020

This script allows for integration with Opsive's Ultimate Character Controller (UFPS 2 included). Note: This currently only allows for control through UCC - not a hybrid with AC, e.g. point and click movement.

To use it:

  1. If using UFPS, set your game's Movement method to First Person
  2. Use the Scene Manager to Organise scene objects, and opt to Convert the UCC's MainCamera into an AC one
  3. Otherwise, you can remove AC's MainCamera, drop the UCC MainCamera into the scene, and attach AC's MainCamera component
  4. Find the UCC Player GameObject in the scene, and attach both AC's Player component, and the script below (AdventureCreatorControllerHandler.cs)
  5. In the AC Player component, set the Animation engine to Custom

AdventureCreatorControllerHandler.cs:

using UnityEngine;
using AC;
using Opsive.UltimateCharacterController.Input;
using Opsive.UltimateCharacterController.Character;
using Opsive.Shared.Events;


[RequireComponent (typeof (UltimateCharacterLocomotion))]
public class AdventureCreatorControllerHandler : MonoBehaviour
{


#region Variables

private Vector2 defaultMouseSensitivity;
private UltimateCharacterLocomotion ultimateCharacterLocomotion;
private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;
private AC.Player player;

#endregion


#region UnityStandards

private void Awake ()
{
player = GetComponent <AC.Player>();
playerInput = GetComponent <Opsive.UltimateCharacterController.Input.PlayerInput>();
ultimateCharacterLocomotion = GetComponent <UltimateCharacterLocomotion>();

if (playerInput != null)
{
defaultMouseSensitivity = playerInput.LookSensitivity;
}
}


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


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


private void Start ()
{
OnEnterGameState (GameState.Normal);
}


private void Update ()
{
if (playerInput != null)
{
playerInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked ())
? defaultMouseSensitivity
: Vector2.zero;

if (KickStarter.stateHandler.IsInGameplay ())
{
if (KickStarter.playerInput.CanDirectControlPlayer ())
{
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", true);
player.motionControl = MotionControl.Manual;
}
else
{
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", false);
player.motionControl = MotionControl.Automatic;
}
}
}
}

#endregion


#region CustomEvents

private void OnEnterGameState (GameState newGameState)
{
if (newGameState == GameState.Normal)
{
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", true);
player.motionControl = MotionControl.Manual;
}
else
{
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", false);
player.motionControl = MotionControl.Automatic;
}
}


private void OnTeleport ()
{
ultimateCharacterLocomotion.SetPositionAndRotation (KickStarter.player.GetTargetPosition (), KickStarter.player.GetTargetRotation (), true);
}

#endregion

}