diff --git a/Assets/Development/Prefabs/UI_Panels/Panel_LoadingData.prefab b/Assets/Development/Prefabs/UI_Panels/Panel_LoadingData.prefab index ac5f6e9..cadaa5c 100644 --- a/Assets/Development/Prefabs/UI_Panels/Panel_LoadingData.prefab +++ b/Assets/Development/Prefabs/UI_Panels/Panel_LoadingData.prefab @@ -75,81 +75,6 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 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 GameObject: m_ObjectHideFlags: 0 @@ -242,7 +167,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &3467790591639231224 RectTransform: m_ObjectHideFlags: 0 @@ -257,9 +182,9 @@ RectTransform: m_Children: [] m_Father: {fileID: 6913946062755835220} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 1, y: 0} - m_AnchorMax: {x: 1, y: 0} - m_AnchoredPosition: {x: -131.09998, y: 59.5} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 165, y: 38} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &7154941800200264157 @@ -408,7 +333,6 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 1428306882141109911} - {fileID: 9139809042769856543} - {fileID: 3467790591639231224} m_Father: {fileID: 0} @@ -439,14 +363,14 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: 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_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Sprite: {fileID: 21300000, guid: 31b6b74ea85cc724ba390ac5c29e5e07, type: 3} + m_Sprite: {fileID: 0} m_Type: 0 m_PreserveAspect: 0 m_FillCenter: 1 diff --git a/Assets/Development/Prefabs/UI_Panels/Panel_Splash.prefab b/Assets/Development/Prefabs/UI_Panels/Panel_Splash.prefab index 6878901..5b649a4 100644 --- a/Assets/Development/Prefabs/UI_Panels/Panel_Splash.prefab +++ b/Assets/Development/Prefabs/UI_Panels/Panel_Splash.prefab @@ -1,6 +1,6 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &3883971050552244427 +--- !u!1 &1382721990208428792 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -8,23 +8,23 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 7558175285853634407} - - component: {fileID: 2850724162131160543} - - component: {fileID: 4944058736642115274} + - component: {fileID: 8690395355838649168} + - component: {fileID: 6810852445961448004} + - component: {fileID: 8715787529924330441} m_Layer: 5 - m_Name: Logo + m_Name: Text (TMP) m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!224 &7558175285853634407 +--- !u!224 &8690395355838649168 RectTransform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {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_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} @@ -32,29 +32,29 @@ RectTransform: m_Children: [] m_Father: {fileID: 9071773475623594905} 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_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 1000.3827, y: 495.4445} m_Pivot: {x: 0.5, y: 0.5} ---- !u!222 &2850724162131160543 +--- !u!222 &6810852445961448004 CanvasRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3883971050552244427} + m_GameObject: {fileID: 1382721990208428792} m_CullTransparentMesh: 1 ---- !u!114 &4944058736642115274 +--- !u!114 &8715787529924330441 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3883971050552244427} + m_GameObject: {fileID: 1382721990208428792} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} @@ -65,16 +65,75 @@ MonoBehaviour: 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 + m_text: Loading... + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + 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 GameObject: m_ObjectHideFlags: 0 @@ -106,7 +165,7 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 7558175285853634407} + - {fileID: 8690395355838649168} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} @@ -135,14 +194,14 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: 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_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Sprite: {fileID: 21300000, guid: 31b6b74ea85cc724ba390ac5c29e5e07, type: 3} + m_Sprite: {fileID: 0} m_Type: 0 m_PreserveAspect: 0 m_FillCenter: 1 diff --git a/Assets/_Scripts/Network/Player/TopDownPlayer.cs b/Assets/_Scripts/Network/Player/TopDownPlayer.cs index 143deec..9d29b72 100644 --- a/Assets/_Scripts/Network/Player/TopDownPlayer.cs +++ b/Assets/_Scripts/Network/Player/TopDownPlayer.cs @@ -1,4 +1,3 @@ - using Fusion; using UnityEngine; using DG.Tweening; @@ -7,103 +6,104 @@ using Fusion.Addons.SimpleKCC; [DefaultExecutionOrder(-5)] public sealed class TopDownPlayer : NetworkBehaviour { - //=================================================== - // FIELDS - //=================================================== - [SerializeField] KCC _kcc = null; - [SerializeField] TopDownPlayerInput _input = null; - [SerializeField] AnimationController _animator = null; - - //=================================================== - // PRIVATE FIELDS - //=================================================== - private MovementData _moveData = new(); - [Networked] - private int _jumpCount { get; set; } - private int _lastVisibleJump; - [Networked] - private int _attackCount { get; set; } - private int _lastVisibleAttack; - - //=================================================== - // PROPERTIES - //=================================================== - public float Speed => _moveData.Speed; - public KCC KCC => _kcc; - public TopDownPlayerInput Input => _input; - private MovementSettings MoveSettings => GameData.Instance.MovementSettings; - - //=================================================== - // METHODS - //=================================================== - public override void Spawned() - { - base.Spawned(); - - _lastVisibleJump = _jumpCount; - _lastVisibleAttack = _attackCount; - - if(_kcc == null) + //=================================================== + // FIELDS + //=================================================== + [SerializeField] KCC _kcc = null; + [SerializeField] TopDownPlayerInput _input = null; + [SerializeField] AnimationController _animator = null; + + //=================================================== + // PRIVATE FIELDS + //=================================================== + private MovementData _moveData = new(); + [Networked] + private int _jumpCount { get; set; } + private int _lastVisibleJump; + [Networked] + private int _attackCount { get; set; } + private int _lastVisibleAttack; + + //=================================================== + // PROPERTIES + //=================================================== + public float Speed => _moveData.Speed; + public KCC KCC => _kcc; + public TopDownPlayerInput Input => _input; + private MovementSettings MoveSettings => GameData.Instance.MovementSettings; + + //=================================================== + // METHODS + //=================================================== + public override void Spawned() + { + base.Spawned(); + + _lastVisibleJump = _jumpCount; + _lastVisibleAttack = _attackCount; + + if(_kcc == null) _kcc = GetComponent(); if(_input == null) _input = GetComponent(); - if (_moveData.MainCamera == null) + if (_moveData.MainCamera == null) _moveData.MainCamera = GameObject.FindGameObjectWithTag("MainCamera"); - - if(_animator == null) - _animator = GetComponent(); - }//Spawned() end + + if(_animator == null) + _animator = GetComponent(); + }//Spawned() end - public override void FixedUpdateNetwork() - { - if(Input == null) - return; + public override void FixedUpdateNetwork() + { + if(Input == null) + 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; - _moveData.TargetRotation = Mathf.Atan2(Input.CurrentInput.MoveDirection.x, Input.CurrentInput.MoveDirection.y) * Mathf.Rad2Deg + _moveData.MainCamera.transform.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); + Vector3 moveDirection = new Vector3(Input.CurrentInput.MoveDirection.x, 0.0f, Input.CurrentInput.MoveDirection.y); + _moveData.TargetRotation = Quaternion.LookRotation(moveDirection).eulerAngles.y; + _moveData.TargetRotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, _moveData.TargetRotation, ref _moveData.RotationVelocity, MoveSettings.RotationSmooth); KCC.SetLookRotation(new Vector2(0f, _moveData.TargetRotation)); }//if end else + { _moveData.TargetRotationMove = 0f; + } - if(Input.CurrentInput.MoveDirection != Vector2.zero) - { - _moveData.InputDirection = Quaternion.Euler(0.0f, _moveData.TargetRotationMove, 0.0f) * Vector3.forward; - _moveData.InputDirection.x += Input.CurrentInput.MoveDirection.x; - _moveData.InputDirection.z += Input.CurrentInput.MoveDirection.y; - }//if end + if(Input.CurrentInput.MoveDirection != Vector2.zero) + { + _moveData.InputDirection = Quaternion.Euler(0.0f, _moveData.TargetRotation, 0.0f) * Vector3.forward; + } else + { _moveData.InputDirection = Vector3.zero; - - if (KCC.IsGrounded && Input.CurrentInput.AttackAction.WasPressed(Input.PreviousInput.AttackAction, NetworkedInput.ATTACK_BUTTON) == true) - _attackCount++; + } + + if (KCC.IsGrounded && Input.CurrentInput.AttackAction.WasPressed(Input.PreviousInput.AttackAction, NetworkedInput.ATTACK_BUTTON) == true) + _attackCount++; - 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(()=> + 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, 0f, 0.25f).SetEase(Ease.InExpo)); - _jumpCount++; - }//if end + _jumpCount++; + }//if end - // It feels better when the player falls quicker. - KCC.SetGravity(KCC.RealVelocity.y >= 0.0f ? MoveSettings.UpGravity : MoveSettings.DownGravity); + // It feels better when the player falls quicker. + KCC.SetGravity(KCC.RealVelocity.y >= 0.0f ? MoveSettings.UpGravity : MoveSettings.DownGravity); _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); else _moveData.Speed = 0f; - _moveData.DesiredMoveVelocity = _moveData.InputDirection * _moveData.Speed; + _moveData.DesiredMoveVelocity = _moveData.InputDirection * _moveData.Speed; if (KCC.ProjectOnGround(_moveData.DesiredMoveVelocity, out Vector3 projectedDesiredMoveVelocity) == true) _moveData.DesiredMoveVelocity = Vector3.Normalize(projectedDesiredMoveVelocity) * _moveData.Speed; @@ -113,23 +113,23 @@ public sealed class TopDownPlayer : NetworkBehaviour else _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); - }//FixedUpdateNetwork() end + }//FixedUpdateNetwork() end - public override void Render() - { - _animator.Animate(KCC.IsGrounded, Speed, Runner.DeltaTime); + public override void Render() + { + _animator.Animate(KCC.IsGrounded, Speed, Runner.DeltaTime); - if (_lastVisibleJump < _jumpCount) - _animator.Jump(); + if (_lastVisibleJump < _jumpCount) + _animator.Jump(); - _lastVisibleJump = _jumpCount; + _lastVisibleJump = _jumpCount; - if (_lastVisibleAttack < _attackCount) - _animator.Attack(); + if (_lastVisibleAttack < _attackCount) + _animator.Attack(); - _lastVisibleAttack = _attackCount; - }//Render() end + _lastVisibleAttack = _attackCount; + }//Render() end -}//class end \ No newline at end of file +}//class end diff --git a/Assets/_Scripts/Network/Player/TopDownPlayerInput.cs b/Assets/_Scripts/Network/Player/TopDownPlayerInput.cs index a53cb47..9b90ef7 100644 --- a/Assets/_Scripts/Network/Player/TopDownPlayerInput.cs +++ b/Assets/_Scripts/Network/Player/TopDownPlayerInput.cs @@ -1,4 +1,3 @@ - using Fusion; using StarterAssets; using UnityEngine; @@ -10,127 +9,134 @@ using UnityEngine.InputSystem; [DefaultExecutionOrder(-10)] public sealed class TopDownPlayerInput : NetworkBehaviour, IBeforeUpdate, IBeforeTick, INetworkInput { - public NetworkedInput CurrentInput => _currentInput; - public NetworkedInput PreviousInput => _previousInput; - - //=================================================== - // PRIVATE FIELDS - //=================================================== - private UICanvasControllerInput _mobileInput = null; - [Networked] - private NetworkedInput _currentInput { get; set; } - - private bool _resetAccumulatedInput; - private NetworkedInput _accumulatedInput; - private NetworkedInput _previousInput; - - //=================================================== - // METHODS - //=================================================== - public override void Spawned() - { - // Reset to default state. - _currentInput = default; - _previousInput = default; - _accumulatedInput = default; - _resetAccumulatedInput = default; - - if (Object.HasInputAuthority == true) - { - Runner.GetComponent().OnInputAction += OnInput; - - if(Application.isMobilePlatform) - { - _mobileInput = Runner.GetComponent().MobileInput; - }//if end - // else if(Application.isEditor) - // { - // Cursor.lockState = CursorLockMode.Locked; - // Cursor.visible = false; - // }//if end - }//if end - - ReplicateToAll(false); - ReplicateTo(Object.InputAuthority, true); - }//Spawned() end - - void IBeforeUpdate.BeforeUpdate() - { - if (HasInputAuthority == false) - return; - - if (_resetAccumulatedInput == true) - { - _resetAccumulatedInput = false; - _accumulatedInput = default; - }//if end - - if(Application.isMobilePlatform) - { - MobileInput(); - }//if end - else - { - // if (Cursor.lockState != CursorLockMode.Locked) - // return; - - StandaloneInput(); - }//if end - - }//BeforeUpdate() end - - void IBeforeTick.BeforeTick() - { - if (Object == null) - return; - - _previousInput = _currentInput; - NetworkedInput currentInput = _currentInput; - _currentInput = currentInput; - - if (Object.InputAuthority != PlayerRef.None) - { - if (GetInput(out NetworkedInput input) == true) - _currentInput = input; - }//if end - }//BeforeTick() end - - private void OnInput(NetworkRunner runner, NetworkInput networkInput) - { - networkInput.Set(_accumulatedInput); - _resetAccumulatedInput = true; - }//OnInput() end - - private void StandaloneInput() - { - Keyboard keyboard = Keyboard.current; - if (keyboard != null) - { - Vector2 moveDirection = Vector2.zero; - - if (keyboard.wKey.isPressed == true) { moveDirection += Vector2.up ; } - if (keyboard.sKey.isPressed == true) { moveDirection += Vector2.down ; } - if (keyboard.aKey.isPressed == true) { moveDirection += Vector2.left ; } - if (keyboard.dKey.isPressed == true) { moveDirection += Vector2.right; } - - _accumulatedInput.MoveDirection = moveDirection.normalized; - _accumulatedInput.Sprint = keyboard.leftShiftKey.isPressed; - _accumulatedInput.JumpAction.Set(NetworkedInput.JUMP_BUTTON, keyboard.spaceKey.isPressed); - }//if end - - if(Mouse.current != null) - _accumulatedInput.AttackAction.Set(NetworkedInput.ATTACK_BUTTON, Mouse.current.leftButton.isPressed); - }//StandaloneInput() end - - private void MobileInput() - { - 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 + public NetworkedInput CurrentInput => _currentInput; + public NetworkedInput PreviousInput => _previousInput; + + //=================================================== + // PRIVATE FIELDS + //=================================================== + private UICanvasControllerInput _mobileInput = null; + [Networked] + private NetworkedInput _currentInput { get; set; } + + private bool _resetAccumulatedInput; + private NetworkedInput _accumulatedInput; + private NetworkedInput _previousInput; + + private Vector3 _targetPosition; + private bool _isClickToMoveActive; + + //=================================================== + // METHODS + //=================================================== + public override void Spawned() + { + // Reset to default state. + _currentInput = default; + _previousInput = default; + _accumulatedInput = default; + _resetAccumulatedInput = default; + _isClickToMoveActive = false; + + if (Object.HasInputAuthority == true) + { + Runner.GetComponent().OnInputAction += OnInput; + + if (Application.isMobilePlatform) + { + _mobileInput = Runner.GetComponent().MobileInput; + }//if end + }//if end + + ReplicateToAll(false); + ReplicateTo(Object.InputAuthority, true); + }//Spawned() end + + void IBeforeUpdate.BeforeUpdate() + { + if (HasInputAuthority == false) + return; + + if (_resetAccumulatedInput == true) + { + _resetAccumulatedInput = false; + _accumulatedInput = default; + }//if end + + if (Application.isMobilePlatform) + { + MobileInput(); + }//if end + else + { + ClickToMoveInput(); + }//else end + }//BeforeUpdate() end + + void IBeforeTick.BeforeTick() + { + if (Object == null) + return; + + _previousInput = _currentInput; + NetworkedInput currentInput = _currentInput; + _currentInput = currentInput; + + if (Object.InputAuthority != PlayerRef.None) + { + if (GetInput(out NetworkedInput input) == true) + _currentInput = input; + }//if end + }//BeforeTick() end + + private void OnInput(NetworkRunner runner, NetworkInput networkInput) + { + networkInput.Set(_accumulatedInput); + _resetAccumulatedInput = true; + }//OnInput() end + + private void ClickToMoveInput() + { + if (Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame) + { + Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue()); + if (Physics.Raycast(ray, out RaycastHit hit)) + { + _targetPosition = hit.point; + _isClickToMoveActive = true; + }//if end + }//if end + + if (_isClickToMoveActive) + { + Vector3 direction = (_targetPosition - transform.position).normalized; + direction.y = 0; // Ignore vertical movement + + if (Vector3.Distance(transform.position, _targetPosition) > 0.1f) + { + _accumulatedInput.MoveDirection = new Vector2(direction.x, direction.z).normalized; + } + else + { + _accumulatedInput.MoveDirection = Vector2.zero; + _isClickToMoveActive = false; + }//else end + }//if end + else + { + _accumulatedInput.MoveDirection = Vector2.zero; + }//else end + }//ClickToMoveInput() end + + private void MobileInput() + { + 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 diff --git a/Packages/manifest.json b/Packages/manifest.json index 845a91e..0e2e13c 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -11,6 +11,7 @@ "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.8", "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.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 704d7e8..0e4f693 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -128,6 +128,22 @@ "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": { "version": "1.1.33", "depth": 0, @@ -160,6 +176,16 @@ }, "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": { "version": "1.0.0", "depth": 0, diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 028662b..c522fc4 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -140,7 +140,8 @@ PlayerSettings: visionOSBundleVersion: 1.0 tvOSBundleVersion: 1.0 bundleVersion: 1 - preloadedAssets: [] + preloadedAssets: + - {fileID: 11400000, guid: 8067e0a3499c4b44ab5a819cfe0c9f88, type: 2} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1