SanAndreasUnity/Assets/Scripts/Networking/PedSync.cs

98 lines
2.4 KiB
C#
Raw Normal View History

2019-04-27 01:11:07 +00:00
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using System.Linq;
using SanAndreasUnity.Utilities;
using SanAndreasUnity.Behaviours;
namespace SanAndreasUnity.Net
{
public class PedSync : NetworkBehaviour
{
Player m_player;
Ped m_ped { get { return m_player.OwnedPed; } }
2019-04-27 13:36:44 +00:00
public static PedSync Local { get; private set; }
2019-04-27 01:11:07 +00:00
void Awake()
{
m_player = this.GetComponentOrThrow<Player>();
}
2019-04-27 13:36:44 +00:00
public override void OnStartLocalPlayer()
{
base.OnStartLocalPlayer();
Local = this;
}
2019-04-27 01:11:07 +00:00
void Start()
{
}
2019-04-27 22:19:22 +00:00
public void SendInput(bool isWalkOn, bool isRunOn, bool isSprintOn, Vector3 movementInput, bool isJumpOn, Vector3 heading)
2019-04-27 01:11:07 +00:00
{
2019-04-27 22:19:22 +00:00
this.CmdSendingInput(isWalkOn, isRunOn, isSprintOn, movementInput, isJumpOn, heading);
2019-04-27 01:11:07 +00:00
}
public void SendInput()
{
Ped ped = m_ped;
2019-04-27 22:19:22 +00:00
this.SendInput(ped.IsWalkOn, ped.IsRunOn, ped.IsSprintOn, ped.Movement, ped.IsJumpOn, ped.Heading);
}
2019-04-27 01:11:07 +00:00
[Command]
2019-04-27 22:19:22 +00:00
void CmdSendingInput(bool isWalkOn, bool isRunOn, bool isSprintOn, Vector3 movementInput, bool isJumpOn, Vector3 heading)
2019-04-27 01:11:07 +00:00
{
if (null == m_ped)
return;
Ped ped = m_ped;
ped.IsWalkOn = isWalkOn;
ped.IsRunOn = isRunOn;
ped.IsSprintOn = isSprintOn;
ped.Movement = movementInput;
ped.IsJumpOn = isJumpOn;
2019-04-27 22:19:22 +00:00
ped.Heading = heading;
2019-04-27 01:11:07 +00:00
}
2019-04-28 17:13:01 +00:00
public void OnCrouchButtonPressed() => this.CmdOnCrouchButtonPressed();
[Command]
void CmdOnCrouchButtonPressed()
{
if (m_ped)
m_ped.OnCrouchButtonPressed();
}
2019-04-28 22:02:46 +00:00
public void PedStartedEnteringVehicle(Ped ped)
2019-04-28 20:57:04 +00:00
{
NetStatus.ThrowIfNotOnServer();
// send rpc to clients
// include params: vehicle, seat
2019-04-28 21:17:50 +00:00
}
2019-04-28 22:02:46 +00:00
public void PedEnteredVehicle(Ped ped)
2019-04-28 21:17:50 +00:00
{
NetStatus.ThrowIfNotOnServer();
// send rpc to clients
// include params: vehicle, seat
}
2019-04-28 22:02:46 +00:00
public void PedStartedExitingVehicle(Ped ped)
2019-04-28 21:17:50 +00:00
{
NetStatus.ThrowIfNotOnServer();
// send rpc to clients
2019-04-28 20:57:04 +00:00
}
2019-04-27 01:11:07 +00:00
}
}