No edit summary Tag: Visual edit |
(Updated to latest UCC version) Tag: Visual edit |
||
Line 8: | Line 8: | ||
# In the AC Player component, set the '''Animation engine''' to '''Custom''' |
# In the AC Player component, set the '''Animation engine''' to '''Custom''' |
||
AdventureCreatorControllerHandler.cs: |
AdventureCreatorControllerHandler.cs: |
||
+ | using UnityEngine;<br>using AC;<br>using Opsive.UltimateCharacterController.Input;<br>using Opsive.UltimateCharacterController.Character;<br><code>using Opsive.Shared.Events;</code><br><br> |
||
− | using UnityEngine;<br> |
||
⚫ | |||
− | using AC;<br> |
||
− | using Opsive.UltimateCharacterController.Input;<br> |
||
− | using Opsive.UltimateCharacterController.Character;<br> |
||
− | using Opsive.UltimateCharacterController.Events;<br> |
||
− | <br> |
||
− | [RequireComponent (typeof (UltimateCharacterLocomotion))]<br> |
||
⚫ | |||
− | {<br> |
||
− | <br> |
||
#region Variables<br> |
#region Variables<br> |
||
+ | private Vector2 defaultMouseSensitivity;<br> private UltimateCharacterLocomotion ultimateCharacterLocomotion;<br> private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;<br> private Player player;<br> |
||
− | <br> |
||
− | private Vector2 defaultMouseSensitivity;<br> |
||
− | private UltimateCharacterLocomotion ultimateCharacterLocomotion;<br> |
||
− | private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;<br> |
||
− | private Player player;<br> |
||
− | <br> |
||
#endregion<br> |
#endregion<br> |
||
+ | |||
+ | #region UnityStandards<br><br> private void Awake ()<br> {<br> player = GetComponent <AC.Player>();<br> playerInput = GetComponent <Opsive.UltimateCharacterController.Input.PlayerInput>();<br> ultimateCharacterLocomotion = GetComponent <UltimateCharacterLocomotion>();<br><br> if (playerInput != null)<br> {<br> defaultMouseSensitivity = playerInput.LookSensitivity;<br> }<br> }<br> |
||
+ | |||
+ | private void OnEnable ()<br> {<br> EventManager.OnEnterGameState += OnEnterGameState;<br> }<br><br><br> private void OnDisable ()<br> {<br> EventManager.OnEnterGameState -= OnEnterGameState;<br> }<br><br> |
||
⚫ | |||
<br> |
<br> |
||
+ | private void Update ()<br> {<br> if (playerInput != null)<br> {<br> playerInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked ())<br> ? defaultMouseSensitivity<br> : Vector2.zero;<br> }<br> }<br><br> #endregion<br> |
||
− | <br> |
||
+ | |||
− | #region UnityStandards<br> |
||
− | <br> |
||
− | private void Awake ()<br> |
||
− | {<br> |
||
− | player = GetComponent <AC.Player>();<br> |
||
− | playerInput = GetComponent <Opsive.UltimateCharacterController.Input.PlayerInput>();<br> |
||
− | ultimateCharacterLocomotion = GetComponent <UltimateCharacterLocomotion>();<br> |
||
− | <br> |
||
− | if (playerInput != null)<br> |
||
− | {<br> |
||
− | defaultMouseSensitivity = playerInput.LookSensitivity;<br> |
||
− | }<br> |
||
− | }<br> |
||
− | <br> |
||
− | <br> |
||
− | private void OnEnable ()<br> |
||
− | {<br> |
||
− | EventManager.OnEnterGameState += OnEnterGameState;<br> |
||
− | }<br> |
||
− | <br> |
||
− | <br> |
||
− | private void OnDisable ()<br> |
||
− | {<br> |
||
− | EventManager.OnEnterGameState -= OnEnterGameState;<br> |
||
− | }<br> |
||
− | <br> |
||
− | private void Start ()<br> |
||
− | {<br> |
||
⚫ | |||
− | } |
||
− | <br><br> |
||
− | private void Update ()<br> |
||
− | {<br> |
||
− | if (playerInput != null)<br> |
||
− | {<br> |
||
− | playerInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked ())<br> |
||
− | ? defaultMouseSensitivity<br> |
||
− | : Vector2.zero;<br> |
||
− | }<br> |
||
− | }<br> |
||
− | <br> |
||
− | #endregion<br> |
||
− | <br> |
||
− | <br> |
||
#region CustomEvents<br> |
#region CustomEvents<br> |
||
+ | private void OnEnterGameState (GameState newGameState)<br> {<br> if (newGameState == GameState.Normal)<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> |
||
+ | |||
− | private void OnEnterGameState (GameState newGameState)<br> |
||
⚫ | |||
− | {<br> |
||
− | if (newGameState == GameState.Normal)<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> |
||
− | private void OnTeleport ()<br> |
||
− | {<br> |
||
⚫ | |||
− | }<br> |
||
− | <br> |
||
#endregion<br> |
#endregion<br> |
||
− | <br> |
||
} |
} |
||
Revision as of 08:06, 15 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:
- If using UFPS, set your game's Movement method to First Person
- Use the Scene Manager to Organise scene objects, and opt to Convert the UCC's MainCamera into an AC one
- Otherwise, you can remove AC's MainCamera, drop the UCC MainCamera into the scene, and attach AC's MainCamera component
- Find the UCC Player GameObject in the scene, and attach both AC's Player component, and the script below (AdventureCreatorControllerHandler.cs)
- 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 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;
}
}
#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
}