Converted to click to move

dev-hazim
Hazim Bin Ijaz 2 weeks ago
parent 86f1797b79
commit 1d9f69762c

@ -75,81 +75,6 @@ MonoBehaviour:
m_FillOrigin: 0 m_FillOrigin: 0
m_UseSpriteMesh: 0 m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1 m_PixelsPerUnitMultiplier: 1
--- !u!1 &3027192775168061578
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1428306882141109911}
- component: {fileID: 794668981400312816}
- component: {fileID: 8060358920238599761}
m_Layer: 5
m_Name: Logo
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1428306882141109911
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3027192775168061578}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6913946062755835220}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 274.7, y: 185}
m_SizeDelta: {x: 371, y: 245}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &794668981400312816
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3027192775168061578}
m_CullTransparentMesh: 1
--- !u!114 &8060358920238599761
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3027192775168061578}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 4a7a22d18b63531438f665e67e42513b, type: 3}
m_Type: 0
m_PreserveAspect: 1
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &5164871674315323616 --- !u!1 &5164871674315323616
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -242,7 +167,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &3467790591639231224 --- !u!224 &3467790591639231224
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -257,9 +182,9 @@ RectTransform:
m_Children: [] m_Children: []
m_Father: {fileID: 6913946062755835220} m_Father: {fileID: 6913946062755835220}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 1, y: 0} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -131.09998, y: 59.5} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 165, y: 38} m_SizeDelta: {x: 165, y: 38}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7154941800200264157 --- !u!222 &7154941800200264157
@ -408,7 +333,6 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 1428306882141109911}
- {fileID: 9139809042769856543} - {fileID: 9139809042769856543}
- {fileID: 3467790591639231224} - {fileID: 3467790591639231224}
m_Father: {fileID: 0} m_Father: {fileID: 0}
@ -439,14 +363,14 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 0, g: 0, b: 0, a: 1}
m_RaycastTarget: 1 m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1 m_Maskable: 1
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Sprite: {fileID: 21300000, guid: 31b6b74ea85cc724ba390ac5c29e5e07, type: 3} m_Sprite: {fileID: 0}
m_Type: 0 m_Type: 0
m_PreserveAspect: 0 m_PreserveAspect: 0
m_FillCenter: 1 m_FillCenter: 1

@ -1,6 +1,6 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1 &3883971050552244427 --- !u!1 &1382721990208428792
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@ -8,23 +8,23 @@ GameObject:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 7558175285853634407} - component: {fileID: 8690395355838649168}
- component: {fileID: 2850724162131160543} - component: {fileID: 6810852445961448004}
- component: {fileID: 4944058736642115274} - component: {fileID: 8715787529924330441}
m_Layer: 5 m_Layer: 5
m_Name: Logo m_Name: Text (TMP)
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!224 &7558175285853634407 --- !u!224 &8690395355838649168
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3883971050552244427} m_GameObject: {fileID: 1382721990208428792}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
@ -32,29 +32,29 @@ RectTransform:
m_Children: [] m_Children: []
m_Father: {fileID: 9071773475623594905} m_Father: {fileID: 9071773475623594905}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 274.7, y: 185} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 371, y: 245} m_SizeDelta: {x: 1000.3827, y: 495.4445}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2850724162131160543 --- !u!222 &6810852445961448004
CanvasRenderer: CanvasRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3883971050552244427} m_GameObject: {fileID: 1382721990208428792}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!114 &4944058736642115274 --- !u!114 &8715787529924330441
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3883971050552244427} m_GameObject: {fileID: 1382721990208428792}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Material: {fileID: 0} m_Material: {fileID: 0}
@ -65,16 +65,75 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Sprite: {fileID: 21300000, guid: 4a7a22d18b63531438f665e67e42513b, type: 3} m_text: Loading...
m_Type: 0 m_isRightToLeft: 0
m_PreserveAspect: 1 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_FillCenter: 1 m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_FillMethod: 4 m_fontSharedMaterials: []
m_FillAmount: 1 m_fontMaterial: {fileID: 0}
m_FillClockwise: 1 m_fontMaterials: []
m_FillOrigin: 0 m_fontColor32:
m_UseSpriteMesh: 0 serializedVersion: 2
m_PixelsPerUnitMultiplier: 1 rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 168.1
m_fontSizeBase: 168.1
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 126.03
m_fontStyle: 0
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &5679638553482947985 --- !u!1 &5679638553482947985
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -106,7 +165,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 7558175285853634407} - {fileID: 8690395355838649168}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
@ -135,14 +194,14 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 0, g: 0, b: 0, a: 1}
m_RaycastTarget: 1 m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1 m_Maskable: 1
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Sprite: {fileID: 21300000, guid: 31b6b74ea85cc724ba390ac5c29e5e07, type: 3} m_Sprite: {fileID: 0}
m_Type: 0 m_Type: 0
m_PreserveAspect: 0 m_PreserveAspect: 0
m_FillCenter: 1 m_FillCenter: 1

@ -1,4 +1,3 @@
using Fusion; using Fusion;
using UnityEngine; using UnityEngine;
using DG.Tweening; using DG.Tweening;
@ -7,103 +6,104 @@ using Fusion.Addons.SimpleKCC;
[DefaultExecutionOrder(-5)] [DefaultExecutionOrder(-5)]
public sealed class TopDownPlayer : NetworkBehaviour public sealed class TopDownPlayer : NetworkBehaviour
{ {
//=================================================== //===================================================
// FIELDS // FIELDS
//=================================================== //===================================================
[SerializeField] KCC _kcc = null; [SerializeField] KCC _kcc = null;
[SerializeField] TopDownPlayerInput _input = null; [SerializeField] TopDownPlayerInput _input = null;
[SerializeField] AnimationController _animator = null; [SerializeField] AnimationController _animator = null;
//=================================================== //===================================================
// PRIVATE FIELDS // PRIVATE FIELDS
//=================================================== //===================================================
private MovementData _moveData = new(); private MovementData _moveData = new();
[Networked] [Networked]
private int _jumpCount { get; set; } private int _jumpCount { get; set; }
private int _lastVisibleJump; private int _lastVisibleJump;
[Networked] [Networked]
private int _attackCount { get; set; } private int _attackCount { get; set; }
private int _lastVisibleAttack; private int _lastVisibleAttack;
//=================================================== //===================================================
// PROPERTIES // PROPERTIES
//=================================================== //===================================================
public float Speed => _moveData.Speed; public float Speed => _moveData.Speed;
public KCC KCC => _kcc; public KCC KCC => _kcc;
public TopDownPlayerInput Input => _input; public TopDownPlayerInput Input => _input;
private MovementSettings MoveSettings => GameData.Instance.MovementSettings; private MovementSettings MoveSettings => GameData.Instance.MovementSettings;
//=================================================== //===================================================
// METHODS // METHODS
//=================================================== //===================================================
public override void Spawned() public override void Spawned()
{ {
base.Spawned(); base.Spawned();
_lastVisibleJump = _jumpCount; _lastVisibleJump = _jumpCount;
_lastVisibleAttack = _attackCount; _lastVisibleAttack = _attackCount;
if(_kcc == null) if(_kcc == null)
_kcc = GetComponent<KCC>(); _kcc = GetComponent<KCC>();
if(_input == null) if(_input == null)
_input = GetComponent<TopDownPlayerInput>(); _input = GetComponent<TopDownPlayerInput>();
if (_moveData.MainCamera == null) if (_moveData.MainCamera == null)
_moveData.MainCamera = GameObject.FindGameObjectWithTag("MainCamera"); _moveData.MainCamera = GameObject.FindGameObjectWithTag("MainCamera");
if(_animator == null) if(_animator == null)
_animator = GetComponent<AnimationController>(); _animator = GetComponent<AnimationController>();
}//Spawned() end }//Spawned() end
public override void FixedUpdateNetwork() public override void FixedUpdateNetwork()
{ {
if(Input == null) if(Input == null)
return; return;
_moveData.TargetSpeed = Input.CurrentInput.Sprint == true ? MoveSettings.SprintSpeed : MoveSettings.MoveSpeed; _moveData.TargetSpeed = Input.CurrentInput.Sprint == true ? MoveSettings.SprintSpeed : MoveSettings.MoveSpeed;
if(Input.CurrentInput.MoveDirection != Vector2.zero) if(Input.CurrentInput.MoveDirection != Vector2.zero)
{ {
_moveData.TargetRotation = KCC.GetLookRotation(false, true).y; Vector3 moveDirection = new Vector3(Input.CurrentInput.MoveDirection.x, 0.0f, Input.CurrentInput.MoveDirection.y);
_moveData.TargetRotation = Mathf.Atan2(Input.CurrentInput.MoveDirection.x, Input.CurrentInput.MoveDirection.y) * Mathf.Rad2Deg + _moveData.MainCamera.transform.eulerAngles.y; _moveData.TargetRotation = Quaternion.LookRotation(moveDirection).eulerAngles.y;
_moveData.TargetRotationMove = _moveData.TargetRotation + _moveData.MainCamera.transform.eulerAngles.y; _moveData.TargetRotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, _moveData.TargetRotation, ref _moveData.RotationVelocity, MoveSettings.RotationSmooth);
_moveData.TargetRotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, _moveData.TargetRotation, ref _moveData.RotationVelocity, MoveSettings.RotationSmooth);
KCC.SetLookRotation(new Vector2(0f, _moveData.TargetRotation)); KCC.SetLookRotation(new Vector2(0f, _moveData.TargetRotation));
}//if end }//if end
else else
{
_moveData.TargetRotationMove = 0f; _moveData.TargetRotationMove = 0f;
}
if(Input.CurrentInput.MoveDirection != Vector2.zero) if(Input.CurrentInput.MoveDirection != Vector2.zero)
{ {
_moveData.InputDirection = Quaternion.Euler(0.0f, _moveData.TargetRotationMove, 0.0f) * Vector3.forward; _moveData.InputDirection = Quaternion.Euler(0.0f, _moveData.TargetRotation, 0.0f) * Vector3.forward;
_moveData.InputDirection.x += Input.CurrentInput.MoveDirection.x; }
_moveData.InputDirection.z += Input.CurrentInput.MoveDirection.y;
}//if end
else else
{
_moveData.InputDirection = Vector3.zero; _moveData.InputDirection = Vector3.zero;
}
if (KCC.IsGrounded && Input.CurrentInput.AttackAction.WasPressed(Input.PreviousInput.AttackAction, NetworkedInput.ATTACK_BUTTON) == true) if (KCC.IsGrounded && Input.CurrentInput.AttackAction.WasPressed(Input.PreviousInput.AttackAction, NetworkedInput.ATTACK_BUTTON) == true)
_attackCount++; _attackCount++;
if (KCC.IsGrounded && Input.CurrentInput.JumpAction.WasPressed(Input.PreviousInput.JumpAction, NetworkedInput.JUMP_BUTTON) == true) if (KCC.IsGrounded && Input.CurrentInput.JumpAction.WasPressed(Input.PreviousInput.JumpAction, NetworkedInput.JUMP_BUTTON) == true)
{ {
DOTween.To(()=> _moveData.JumpImpulse, x=> _moveData.JumpImpulse = x, MoveSettings.JumpImpulsePeak, 0.25f).SetEase(Ease.InExpo).OnComplete(()=> DOTween.To(()=> _moveData.JumpImpulse, x=> _moveData.JumpImpulse = x, MoveSettings.JumpImpulsePeak, 0.25f).SetEase(Ease.InExpo).OnComplete(()=>
DOTween.To(()=> _moveData.JumpImpulse, x=> _moveData.JumpImpulse = x, 0f, 0.25f).SetEase(Ease.InExpo)); DOTween.To(()=> _moveData.JumpImpulse, x=> _moveData.JumpImpulse = x, 0f, 0.25f).SetEase(Ease.InExpo));
_jumpCount++; _jumpCount++;
}//if end }//if end
// It feels better when the player falls quicker. // It feels better when the player falls quicker.
KCC.SetGravity(KCC.RealVelocity.y >= 0.0f ? MoveSettings.UpGravity : MoveSettings.DownGravity); KCC.SetGravity(KCC.RealVelocity.y >= 0.0f ? MoveSettings.UpGravity : MoveSettings.DownGravity);
_moveData.MovementSpeed = Input.CurrentInput.MoveDirection.magnitude; _moveData.MovementSpeed = Input.CurrentInput.MoveDirection.magnitude;
if(_moveData.MovementSpeed > 0.01f) if(_moveData.MovementSpeed > 0.01f)
_moveData.Speed = Mathf.Lerp(_moveData.Speed, _moveData.MovementSpeed > 0.01f ? _moveData.TargetSpeed : 0f, Runner.DeltaTime * 10f); _moveData.Speed = Mathf.Lerp(_moveData.Speed, _moveData.MovementSpeed > 0.01f ? _moveData.TargetSpeed : 0f, Runner.DeltaTime * 10f);
else else
_moveData.Speed = 0f; _moveData.Speed = 0f;
_moveData.DesiredMoveVelocity = _moveData.InputDirection * _moveData.Speed; _moveData.DesiredMoveVelocity = _moveData.InputDirection * _moveData.Speed;
if (KCC.ProjectOnGround(_moveData.DesiredMoveVelocity, out Vector3 projectedDesiredMoveVelocity) == true) if (KCC.ProjectOnGround(_moveData.DesiredMoveVelocity, out Vector3 projectedDesiredMoveVelocity) == true)
_moveData.DesiredMoveVelocity = Vector3.Normalize(projectedDesiredMoveVelocity) * _moveData.Speed; _moveData.DesiredMoveVelocity = Vector3.Normalize(projectedDesiredMoveVelocity) * _moveData.Speed;
@ -113,23 +113,23 @@ public sealed class TopDownPlayer : NetworkBehaviour
else else
_moveData.Acceleration = KCC.IsGrounded == true ? MoveSettings.GroundAcceleration : MoveSettings.AirAcceleration; _moveData.Acceleration = KCC.IsGrounded == true ? MoveSettings.GroundAcceleration : MoveSettings.AirAcceleration;
_moveData.MoveVelocity = Vector3.Lerp(_moveData.MoveVelocity, _moveData.DesiredMoveVelocity, _moveData.Acceleration * Runner.DeltaTime); _moveData.MoveVelocity = Vector3.Lerp(_moveData.MoveVelocity, _moveData.DesiredMoveVelocity, _moveData.Acceleration * Runner.DeltaTime);
KCC.Move(_moveData.MoveVelocity, _moveData.JumpImpulse); KCC.Move(_moveData.MoveVelocity, _moveData.JumpImpulse);
}//FixedUpdateNetwork() end }//FixedUpdateNetwork() end
public override void Render() public override void Render()
{ {
_animator.Animate(KCC.IsGrounded, Speed, Runner.DeltaTime); _animator.Animate(KCC.IsGrounded, Speed, Runner.DeltaTime);
if (_lastVisibleJump < _jumpCount) if (_lastVisibleJump < _jumpCount)
_animator.Jump(); _animator.Jump();
_lastVisibleJump = _jumpCount; _lastVisibleJump = _jumpCount;
if (_lastVisibleAttack < _attackCount) if (_lastVisibleAttack < _attackCount)
_animator.Attack(); _animator.Attack();
_lastVisibleAttack = _attackCount; _lastVisibleAttack = _attackCount;
}//Render() end }//Render() end
}//class end }//class end

@ -1,4 +1,3 @@
using Fusion; using Fusion;
using StarterAssets; using StarterAssets;
using UnityEngine; using UnityEngine;
@ -10,127 +9,134 @@ using UnityEngine.InputSystem;
[DefaultExecutionOrder(-10)] [DefaultExecutionOrder(-10)]
public sealed class TopDownPlayerInput : NetworkBehaviour, IBeforeUpdate, IBeforeTick, INetworkInput public sealed class TopDownPlayerInput : NetworkBehaviour, IBeforeUpdate, IBeforeTick, INetworkInput
{ {
public NetworkedInput CurrentInput => _currentInput; public NetworkedInput CurrentInput => _currentInput;
public NetworkedInput PreviousInput => _previousInput; public NetworkedInput PreviousInput => _previousInput;
//=================================================== //===================================================
// PRIVATE FIELDS // PRIVATE FIELDS
//=================================================== //===================================================
private UICanvasControllerInput _mobileInput = null; private UICanvasControllerInput _mobileInput = null;
[Networked] [Networked]
private NetworkedInput _currentInput { get; set; } private NetworkedInput _currentInput { get; set; }
private bool _resetAccumulatedInput; private bool _resetAccumulatedInput;
private NetworkedInput _accumulatedInput; private NetworkedInput _accumulatedInput;
private NetworkedInput _previousInput; private NetworkedInput _previousInput;
//=================================================== private Vector3 _targetPosition;
// METHODS private bool _isClickToMoveActive;
//===================================================
public override void Spawned() //===================================================
{ // METHODS
// Reset to default state. //===================================================
_currentInput = default; public override void Spawned()
_previousInput = default; {
_accumulatedInput = default; // Reset to default state.
_resetAccumulatedInput = default; _currentInput = default;
_previousInput = default;
if (Object.HasInputAuthority == true) _accumulatedInput = default;
{ _resetAccumulatedInput = default;
Runner.GetComponent<ClientSessionHandler>().OnInputAction += OnInput; _isClickToMoveActive = false;
if(Application.isMobilePlatform) if (Object.HasInputAuthority == true)
{ {
_mobileInput = Runner.GetComponent<ClientSessionHandler>().MobileInput; Runner.GetComponent<ClientSessionHandler>().OnInputAction += OnInput;
}//if end
// else if(Application.isEditor) if (Application.isMobilePlatform)
// { {
// Cursor.lockState = CursorLockMode.Locked; _mobileInput = Runner.GetComponent<ClientSessionHandler>().MobileInput;
// Cursor.visible = false; }//if end
// }//if end }//if end
}//if end
ReplicateToAll(false);
ReplicateToAll(false); ReplicateTo(Object.InputAuthority, true);
ReplicateTo(Object.InputAuthority, true); }//Spawned() end
}//Spawned() end
void IBeforeUpdate.BeforeUpdate()
void IBeforeUpdate.BeforeUpdate() {
{ if (HasInputAuthority == false)
if (HasInputAuthority == false) return;
return;
if (_resetAccumulatedInput == true)
if (_resetAccumulatedInput == true) {
{ _resetAccumulatedInput = false;
_resetAccumulatedInput = false; _accumulatedInput = default;
_accumulatedInput = default; }//if end
}//if end
if (Application.isMobilePlatform)
if(Application.isMobilePlatform) {
{ MobileInput();
MobileInput(); }//if end
}//if end else
else {
{ ClickToMoveInput();
// if (Cursor.lockState != CursorLockMode.Locked) }//else end
// return; }//BeforeUpdate() end
StandaloneInput(); void IBeforeTick.BeforeTick()
}//if end {
if (Object == null)
}//BeforeUpdate() end return;
void IBeforeTick.BeforeTick() _previousInput = _currentInput;
{ NetworkedInput currentInput = _currentInput;
if (Object == null) _currentInput = currentInput;
return;
if (Object.InputAuthority != PlayerRef.None)
_previousInput = _currentInput; {
NetworkedInput currentInput = _currentInput; if (GetInput(out NetworkedInput input) == true)
_currentInput = currentInput; _currentInput = input;
}//if end
if (Object.InputAuthority != PlayerRef.None) }//BeforeTick() end
{
if (GetInput(out NetworkedInput input) == true) private void OnInput(NetworkRunner runner, NetworkInput networkInput)
_currentInput = input; {
}//if end networkInput.Set(_accumulatedInput);
}//BeforeTick() end _resetAccumulatedInput = true;
}//OnInput() end
private void OnInput(NetworkRunner runner, NetworkInput networkInput)
{ private void ClickToMoveInput()
networkInput.Set(_accumulatedInput); {
_resetAccumulatedInput = true; if (Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame)
}//OnInput() end {
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
private void StandaloneInput() if (Physics.Raycast(ray, out RaycastHit hit))
{ {
Keyboard keyboard = Keyboard.current; _targetPosition = hit.point;
if (keyboard != null) _isClickToMoveActive = true;
{ }//if end
Vector2 moveDirection = Vector2.zero; }//if end
if (keyboard.wKey.isPressed == true) { moveDirection += Vector2.up ; } if (_isClickToMoveActive)
if (keyboard.sKey.isPressed == true) { moveDirection += Vector2.down ; } {
if (keyboard.aKey.isPressed == true) { moveDirection += Vector2.left ; } Vector3 direction = (_targetPosition - transform.position).normalized;
if (keyboard.dKey.isPressed == true) { moveDirection += Vector2.right; } direction.y = 0; // Ignore vertical movement
_accumulatedInput.MoveDirection = moveDirection.normalized; if (Vector3.Distance(transform.position, _targetPosition) > 0.1f)
_accumulatedInput.Sprint = keyboard.leftShiftKey.isPressed; {
_accumulatedInput.JumpAction.Set(NetworkedInput.JUMP_BUTTON, keyboard.spaceKey.isPressed); _accumulatedInput.MoveDirection = new Vector2(direction.x, direction.z).normalized;
}//if end }
else
if(Mouse.current != null) {
_accumulatedInput.AttackAction.Set(NetworkedInput.ATTACK_BUTTON, Mouse.current.leftButton.isPressed); _accumulatedInput.MoveDirection = Vector2.zero;
}//StandaloneInput() end _isClickToMoveActive = false;
}//else end
private void MobileInput() }//if end
{ else
if(_mobileInput is null) {
return; _accumulatedInput.MoveDirection = Vector2.zero;
}//else end
_accumulatedInput.MoveDirection = _mobileInput.Move; }//ClickToMoveInput() end
_accumulatedInput.Sprint = _mobileInput.Sprint;
_accumulatedInput.JumpAction.Set(NetworkedInput.JUMP_BUTTON, _mobileInput.Jump); private void MobileInput()
_accumulatedInput.AttackAction.Set(NetworkedInput.ATTACK_BUTTON, _mobileInput.Attack); {
}//MobileInput() end if (_mobileInput is null)
return;
_accumulatedInput.MoveDirection = _mobileInput.Move;
_accumulatedInput.Sprint = _mobileInput.Sprint;
_accumulatedInput.JumpAction.Set(NetworkedInput.JUMP_BUTTON, _mobileInput.Jump);
_accumulatedInput.AttackAction.Set(NetworkedInput.ATTACK_BUTTON, _mobileInput.Attack);
}//MobileInput() end
}//class end }//class end

@ -11,6 +11,7 @@
"com.unity.test-framework": "1.1.33", "com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.8", "com.unity.textmeshpro": "3.0.8",
"com.unity.timeline": "1.7.6", "com.unity.timeline": "1.7.6",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.10",
"com.unity.ugui": "1.0.0", "com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0", "com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0", "com.unity.modules.androidjni": "1.0.0",

@ -128,6 +128,22 @@
"com.unity.searcher": "4.9.2" "com.unity.searcher": "4.9.2"
} }
}, },
"com.unity.sysroot": {
"version": "2.0.10",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.sysroot.linux-x86_64": {
"version": "2.0.9",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.sysroot": "2.0.10"
},
"url": "https://packages.unity.com"
},
"com.unity.test-framework": { "com.unity.test-framework": {
"version": "1.1.33", "version": "1.1.33",
"depth": 0, "depth": 0,
@ -160,6 +176,16 @@
}, },
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.toolchain.win-x86_64-linux-x86_64": {
"version": "2.0.10",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.sysroot": "2.0.10",
"com.unity.sysroot.linux-x86_64": "2.0.9"
},
"url": "https://packages.unity.com"
},
"com.unity.ugui": { "com.unity.ugui": {
"version": "1.0.0", "version": "1.0.0",
"depth": 0, "depth": 0,

@ -140,7 +140,8 @@ PlayerSettings:
visionOSBundleVersion: 1.0 visionOSBundleVersion: 1.0
tvOSBundleVersion: 1.0 tvOSBundleVersion: 1.0
bundleVersion: 1 bundleVersion: 1
preloadedAssets: [] preloadedAssets:
- {fileID: 11400000, guid: 8067e0a3499c4b44ab5a819cfe0c9f88, type: 2}
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1 m_HolographicPauseOnTrackingLoss: 1

Loading…
Cancel
Save