Пример #1
0
    void SpawnPlayer(DarkRiftReader reader)
    {
        Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
        Vector3 rotation = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

        uint id = reader.ReadUInt32();

        if (id == client.ID)
        {
            GameObject o = Instantiate(
                playerPrefab,
                position,
                Quaternion.Euler(rotation)
                ) as GameObject;

            BlockCharacter character = o.GetComponent <BlockCharacter>();
            character.PlayerID = id;
            character.Setup(client, blockWorld);
        }
        else
        {
            GameObject o = Instantiate(
                networkPlayerPrefab,
                position,
                Quaternion.Euler(rotation)
                ) as GameObject;

            BlockNetworkCharacter character = o.GetComponent <BlockNetworkCharacter>();
            characterManager.AddCharacter(id, character);
        }
    }
Пример #2
0
    /// <summary>
    ///     Spawns a new player from the data received from the server.
    /// </summary>
    /// <param name="reader">The reader from the server.</param>
    void SpawnPlayer(DarkRiftReader reader)
    {
        //Extract the positions
        Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
        Vector3 rotation = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

        //Extract their ID
        ushort id = reader.ReadUInt16();

        //If it's a player for us then spawn us our prefab and set it up
        if (id == client.ID)
        {
            GameObject o = Instantiate(
                playerPrefab,
                position,
                Quaternion.Euler(rotation)
                ) as GameObject;

            BlockCharacter character = o.GetComponent <BlockCharacter>();
            character.PlayerID = id;
            character.Setup(client, blockWorld);
        }
        //If it's for another player then spawn a network player and and to the manager.
        else
        {
            GameObject o = Instantiate(
                networkPlayerPrefab,
                position,
                Quaternion.Euler(rotation)
                ) as GameObject;

            BlockNetworkCharacter character = o.GetComponent <BlockNetworkCharacter>();
            characterManager.AddCharacter(id, character);
        }
    }
 /// <summary>
 ///     Adds a character to the list of those we're managing.
 /// </summary>
 /// <param name="id">The ID of the owning player.</param>
 /// <param name="character">The character to synchronize.</param>
 public void AddCharacter(ushort id, BlockNetworkCharacter character)
 {
     characters.Add(id, character);
 }