Inheritance: MonoBehaviour
コード例 #1
0
    /// <summary>
    /// spawning the Hostbehaviour
    /// </summary>
    public void SpawnHost()
    {
        string name = playerName.text;

        if (name == string.Empty)
        {
            name = "Vincent #" + Mathf.RoundToInt(UnityEngine.Random.Range(0, 1000));
        }

        GameObject go = new GameObject();
        //adding serverbehaviour and set the playbutton onclick
        ServerBehaviour serverBehaviour = go.AddComponent <ServerBehaviour>();

        UIManager.Instance.PlayButton.onClick.AddListener(serverBehaviour.StartGame);

        //clientbehaviour
        ClientBehaviour connect = go.AddComponent <ClientBehaviour>();

        if (ipAdress.text == "")
        {
            serverBehaviour.IPAdress = ipAdress.text;
            connect.IPAdress         = ipAdress.text;
        }
        go.name            = "Server + Client";
        connect.playerName = name;
    }
コード例 #2
0
ファイル: NetworkMessage.cs プロジェクト: eMsylf/Havocraft
        public static void Send(ClientMessage clientMessageType, ClientBehaviour sender)
        {
            DataStreamWriter writer = sender.m_Driver.BeginSend(sender.m_Connection);

            writer.WriteByte((byte)clientMessageType);
            Debug.LogError("Player_id: " + ClientBehaviour.player_id);

            switch (clientMessageType)
            {
            case ClientMessage.Pong:
            case ClientMessage.PlayerReady:
            default:
                break;

            case ClientMessage.MovementInput:
                WriteVector2(ref writer, sender.MovementInput);
                break;

            //case ClientMessage.ShootInput:
            //    writer.WriteByte(Convert.ToByte(sender.IsShooting));
            //    break;
            case ClientMessage.PlayerID:
                writer.WriteInt(ClientBehaviour.player_id);
                break;
            }
            sender.m_Driver.EndSend(writer);
            //AdditionalData.Dispose()
        }
コード例 #3
0
ファイル: LobbyManager.cs プロジェクト: LMichelle/Kerndev4
        public void JoinGame()
        {
            if (ipInputField.text != "")
            {
                // validate the IP adress
                bool valid = ValidateIPv4(ipInputField.text);
                // if not valid, return.
                if (!valid)
                {
                    outputLogsText.text = "The IP Adress is invalid.";
                    return;
                }
            }

            // Add the Client Behaviour
            GameObject client = new GameObject();

            clientBehaviour = client.AddComponent <ClientBehaviour>();
            client.tag      = "Client";
            client.name     = "Client";

            gameObject.GetComponent <ClientGameManager>().enabled = true;
            gameObject.GetComponent <ClientGameManager>().SetOutputText(joinMessagesText, true);
            gameObject.GetComponent <ClientGameManager>().StartClientGameManager();

            clientBehaviour.ClientStart(ipInputField.text);

            outputLogsText.text += "Joined the game.";

            // Update the UI
            lobbyUIGO.SetActive(true);
            joinUIGO.SetActive(true);
            gameObject.GetComponent <LobbyManager>().SetOutputText(joinMessagesText);
            joinOptionsGO.SetActive(true);
        }
コード例 #4
0
    public void SpawnInClient(int prefabId, int instanceId, int ownershipId, ClientBehaviour client)
    {
        var type     = (EOwnershipType)ownershipId;
        var prefab   = type == EOwnershipType.Owner ? Ghosts[prefabId].OwnerPrefab : Ghosts[prefabId].GhostPrefab;
        var instance = Instantiate(prefab, client.transform);

        if (type == EOwnershipType.Owner)
        {
            foreach (var sender in instance.Senders)
            {
                sender.InstanceId = instanceId;
                client.Senders.Add(sender);
            }
        }
        else
        {
            foreach (var reader in instance.Readers)
            {
                reader.InstanceId = instanceId;
                client.Readers.Add(reader);
            }
        }

        instance.InstanceId = instanceId;
        Instances.Add(instance);
    }
コード例 #5
0
    public void CreateClient(bool _isHost = false)
    {
        Tools.LOCAL = localToggle.isOn;
        Tools.IP    = ipField.text;

        localToggle.gameObject.SetActive(false);
        ipField.gameObject.SetActive(false);

        isHost = _isHost;

        GameObject client = new GameObject("client");

        if (isHost)
        {
            client.AddComponent <ServerBehaviour>();
        }

        client.AddComponent <DataHolder>().lobby = this;
        clientB = client.AddComponent <ClientBehaviour>();
        DontDestroyOnLoad(client);

        connectClientButton.SetActive(false);
        connectHostButton.SetActive(false);
        //setNameField.gameObject.SetActive(true);
        //setNameButton.SetActive(true);
    }
コード例 #6
0
ファイル: NetworkMessage.cs プロジェクト: eMsylf/Havocraft
        public static void Read(DataStreamReader stream, ClientBehaviour reader)
        {
            ServerMessage serverMessageType = (ServerMessage)stream.ReadByte();

            Debug.Log(reader.name + " got message of type " + serverMessageType.ToString());
            switch (serverMessageType)
            {
            case ServerMessage.ConnectionID:
                reader.SaveConnectionID(stream.ReadInt());
                break;

            case ServerMessage.Ping:
                SendPing(reader.m_Driver, reader.m_Connection);
                break;

            //case ServerMessage.Disconnection:
            //    reader.Disconnect((DisconnectionReason)stream.ReadByte());
            //break;
            case ServerMessage.GameStart:
                reader.GameStart(stream.ReadInt());
                break;

            case ServerMessage.GameOver:
                reader.GameOver(ref stream);
                break;

            case ServerMessage.TurnStart:
                reader.TurnStart();
                break;

            case ServerMessage.TurnEnd:
                reader.TurnEnd();
                break;

            case ServerMessage.ScoreUpdate:
                int score = (int)stream.ReadFloat();
                reader.ScoreUpdate(score);
                break;

            case ServerMessage.PlayerPositions:
                reader.UpdatePlayerPositions(ExtractVector3List(ref stream));
                break;

            case ServerMessage.PlayerRotations:
                reader.UpdatePlayerRotations(ExtractVector3List(ref stream));
                break;

            case ServerMessage.ProjectilePositions:
                reader.UpdateProjectilePositions(ExtractVector3List(ref stream));
                break;

            case ServerMessage.PlayerTakesDamage:
                reader.PlayerTakesDamage(ref stream);
                break;

            default:
                break;
            }
        }
コード例 #7
0
    // Client requesting to despawn
    public void RequestDespawn(int instanceId, ClientBehaviour client)
    {
        var writer = new DataStreamWriter(8, Allocator.Temp);

        writer.Write(DespawnRequestId);
        writer.Write(instanceId);
        client.Send(writer);
    }
コード例 #8
0
 void Awake()
 {
     if (instance != null)
     {
         return;
     }
     instance = this;
 }
コード例 #9
0
        void Start()
        {
            m_OfferView = FindObjectOfType <SellingInterfaceManagement>();
            m_ProductDisplayController = GameObject.FindObjectOfType <ProductDisplayController>();
            m_ScoreSystem = FindObjectOfType <ScoreSystem>();

            m_ClientData      = GetComponent <ClientData>();
            m_ClientBehaviour = GetComponent <ClientBehaviour>();
        }
コード例 #10
0
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(gameObject);
     }
     else
     {
         _instance = this;
     }
     DontDestroyOnLoad(gameObject);
 }
コード例 #11
0
 void Shoot()
 {
     if (Input.GetMouseButton(0) && bulletsCount > 0 && !reloading)
     {
         ClientBehaviour.SendShoot();
         Instantiate(ClientManager.instance.bulletObject, anchor.position, anchor.rotation);
         bulletsCount--;
         UIManager.UpdateBar(bulletsCount, 150f);
     }
     if (bulletsCount <= 0 && !reloading)
     {
         reloading = true;
         StartCoroutine(ReloadAmmo());
     }
 }
コード例 #12
0
    // Start is called before the first frame update
    void Start()
    {
        foreach (GameObject ui in UIs)
        {
            ui.SetActive(false);
        }
        ScoreText.enabled = false;
        TurnText.SetActive(false);
        GameTimer = 5f;

        // If the GameManager is instantiated (and therefore the Start method is called),
        // this means that both players have joined and the game is ready to start.
        GameReady = false;
        Client    = FindObjectOfType <ClientBehaviour>();
    }
コード例 #13
0
ファイル: LobbyManager.cs プロジェクト: LMichelle/Kerndev4
        /// <summary>
        /// Adds both a Serverbehaviour and a Clientbehaviour.
        /// </summary>
        public void HostGame()
        {
            if (ipInputField.text != "")
            {
                // validate the IP adress
                bool valid = ValidateIPv4(ipInputField.text);
                // if not valid, return.
                if (!valid)
                {
                    outputLogsText.text = "The IP Adress is invalid.";
                    return;
                }
            }

            // Add the Server Behaviour
            GameObject server = new GameObject();

            server.AddComponent <ServerBehaviour>().ServerStart(ipInputField.text);
            server.name = "Server";
            server.tag  = "Server";
            DontDestroyOnLoad(server);
            outputLogsText.text += "The room is created.";

            // Enable the HostGameManager
            gameObject.GetComponent <HostGameManager>().enabled = true;

            // Add the Client Behaviour
            GameObject client = new GameObject();

            clientBehaviour = client.AddComponent <ClientBehaviour>();
            client.name     = "Client";
            client.tag      = "Client";
            gameObject.GetComponent <ClientGameManager>().enabled = true;
            gameObject.GetComponent <ClientGameManager>().SetOutputText(hostMessagesText, true);
            gameObject.GetComponent <ClientGameManager>().StartClientGameManager();

            clientBehaviour.ClientStart(ipInputField.text);


            // Update the UI to go to the Lobby
            lobbyUIGO.SetActive(true);
            hostUIGO.SetActive(true);
            gameObject.GetComponent <LobbyManager>().SetOutputText(hostMessagesText);
            hostOptionsGO.SetActive(true);
        }
コード例 #14
0
    /// <summary>
    /// Spawning the Clientbehaviour for
    /// </summary>
    public void SpawnConnect()
    {
        string name = playerName.text;

        if (name == string.Empty)
        {
            name = "Vincent #" + Mathf.RoundToInt(UnityEngine.Random.Range(0, 1000));
        }
        GameObject      go      = new GameObject();
        ClientBehaviour connect = go.AddComponent <ClientBehaviour>();

        if (ipAdress.text != "")
        {
            connect.IPAdress = ipAdress.text;
        }

        go.name            = "ClientBehaviour";
        connect.playerName = name;
    }
コード例 #15
0
    // Client requesting to spawn
    public void RequestSpawn(int prefabId, ClientBehaviour client, Vector3 position, Quaternion rotation)
    {
        var writer = new DataStreamWriter(36, Allocator.Temp);

        writer.Write(SpawnRequestId);
        writer.Write(prefabId);

        byte[] buff = new byte[sizeof(float) * 7];
        Buffer.BlockCopy(BitConverter.GetBytes(position.x), 0, buff, 0 * sizeof(float), sizeof(float));
        Buffer.BlockCopy(BitConverter.GetBytes(position.y), 0, buff, 1 * sizeof(float), sizeof(float));
        Buffer.BlockCopy(BitConverter.GetBytes(position.z), 0, buff, 2 * sizeof(float), sizeof(float));

        Buffer.BlockCopy(BitConverter.GetBytes(rotation.x), 0, buff, 3 * sizeof(float), sizeof(float));
        Buffer.BlockCopy(BitConverter.GetBytes(rotation.y), 0, buff, 4 * sizeof(float), sizeof(float));
        Buffer.BlockCopy(BitConverter.GetBytes(rotation.z), 0, buff, 5 * sizeof(float), sizeof(float));
        Buffer.BlockCopy(BitConverter.GetBytes(rotation.w), 0, buff, 6 * sizeof(float), sizeof(float));

        writer.Write(buff);

        client.Send(writer);
    }
コード例 #16
0
    private IEnumerator CallRandomClientCoroutine()
    {
        ClientRulesManager.Instance.EvaluateRules();

        if (Clients.Count == 0)
        {
            Debug.Log("No more clients");
            yield break;
        }

        GameObject randomClient = null;

        do
        {
            randomClient = Clients.GetRandom();
        }while ((
                    randomClient == lastClient ||
                    (ClientsVisitedCount == 0 && randomClient.GetComponent <ThiefBehaviour>() != null)
                    ) &&
                Clients.Count > 1);

        lastClient = randomClient;
        ClientBehaviour client = randomClient.GetComponent <ClientBehaviour>();

        client.TargetPosition = ExitPosition;
        yield return(new WaitForSeconds(UnityEngine.Random.Range(3f, 4f)));

        client.Paused = true;

        ActiveClient          = randomClient;
        client.TargetPosition = ActivePosition;
        client.Paused         = false;

        callCoroutine = null;
        ++ClientsVisitedCount;
    }
コード例 #17
0
 public ClientManager()
 {
     clientBehaviour = new ClientBehaviour(this);
 }
コード例 #18
0
 public void Die()
 {
     ClientBehaviour.SendDie();
     RestorePosition();
 }
コード例 #19
0
 public void StartClientGameManager()
 {
     AllClientsList  = new List <Client>();
     clientBehaviour = GameObject.FindGameObjectWithTag("Client").GetComponent <ClientBehaviour>();
     clientBehaviour.ClientGameManager = this;
 }
コード例 #20
0
 public void NewInClient(int prefabId, int instanceId, int ownershipId, ClientBehaviour client)
 {
     Spawner.SpawnInClient(prefabId, instanceId, ownershipId, client);
 }
コード例 #21
0
ファイル: SideMenu.cs プロジェクト: GHendrikx/Kernmodule4-2
 // Start is called before the first frame update
 private void Start()
 {
     clientBehaviour = FindObjectOfType <ClientBehaviour>();
     leaveButton.onClick.AddListener(() => SendLeaveRequest());
     leaveButton.gameObject.SetActive(false);
 }