/** * IPlayerActionHandler interface. * * TODO - Consider breaking this into a delegate. */ public void HandleLocalPlayerAttack( NetworkObjectType type, Vector3 position, Quaternion orientation) { var obj = networkObjectManager.SpawnPlayerObject(0, type, position, orientation, true); // Check hit for logging purposes but dont do anything with this yet. var playerHit = obj.GetComponent <HitscanAttack>().CheckHit(true); if (playerHit != null) { clientHitSound.Play(); Debug.Log($"Local hit {playerHit.name} at ${playerHit.transform.position} server world tick ${simulation.lastServerWorldTick}"); } }
public static void SendSyncPosition(int syncObjID, NetworkObjectType type, Vector3 pos) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteLong((long)PacketType.SyncPosition); buffer.WriteLong((long)type); buffer.WriteInteger(syncObjID); buffer.WriteFloat(pos.x); buffer.WriteFloat(pos.y); buffer.WriteFloat(pos.z); SendData(buffer.ToArray()); buffer.Dispose(); }
public static void SendSyncRotation(int syncObjID, NetworkObjectType type, Quaternion rot) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteLong((long)PacketType.SyncRotation); buffer.WriteLong((long)type); buffer.WriteInteger(syncObjID); buffer.WriteFloat(rot.x); buffer.WriteFloat(rot.y); buffer.WriteFloat(rot.z); buffer.WriteFloat(rot.w); SendData(buffer.ToArray()); buffer.Dispose(); }
private static void PACKET_SyncPosition(byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); long packetnum = buffer.ReadLong(); NetworkObjectType type = (NetworkObjectType)buffer.ReadLong(); int syncObjID = buffer.ReadInteger(); float x = buffer.ReadFloat(); float y = buffer.ReadFloat(); float z = buffer.ReadFloat(); NetworkManager.UpdateSyncdObject(syncObjID, new Vector3(x, y, z)); buffer.Dispose(); }
/** * IPlayerActionHandler interface. * * TODO - Consider breaking this into a delegate. */ public void HandlePlayerAttack( Player player, NetworkObjectType type, Vector3 position, Quaternion orientation) { // Create the attack object and check for hits. var obj = networkObjectManager.SpawnPlayerObject(0, type, position, orientation); var wasHit = simulation.ProcessPlayerAttack(player, obj.GetComponent <HitscanAttack>()); // Broadcast to all players the spawned object data. var spawnObjectCmd = new NetCommand.SpawnObject { NetworkObjectState = obj.ToNetworkState(), Type = type, CreatorPlayerId = player.Id, Position = obj.transform.position, Orientation = obj.transform.rotation, WasAttackHit = wasHit, }; netChannel.BroadcastCommand(spawnObjectCmd); }
public NetworkObject SpawnPlayerObject( ushort networkId, NetworkObjectType type, Vector3 position, Quaternion orientation, bool forLocalPlayer = false) { if (type != NetworkObjectType.HITSCAN_ATTACK) { throw new NotImplementedException(); } var obj = Instantiate(hitscanAttackPrefab, position, orientation); // For local players we skip the network ID for now. // TODO - We'll still need to track this and assign it to the server network ID later. if (!forLocalPlayer) { obj.NetworkId = EnsureNetworkId(networkId); activeObjects[obj.NetworkId] = obj; } return(obj); }
public void Init() { syncData.netObj = GetComponent <NetworkObject>(); type = syncData.netObj.data.type; }