예제 #1
0
    /**
     * 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}");
        }
    }
예제 #2
0
    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();
    }
예제 #3
0
    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();
    }
예제 #4
0
    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();
    }
예제 #5
0
    /**
     * 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);
    }
예제 #6
0
    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);
    }
예제 #7
0
 public void Init()
 {
     syncData.netObj = GetComponent <NetworkObject>();
     type            = syncData.netObj.data.type;
 }