using System.Collections;
using TNet;
using UnityEngine;
public class NetworkPuppetSync : TNBehaviour
{
#region Fields Arranged Nicely :)
public Puppet whatToControl;
public float sendRate = 0.1F;
public bool remote = false;
float timer = 0;
bool commandAimWeapon;
bool commandDodge;
bool commandMeleeAttack;
bool commandReloadWeapon;
bool commandShoot;
bool commandSprint;
bool commandSwitchWeapon;
bool commandVault;
#endregion Fields Arranged Nicely :)
#region Methods
void CheckBool(ref bool aBool, bool aNewBool, byte rfc)
{
if (aBool != aNewBool)
{
aBool = aNewBool;
tno.Send(rfc, Target.Others, aBool);
}
}
[RFC(12)]
void SetCommandAimWeapon(bool aValue)
{
whatToControl.commandAimWeapon = aValue;
}
[RFC(8)]
void SetCommandDodge(bool aValue)
{
whatToControl.commandDodge = aValue;
}
[RFC(6)]
void SetCommandMeleeAttack(bool aValue)
{
whatToControl.commandMeleeAttack = aValue;
}
[RFC(10)]
void SetCommandReloadWeapon(bool aValue)
{
whatToControl.commandReloadWeapon = aValue;
}
[RFC(5)]
void SetCommandShoot(bool aValue)
{
whatToControl.commandShoot = aValue;
}
[RFC(11)]
void SetCommandSprint(bool aValue)
{
whatToControl.commandSprint = aValue;
}
[RFC(9)]
void SetCommandSwitchWeapon(bool aValue)
{
whatToControl.commandSwitchWeapon = aValue;
}
[RFC(7)]
void SetCommandVault(bool aValue)
{
whatToControl.commandVault = aValue;
}
[RFC(2)]
void SetLookDir(Vector3 aLookDir)
{
whatToControl.lookingDirection =
//Vector3.Lerp(
//whatToControl.lookingDirection
//,
aLookDir
//, Time.deltaTime)
;
}
[RFC(1)]
void SetMoveDir(Vector3 aMoveDir)
{
whatToControl.moveDirection =
//Vector3.Lerp(
//whatToControl.moveDirection
//,
aMoveDir
//, Time.deltaTime)
;
}
[RFC(3)]
void SetPos(Vector3 aPos)
{
if ((whatToControl.xForm.position - aPos).sqrMagnitude > 0.1F)
{
whatToControl.xForm.position = Vector3.Lerp(whatToControl.xForm.position, aPos, Time.deltaTime);
}
}
void Update()
{
if (remote)
{
return;
}
if (timer > sendRate)
{
timer = 0;
tno.SendQuickly(1, Target.Others, whatToControl.moveDirection);
tno.SendQuickly(2, Target.Others, whatToControl.lookingDirection);
}
tno.SendQuickly(3, Target.Others, whatToControl.xForm.position);
timer += Time.deltaTime;
CheckBool(ref commandShoot, whatToControl.commandShoot,5);
CheckBool(ref commandMeleeAttack, whatToControl.commandMeleeAttack, 6);
CheckBool(ref commandVault, whatToControl.commandVault, 7);
CheckBool(ref commandDodge, whatToControl.commandDodge, 8);
CheckBool(ref commandSwitchWeapon, whatToControl.commandSwitchWeapon, 9);
CheckBool(ref commandReloadWeapon, whatToControl.commandReloadWeapon, 10);
CheckBool(ref commandSprint, whatToControl.commandSprint, 11);
CheckBool(ref commandAimWeapon, whatToControl.commandAimWeapon, 12);
}
#endregion Methods
}