update
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 862ff94b40847fd49a64dd8014439596
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 644a107b18bafce43b25dde3fa6ee196
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 030da38e3f89e0141a1a84d80ecde0d3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: SkyboxLiteWarm
|
||||
m_Shader: {fileID: 106, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords: _SUNDISK_HIGH_QUALITY
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _AtmosphereThickness: 0.5
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _Exposure: 0.7
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SunDisk: 2
|
||||
- _SunSize: 0.05
|
||||
- _SunSizeConvergence: 3.5
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _GroundColor: {r: 0.08627451, g: 0.08235294, b: 0.08235294, a: 1}
|
||||
- _SkyTint: {r: 0.8820755, g: 1, b: 0.9987828, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aeab33f69c199e54794f516d31450ec4
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/Environment/Art/Skybox/SkyboxLiteWarm.mat
|
||||
uploadId: 691166
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d966194233ecb2f4ba1b4d6fde2a94a2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84ec1b6e1d906a84a9ce27d5466afeda
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BasicRigidBodyPush : MonoBehaviour
|
||||
{
|
||||
public LayerMask pushLayers;
|
||||
public bool canPush;
|
||||
[Range(0.5f, 5f)] public float strength = 1.1f;
|
||||
|
||||
private void OnControllerColliderHit(ControllerColliderHit hit)
|
||||
{
|
||||
if (canPush) PushRigidBodies(hit);
|
||||
}
|
||||
|
||||
private void PushRigidBodies(ControllerColliderHit hit)
|
||||
{
|
||||
// https://docs.unity3d.com/ScriptReference/CharacterController.OnControllerColliderHit.html
|
||||
|
||||
// make sure we hit a non kinematic rigidbody
|
||||
Rigidbody body = hit.collider.attachedRigidbody;
|
||||
if (body == null || body.isKinematic) return;
|
||||
|
||||
// make sure we only push desired layer(s)
|
||||
var bodyLayerMask = 1 << body.gameObject.layer;
|
||||
if ((bodyLayerMask & pushLayers.value) == 0) return;
|
||||
|
||||
// We dont want to push objects below us
|
||||
if (hit.moveDirection.y < -0.3f) return;
|
||||
|
||||
// Calculate push direction from move direction, horizontal motion only
|
||||
Vector3 pushDir = new Vector3(hit.moveDirection.x, 0.0f, hit.moveDirection.z);
|
||||
|
||||
// Apply the push and take strength into account
|
||||
body.AddForce(pushDir * strength, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 909d917d73a63f940ac158d02e936645
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/FirstPersonController/Scripts/BasicRigidBodyPush.cs
|
||||
uploadId: 691166
|
||||
@@ -0,0 +1,372 @@
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
namespace StarterAssets
|
||||
{
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
[RequireComponent(typeof(PlayerInput))]
|
||||
#endif
|
||||
public class FirstPersonController : MonoBehaviour
|
||||
{
|
||||
[Header("Player")]
|
||||
public float StandingSpeed = 4.0f;
|
||||
private float MoveSpeed = 4.0f;
|
||||
public float SprintSpeed = 6.0f;
|
||||
public float RotationSpeed = 1.0f;
|
||||
public float SpeedChangeRate = 10.0f;
|
||||
|
||||
[Space(10)]
|
||||
public float JumpHeight = 1.2f;
|
||||
public float Gravity = -15.0f;
|
||||
|
||||
[Space(10)]
|
||||
public float JumpTimeout = 0.1f;
|
||||
public float FallTimeout = 0.15f;
|
||||
|
||||
[Header("Posture Heights")]
|
||||
[Tooltip("Height when standing")]
|
||||
public float StandingHeight = 1.8f;
|
||||
[Tooltip("Height when crouching")]
|
||||
public float CrouchHeight = 1.2f;
|
||||
[Tooltip("Height when crawling")]
|
||||
public float CrawlHeight = 0.8f;
|
||||
|
||||
[Header("Player Grounded")]
|
||||
public bool Grounded = true;
|
||||
public float GroundedOffset = -0.14f;
|
||||
public float GroundedRadius = 0.5f;
|
||||
public LayerMask GroundLayers;
|
||||
|
||||
[Header("Cinemachine")]
|
||||
public GameObject CinemachineCameraTarget;
|
||||
public float TopClamp = 90.0f;
|
||||
public float BottomClamp = -90.0f;
|
||||
|
||||
private float _cinemachineTargetPitch;
|
||||
|
||||
private float _speed;
|
||||
private float _rotationVelocity;
|
||||
private float _verticalVelocity;
|
||||
private float _terminalVelocity = 53.0f;
|
||||
|
||||
private float _jumpTimeoutDelta;
|
||||
private float _fallTimeoutDelta;
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
private PlayerInput _playerInput;
|
||||
#endif
|
||||
private CharacterController _controller;
|
||||
private StarterAssetsInputs _input;
|
||||
private GameObject _mainCamera;
|
||||
|
||||
private const float _threshold = 0.01f;
|
||||
|
||||
// Posture state
|
||||
private enum PlayerPosture { Standing, Crouching, Crawling }
|
||||
private PlayerPosture _currentPosture = PlayerPosture.Standing;
|
||||
private PlayerPosture _OldPosture = PlayerPosture.Standing;
|
||||
|
||||
private bool IsCurrentDeviceMouse
|
||||
{
|
||||
get
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
return _playerInput.currentControlScheme == "KeyboardMouse";
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_mainCamera == null)
|
||||
{
|
||||
_mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
MoveSpeed = StandingSpeed;
|
||||
_controller = GetComponent<CharacterController>();
|
||||
_input = GetComponent<StarterAssetsInputs>();
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
_playerInput = GetComponent<PlayerInput>();
|
||||
#else
|
||||
Debug.LogError("Starter Assets package is missing dependencies.");
|
||||
#endif
|
||||
|
||||
_jumpTimeoutDelta = JumpTimeout;
|
||||
_fallTimeoutDelta = FallTimeout;
|
||||
|
||||
// Initialise posture
|
||||
SetPosture(PlayerPosture.Standing);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
JumpAndGravity();
|
||||
GroundedCheck();
|
||||
HandlePosture();
|
||||
Move();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
CameraRotation();
|
||||
}
|
||||
|
||||
private void GroundedCheck()
|
||||
{
|
||||
Vector3 spherePosition = new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z);
|
||||
Grounded = Physics.CheckSphere(spherePosition, GroundedRadius, GroundLayers, QueryTriggerInteraction.Ignore);
|
||||
}
|
||||
|
||||
private void CameraRotation()
|
||||
{
|
||||
if (_input.look.sqrMagnitude >= _threshold)
|
||||
{
|
||||
float deltaTimeMultiplier = IsCurrentDeviceMouse ? 1.0f : Time.deltaTime;
|
||||
|
||||
_cinemachineTargetPitch += _input.look.y * RotationSpeed * deltaTimeMultiplier;
|
||||
_rotationVelocity = _input.look.x * RotationSpeed * deltaTimeMultiplier;
|
||||
|
||||
_cinemachineTargetPitch = ClampAngle(_cinemachineTargetPitch, BottomClamp, TopClamp);
|
||||
|
||||
CinemachineCameraTarget.transform.localRotation = Quaternion.Euler(_cinemachineTargetPitch, 0.0f, 0.0f);
|
||||
|
||||
transform.Rotate(Vector3.up * _rotationVelocity);
|
||||
}
|
||||
}
|
||||
|
||||
private void Move()
|
||||
{
|
||||
float targetSpeed = _input.sprint ? SprintSpeed : MoveSpeed;
|
||||
|
||||
if (_input.move == Vector2.zero) targetSpeed = 0.0f;
|
||||
|
||||
float currentHorizontalSpeed = new Vector3(_controller.velocity.x, 0.0f, _controller.velocity.z).magnitude;
|
||||
float speedOffset = 0.1f;
|
||||
float inputMagnitude = _input.analogMovement ? _input.move.magnitude : 1f;
|
||||
|
||||
if (currentHorizontalSpeed < targetSpeed - speedOffset || currentHorizontalSpeed > targetSpeed + speedOffset)
|
||||
{
|
||||
_speed = Mathf.Lerp(currentHorizontalSpeed, targetSpeed * inputMagnitude, Time.deltaTime * SpeedChangeRate);
|
||||
_speed = Mathf.Round(_speed * 1000f) / 1000f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_speed = targetSpeed;
|
||||
}
|
||||
|
||||
Vector3 inputDirection = new Vector3(_input.move.x, 0.0f, _input.move.y).normalized;
|
||||
|
||||
if (_input.move != Vector2.zero)
|
||||
{
|
||||
inputDirection = transform.right * _input.move.x + transform.forward * _input.move.y;
|
||||
}
|
||||
|
||||
_controller.Move(inputDirection.normalized * (_speed * Time.deltaTime) + new Vector3(0.0f, _verticalVelocity, 0.0f) * Time.deltaTime);
|
||||
}
|
||||
|
||||
private void JumpAndGravity()
|
||||
{
|
||||
if (Grounded)
|
||||
{
|
||||
_fallTimeoutDelta = FallTimeout;
|
||||
|
||||
if (_verticalVelocity < 0.0f)
|
||||
{
|
||||
_verticalVelocity = -2f;
|
||||
}
|
||||
|
||||
if (_input.jump && _jumpTimeoutDelta <= 0.0f)
|
||||
{
|
||||
_verticalVelocity = Mathf.Sqrt(JumpHeight * -2f * Gravity);
|
||||
}
|
||||
|
||||
if (_jumpTimeoutDelta >= 0.0f)
|
||||
{
|
||||
_jumpTimeoutDelta -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_jumpTimeoutDelta = JumpTimeout;
|
||||
|
||||
if (_fallTimeoutDelta >= 0.0f)
|
||||
{
|
||||
_fallTimeoutDelta -= Time.deltaTime;
|
||||
}
|
||||
|
||||
_input.jump = false;
|
||||
}
|
||||
|
||||
if (_verticalVelocity < _terminalVelocity)
|
||||
{
|
||||
_verticalVelocity += Gravity * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePosture()
|
||||
{
|
||||
// Appui sur 'C' : Passage entre Crouch et Standing
|
||||
if (_input.crouch)
|
||||
{
|
||||
// Debug.Log("_input.crouch : " + _input.crouch);
|
||||
_input.crouch = false;
|
||||
|
||||
if (_currentPosture == PlayerPosture.Crouching)
|
||||
{
|
||||
// Vérification de la hauteur du plafond avant de se redresser
|
||||
if (CheckCeilingHeight() >= StandingHeight)
|
||||
{
|
||||
SetPosture(PlayerPosture.Standing);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Pas assez de hauteur pour se lever.");
|
||||
}
|
||||
}
|
||||
else if (_currentPosture == PlayerPosture.Standing || _currentPosture == PlayerPosture.Crawling )
|
||||
{
|
||||
if (CheckCeilingHeight() >= CrouchHeight)
|
||||
{
|
||||
SetPosture(PlayerPosture.Crouching);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Pas assez de hauteur pour se baisser.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Appui sur 'V' : Passage entre Crawl et Standing
|
||||
if (_input.crawl)
|
||||
{
|
||||
// Debug.Log("_input.crawl : " + _input.crawl);
|
||||
_input.crawl = false;
|
||||
|
||||
if (_currentPosture == PlayerPosture.Crawling)
|
||||
{
|
||||
// Vérification de la hauteur du plafond avant de se redresser
|
||||
if (CheckCeilingHeight() >= StandingHeight)
|
||||
{
|
||||
SetPosture(PlayerPosture.Standing);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Pas assez de hauteur pour se lever.");
|
||||
if (CheckCeilingHeight() >= CrouchHeight)
|
||||
{
|
||||
SetPosture(PlayerPosture.Crouching);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Pas assez de hauteur pour se baisser.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_currentPosture == PlayerPosture.Standing)
|
||||
{
|
||||
SetPosture(PlayerPosture.Crawling);
|
||||
}
|
||||
else if (_currentPosture == PlayerPosture.Crouching)
|
||||
{
|
||||
SetPosture(PlayerPosture.Crawling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private float CheckCeilingHeight()
|
||||
{
|
||||
// Calculer la position de la tête, qui est à la hauteur maximale de la capsule
|
||||
Vector3 headPosition = transform.position + Vector3.up * (_controller.height / 2);
|
||||
|
||||
// Effectuer un rayon vers le haut à partir de la position de la tête
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(headPosition, Vector3.up, out hit, 2f))
|
||||
{
|
||||
// Si le rayon touche un objet, on retourne la distance entre la tête et le plafond
|
||||
Debug.Log ("hit.distance : " + hit.distance + ", headPosition : " + headPosition);
|
||||
return 10.0f;
|
||||
// return hit.distance;
|
||||
}
|
||||
return 10.0f;
|
||||
// return Mathf.Infinity; // Si rien n'est touché, on considère qu'il n'y a pas de plafond
|
||||
}
|
||||
|
||||
|
||||
private void SetPosture(PlayerPosture posture)
|
||||
{
|
||||
float h=0.0f;
|
||||
|
||||
_OldPosture = _currentPosture;
|
||||
_currentPosture = posture;
|
||||
|
||||
if ( _OldPosture == PlayerPosture.Standing) h = StandingHeight;
|
||||
else if ( _OldPosture == PlayerPosture.Crouching) h = CrouchHeight;
|
||||
else if ( _OldPosture == PlayerPosture.Crawling) h = CrawlHeight;
|
||||
|
||||
Debug.Log ("_OldPosture : " + _OldPosture + ", _currentPosture : " + _currentPosture);
|
||||
|
||||
switch (posture)
|
||||
{
|
||||
case PlayerPosture.Standing:
|
||||
_controller.height = StandingHeight;
|
||||
_controller.center = new Vector3(0.0f, StandingHeight / 2.0f, 0.0f);
|
||||
|
||||
MoveSpeed = StandingSpeed;
|
||||
CinemachineCameraTarget.transform.position = new Vector3(
|
||||
CinemachineCameraTarget.transform.position.x,
|
||||
CinemachineCameraTarget.transform.position.y + StandingHeight - h,
|
||||
CinemachineCameraTarget.transform.position.z
|
||||
);
|
||||
break;
|
||||
case PlayerPosture.Crouching:
|
||||
_controller.height = CrouchHeight;
|
||||
_controller.center = new Vector3(0.0f, CrouchHeight / 2.0f, 0.0f);
|
||||
MoveSpeed = StandingSpeed*0.6f;
|
||||
CinemachineCameraTarget.transform.position = new Vector3(
|
||||
CinemachineCameraTarget.transform.position.x,
|
||||
CinemachineCameraTarget.transform.position.y + CrouchHeight - h,
|
||||
CinemachineCameraTarget.transform.position.z
|
||||
);
|
||||
break;
|
||||
case PlayerPosture.Crawling:
|
||||
_controller.height = CrawlHeight;
|
||||
_controller.center = new Vector3(0.0f, CrawlHeight / 2.0f, 0.0f);
|
||||
MoveSpeed = StandingSpeed*0.4f;
|
||||
CinemachineCameraTarget.transform.position = new Vector3(
|
||||
CinemachineCameraTarget.transform.position.x,
|
||||
CinemachineCameraTarget.transform.position.y + CrawlHeight - h,
|
||||
CinemachineCameraTarget.transform.position.z
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static float ClampAngle(float lfAngle, float lfMin, float lfMax)
|
||||
{
|
||||
if (lfAngle < -360f) lfAngle += 360f;
|
||||
if (lfAngle > 360f) lfAngle -= 360f;
|
||||
return Mathf.Clamp(lfAngle, lfMin, lfMax);
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Color transparentGreen = new Color(0.0f, 1.0f, 0.0f, 0.35f);
|
||||
Color transparentRed = new Color(1.0f, 0.0f, 0.0f, 0.35f);
|
||||
|
||||
Gizmos.color = Grounded ? transparentGreen : transparentRed;
|
||||
|
||||
Gizmos.DrawSphere(new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z), GroundedRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55919ac34a26952479f3fc91f777b2fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/FirstPersonController/Scripts/FirstPersonController.cs
|
||||
uploadId: 691166
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fbc3ed380cd3664eb239eae97bcb586
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
namespace StarterAssets
|
||||
{
|
||||
public class StarterAssetsInputs : MonoBehaviour
|
||||
{
|
||||
[Header("Character Input Values")]
|
||||
public Vector2 move;
|
||||
public Vector2 look;
|
||||
public bool jump;
|
||||
public bool sprint;
|
||||
public bool crouch;
|
||||
public bool crawl;
|
||||
|
||||
[Header("Movement Settings")]
|
||||
public bool analogMovement;
|
||||
|
||||
[Header("Mouse Cursor Settings")]
|
||||
public bool cursorLocked = true;
|
||||
public bool cursorInputForLook = true;
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
public void OnMove(InputValue value)
|
||||
{
|
||||
MoveInput(value.Get<Vector2>());
|
||||
}
|
||||
|
||||
public void OnLook(InputValue value)
|
||||
{
|
||||
if(cursorInputForLook)
|
||||
{
|
||||
LookInput(value.Get<Vector2>());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnJump(InputValue value)
|
||||
{
|
||||
JumpInput(value.isPressed);
|
||||
}
|
||||
|
||||
public void OnSprint(InputValue value)
|
||||
{
|
||||
SprintInput(value.isPressed);
|
||||
}
|
||||
|
||||
public void OnCrouch(InputValue value)
|
||||
{
|
||||
crouch = value.isPressed;
|
||||
}
|
||||
|
||||
public void OnCrawl(InputValue value)
|
||||
{
|
||||
crawl = value.isPressed;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
public void MoveInput(Vector2 newMoveDirection)
|
||||
{
|
||||
move = newMoveDirection;
|
||||
}
|
||||
|
||||
public void LookInput(Vector2 newLookDirection)
|
||||
{
|
||||
look = newLookDirection;
|
||||
}
|
||||
|
||||
public void JumpInput(bool newJumpState)
|
||||
{
|
||||
jump = newJumpState;
|
||||
}
|
||||
|
||||
public void SprintInput(bool newSprintState)
|
||||
{
|
||||
sprint = newSprintState;
|
||||
}
|
||||
|
||||
private void OnApplicationFocus(bool hasFocus)
|
||||
{
|
||||
SetCursorState(cursorLocked);
|
||||
}
|
||||
|
||||
private void SetCursorState(bool newState)
|
||||
{
|
||||
Cursor.lockState = newState ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e087ecce43ebbff45a1b360637807d93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/InputSystem/StarterAssetsInputs.cs
|
||||
uploadId: 691166
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 109e82bf2c4b22140a3c50773a9be4fe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e614526bd44fc9b4bb59cb208160066a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f59bfd1cbb64ca44be97f8939b7b258
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace StarterAssets
|
||||
{
|
||||
public class UICanvasControllerInput : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("Output")]
|
||||
public StarterAssetsInputs starterAssetsInputs;
|
||||
|
||||
public void VirtualMoveInput(Vector2 virtualMoveDirection)
|
||||
{
|
||||
starterAssetsInputs.MoveInput(virtualMoveDirection);
|
||||
}
|
||||
|
||||
public void VirtualLookInput(Vector2 virtualLookDirection)
|
||||
{
|
||||
starterAssetsInputs.LookInput(virtualLookDirection);
|
||||
}
|
||||
|
||||
public void VirtualJumpInput(bool virtualJumpState)
|
||||
{
|
||||
starterAssetsInputs.JumpInput(virtualJumpState);
|
||||
}
|
||||
|
||||
public void VirtualSprintInput(bool virtualSprintState)
|
||||
{
|
||||
starterAssetsInputs.SprintInput(virtualSprintState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a300d010f57451488aa99000126fbd5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/Mobile/Scripts/CanvasInputs/UICanvasControllerInput.cs
|
||||
uploadId: 691166
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b828a5c3b624c34c995caf4f36f470e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
The PlayerInput component has an auto-switch control scheme action that allows automatic changing of connected devices.
|
||||
IE: Switching from Keyboard to Gamepad in-game.
|
||||
When built to a mobile phone; in most cases, there is no concept of switching connected devices as controls are typically driven through what is on the device's hardware (Screen, Tilt, etc)
|
||||
In Input System 1.0.2, if the PlayerInput component has Auto Switch enabled, it will search the mobile device for connected devices; which is very costly and results in bad performance.
|
||||
This is fixed in Input System 1.1.
|
||||
For the time-being; this script will disable a PlayerInput's auto switch control schemes; when project is built to mobile.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
public class MobileDisableAutoSwitchControls : MonoBehaviour
|
||||
{
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM && (UNITY_IOS || UNITY_ANDROID)
|
||||
|
||||
[Header("Target")]
|
||||
public PlayerInput playerInput;
|
||||
|
||||
void Start()
|
||||
{
|
||||
DisableAutoSwitchControls();
|
||||
}
|
||||
|
||||
void DisableAutoSwitchControls()
|
||||
{
|
||||
playerInput.neverAutoSwitchControlSchemes = true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 901182334643ba1438a25accc6bd0c79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/Mobile/Scripts/Utilities/MobileDisableAutoSwitchControls.cs
|
||||
uploadId: 691166
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ce59d517e01d14479a15ea4d9f9dcee
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class UIVirtualButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
|
||||
{
|
||||
[System.Serializable]
|
||||
public class BoolEvent : UnityEvent<bool> { }
|
||||
[System.Serializable]
|
||||
public class Event : UnityEvent { }
|
||||
|
||||
[Header("Output")]
|
||||
public BoolEvent buttonStateOutputEvent;
|
||||
public Event buttonClickOutputEvent;
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
OutputButtonStateValue(true);
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
OutputButtonStateValue(false);
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
OutputButtonClickEvent();
|
||||
}
|
||||
|
||||
void OutputButtonStateValue(bool buttonState)
|
||||
{
|
||||
buttonStateOutputEvent.Invoke(buttonState);
|
||||
}
|
||||
|
||||
void OutputButtonClickEvent()
|
||||
{
|
||||
buttonClickOutputEvent.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 448cd6d8e2f2cb04096e777d99974bc4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/Mobile/Scripts/VirtualInputs/UIVirtualButton.cs
|
||||
uploadId: 691166
|
||||
@@ -0,0 +1,113 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class UIVirtualJoystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Event : UnityEvent<Vector2> { }
|
||||
|
||||
[Header("Rect References")]
|
||||
public RectTransform containerRect;
|
||||
public RectTransform handleRect;
|
||||
|
||||
[Header("Settings")]
|
||||
public float joystickRange = 50f;
|
||||
public float magnitudeMultiplier = 1f;
|
||||
public bool invertXOutputValue;
|
||||
public bool invertYOutputValue;
|
||||
|
||||
[Header("Output")]
|
||||
public Event joystickOutputEvent;
|
||||
|
||||
void Start()
|
||||
{
|
||||
SetupHandle();
|
||||
}
|
||||
|
||||
private void SetupHandle()
|
||||
{
|
||||
if(handleRect)
|
||||
{
|
||||
UpdateHandleRectPosition(Vector2.zero);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
OnDrag(eventData);
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out Vector2 position);
|
||||
|
||||
position = ApplySizeDelta(position);
|
||||
|
||||
Vector2 clampedPosition = ClampValuesToMagnitude(position);
|
||||
|
||||
Vector2 outputPosition = ApplyInversionFilter(position);
|
||||
|
||||
OutputPointerEventValue(outputPosition * magnitudeMultiplier);
|
||||
|
||||
if(handleRect)
|
||||
{
|
||||
UpdateHandleRectPosition(clampedPosition * joystickRange);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
OutputPointerEventValue(Vector2.zero);
|
||||
|
||||
if(handleRect)
|
||||
{
|
||||
UpdateHandleRectPosition(Vector2.zero);
|
||||
}
|
||||
}
|
||||
|
||||
private void OutputPointerEventValue(Vector2 pointerPosition)
|
||||
{
|
||||
joystickOutputEvent.Invoke(pointerPosition);
|
||||
}
|
||||
|
||||
private void UpdateHandleRectPosition(Vector2 newPosition)
|
||||
{
|
||||
handleRect.anchoredPosition = newPosition;
|
||||
}
|
||||
|
||||
Vector2 ApplySizeDelta(Vector2 position)
|
||||
{
|
||||
float x = (position.x/containerRect.sizeDelta.x) * 2.5f;
|
||||
float y = (position.y/containerRect.sizeDelta.y) * 2.5f;
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
|
||||
Vector2 ClampValuesToMagnitude(Vector2 position)
|
||||
{
|
||||
return Vector2.ClampMagnitude(position, 1);
|
||||
}
|
||||
|
||||
Vector2 ApplyInversionFilter(Vector2 position)
|
||||
{
|
||||
if(invertXOutputValue)
|
||||
{
|
||||
position.x = InvertValue(position.x);
|
||||
}
|
||||
|
||||
if(invertYOutputValue)
|
||||
{
|
||||
position.y = InvertValue(position.y);
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
float InvertValue(float value)
|
||||
{
|
||||
return -value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2cb8c4d669392748bb924209de33b85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/Mobile/Scripts/VirtualInputs/UIVirtualJoystick.cs
|
||||
uploadId: 691166
|
||||
@@ -0,0 +1,125 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class UIVirtualTouchZone : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Event : UnityEvent<Vector2> { }
|
||||
|
||||
[Header("Rect References")]
|
||||
public RectTransform containerRect;
|
||||
public RectTransform handleRect;
|
||||
|
||||
[Header("Settings")]
|
||||
public bool clampToMagnitude;
|
||||
public float magnitudeMultiplier = 1f;
|
||||
public bool invertXOutputValue;
|
||||
public bool invertYOutputValue;
|
||||
|
||||
//Stored Pointer Values
|
||||
private Vector2 pointerDownPosition;
|
||||
private Vector2 currentPointerPosition;
|
||||
|
||||
[Header("Output")]
|
||||
public Event touchZoneOutputEvent;
|
||||
|
||||
void Start()
|
||||
{
|
||||
SetupHandle();
|
||||
}
|
||||
|
||||
private void SetupHandle()
|
||||
{
|
||||
if(handleRect)
|
||||
{
|
||||
SetObjectActiveState(handleRect.gameObject, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out pointerDownPosition);
|
||||
|
||||
if(handleRect)
|
||||
{
|
||||
SetObjectActiveState(handleRect.gameObject, true);
|
||||
UpdateHandleRectPosition(pointerDownPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out currentPointerPosition);
|
||||
|
||||
Vector2 positionDelta = GetDeltaBetweenPositions(pointerDownPosition, currentPointerPosition);
|
||||
|
||||
Vector2 clampedPosition = ClampValuesToMagnitude(positionDelta);
|
||||
|
||||
Vector2 outputPosition = ApplyInversionFilter(clampedPosition);
|
||||
|
||||
OutputPointerEventValue(outputPosition * magnitudeMultiplier);
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
pointerDownPosition = Vector2.zero;
|
||||
currentPointerPosition = Vector2.zero;
|
||||
|
||||
OutputPointerEventValue(Vector2.zero);
|
||||
|
||||
if(handleRect)
|
||||
{
|
||||
SetObjectActiveState(handleRect.gameObject, false);
|
||||
UpdateHandleRectPosition(Vector2.zero);
|
||||
}
|
||||
}
|
||||
|
||||
void OutputPointerEventValue(Vector2 pointerPosition)
|
||||
{
|
||||
touchZoneOutputEvent.Invoke(pointerPosition);
|
||||
}
|
||||
|
||||
void UpdateHandleRectPosition(Vector2 newPosition)
|
||||
{
|
||||
handleRect.anchoredPosition = newPosition;
|
||||
}
|
||||
|
||||
void SetObjectActiveState(GameObject targetObject, bool newState)
|
||||
{
|
||||
targetObject.SetActive(newState);
|
||||
}
|
||||
|
||||
Vector2 GetDeltaBetweenPositions(Vector2 firstPosition, Vector2 secondPosition)
|
||||
{
|
||||
return secondPosition - firstPosition;
|
||||
}
|
||||
|
||||
Vector2 ClampValuesToMagnitude(Vector2 position)
|
||||
{
|
||||
return Vector2.ClampMagnitude(position, 1);
|
||||
}
|
||||
|
||||
Vector2 ApplyInversionFilter(Vector2 position)
|
||||
{
|
||||
if(invertXOutputValue)
|
||||
{
|
||||
position.x = InvertValue(position.x);
|
||||
}
|
||||
|
||||
if(invertYOutputValue)
|
||||
{
|
||||
position.y = InvertValue(position.y);
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
float InvertValue(float value)
|
||||
{
|
||||
return -value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65870f34fef70aa44b0f562cfc810220
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 196525
|
||||
packageName: Starter Assets - FirstPerson | Updates in new CharacterController
|
||||
package
|
||||
packageVersion: 1.3
|
||||
assetPath: Assets/StarterAssets/Mobile/Scripts/VirtualInputs/UIVirtualTouchZone.cs
|
||||
uploadId: 691166
|
||||
Reference in New Issue
Block a user