update
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using OnlyScove.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vCharacterController
|
||||
{
|
||||
@@ -24,11 +25,10 @@ namespace Invector.vCharacterController
|
||||
public float cameraHeightOffset;
|
||||
[Tooltip("Transition Speed for the Camera")]
|
||||
public float lockSpeed = 0.5f;
|
||||
[Header("LockOn Inputs")]
|
||||
public GenericInput lockOnInput = new GenericInput("Tab", "RightStickClick", "RightStickClick");
|
||||
public GenericInput nexTargetInput = new GenericInput("X", false, false, "RightAnalogHorizontal", true, false, "X", false, false);
|
||||
public GenericInput previousTargetInput = new GenericInput("Z", false, false, "RightAnalogHorizontal", true, true, "Z", false, false);
|
||||
|
||||
|
||||
[vEditorToolbar("Debug")]
|
||||
public bool debugMode;
|
||||
|
||||
internal bool isLockingOn;
|
||||
public LockOnEvent onLockOnTarget;
|
||||
public LockOnEvent onUnLockOnTarget;
|
||||
@@ -38,6 +38,7 @@ namespace Invector.vCharacterController
|
||||
protected bool _inTarget;
|
||||
protected virtual bool inTarget { get { return _inTarget; } set { _inTarget = value; } }
|
||||
protected vThirdPersonInput tpInput;
|
||||
protected InputReader inputReader;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -49,6 +50,8 @@ namespace Invector.vCharacterController
|
||||
tpInput = GetComponent<vThirdPersonInput>();
|
||||
if (tpInput)
|
||||
{
|
||||
inputReader = tpInput.inputReader;
|
||||
|
||||
tpInput.onUpdate -= UpdateLockOn;
|
||||
tpInput.onUpdate += UpdateLockOn;
|
||||
|
||||
@@ -61,6 +64,8 @@ namespace Invector.vCharacterController
|
||||
UpdateLockOn();
|
||||
});
|
||||
}
|
||||
|
||||
if (inputReader == null) inputReader = GetComponentInParent<InputReader>();
|
||||
|
||||
if (!aimImageContainer)
|
||||
{
|
||||
@@ -89,31 +94,18 @@ namespace Invector.vCharacterController
|
||||
|
||||
protected virtual void UpdateLockOn()
|
||||
{
|
||||
if (this.tpInput == null) return;
|
||||
if (this.tpInput == null || inputReader == null) return;
|
||||
|
||||
LockOnInput();
|
||||
SwitchTargetsInput();
|
||||
CheckForTargetDistance();
|
||||
CheckForCharacterAlive();
|
||||
UpdateAimImage();
|
||||
}
|
||||
|
||||
protected virtual void LockOnInput()
|
||||
{
|
||||
if (tpInput.tpCamera == null || tpInput.cc == null) return;
|
||||
|
||||
// lock the camera into a target, if there is any around
|
||||
if (lockOnInput.GetButtonDown() && !tpInput.cc.customAction)
|
||||
{
|
||||
isLockingOn = !isLockingOn;
|
||||
LockOn(isLockingOn);
|
||||
}
|
||||
// unlock the camera if the target is null
|
||||
else if (isLockingOn && (tpInput.tpCamera.lockTarget == null) || LostTargetDistance())
|
||||
if (isLockingOn && (tpInput.tpCamera.lockTarget == null) || LostTargetDistance())
|
||||
{
|
||||
isLockingOn = false;
|
||||
LockOn(false);
|
||||
}
|
||||
// choose to use lock-on with strafe of free movement
|
||||
|
||||
// choose to use lock-on with strafe or free movement
|
||||
if (strafeWhileLockOn && !tpInput.cc.locomotionType.Equals(vThirdPersonMotor.LocomotionType.OnlyStrafe))
|
||||
{
|
||||
if (isLockingOn && tpInput.tpCamera.lockTarget != null)
|
||||
@@ -127,6 +119,26 @@ namespace Invector.vCharacterController
|
||||
tpInput.cc.isStrafing = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isLockingOn && tpInput.tpCamera.lockTarget)
|
||||
{
|
||||
if (inputReader.ConsumeNext()) ChangeTarget(1);
|
||||
else if (inputReader.ConsumePrevious()) ChangeTarget(-1);
|
||||
}
|
||||
|
||||
CheckForTargetDistance();
|
||||
CheckForCharacterAlive();
|
||||
UpdateAimImage();
|
||||
}
|
||||
|
||||
protected virtual void LockOnInput()
|
||||
{
|
||||
// lock the camera into a target, if there is any around
|
||||
if (inputReader.ConsumeToggleView() && !tpInput.cc.customAction)
|
||||
{
|
||||
isLockingOn = !isLockingOn;
|
||||
LockOn(isLockingOn);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool LostTargetDistance()
|
||||
@@ -147,18 +159,6 @@ namespace Invector.vCharacterController
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void SwitchTargetsInput()
|
||||
{
|
||||
if (tpInput.tpCamera == null) return;
|
||||
|
||||
if (tpInput.tpCamera.lockTarget)
|
||||
{
|
||||
// switch between targets using Keyboard
|
||||
if (previousTargetInput.GetButtonDown()) PreviousTarget();
|
||||
else if (nexTargetInput.GetButtonDown()) NextTarget();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CheckForTargetDistance()
|
||||
{
|
||||
if (!isLockingOn || currentTarget == null) return;
|
||||
@@ -214,7 +214,7 @@ namespace Invector.vCharacterController
|
||||
aimImage.transform.gameObject.SetActive(false);
|
||||
}
|
||||
if (currentTarget && aimImage && aimImageContainer)
|
||||
aimImage.anchoredPosition = currentTarget.GetScreenPointOffBoundsCenter(aimImageContainer, tpCamera.targetCamera, spriteHeight);
|
||||
aimImage.anchoredPosition = currentTarget.GetScreenPointOffBoundsCenter(aimImageContainer, tpInput.tpCamera.targetCamera, spriteHeight);
|
||||
else if (aimImageContainer)
|
||||
aimImage.anchoredPosition = Vector2.zero;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user