Наследование: MonoBehaviour
Пример #1
0
        public static void Read(ServerBehaviour reader, int connectionID, DataStreamReader stream)
        {
            ClientMessage clientMessageType = (ClientMessage)stream.ReadByte();

            //Debug.Log(reader.name + " got message of type " + clientMessageType.ToString());

            switch (clientMessageType)
            {
            case ClientMessage.Pong:
                reader.ReadPong(connectionID);
                break;

            case ClientMessage.PlayerReady:
                reader.PlayerReady(connectionID);
                break;

            case ClientMessage.MovementInput:
                reader.ReadMovementInput(ExtractVector2(ref stream), connectionID);
                break;

            //case ClientMessage.ShootInput:
            //    reader.ShootInput(connectionID, Convert.ToBoolean(stream.ReadByte()));
            //    break;
            case ClientMessage.PlayerID:
                int val = stream.ReadInt();
                reader.AssignPlayerIDToConnection(connectionID, val);
                break;

            default:
                break;
            }
        }
Пример #2
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;
    }
Пример #3
0
    public virtual void Fire()
    {
        if (Cooldown.IsActive)
        {
            //Debug.Log(name + " is on cooldown.", this);
            return;
        }
        //Debug.Log("Fire " + name);
        if (Ammunition != null)
        {
            // Instantiate
            Projectile projectile = Instantiate(Ammunition, Muzzle.position, Muzzle.rotation);

            // Add force
            projectile.GetComponent <Rigidbody>()?.AddForce(GetComponentInParent <Rigidbody>().velocity *ParentVelocityInfluence + Muzzle.forward * ProjectileSpeed, forceMode);
            projectile.Owner = GetComponentInParent <Player>();

            if (ServerBehaviour.HasActiveInstance())
            {
                ServerBehaviour.Instance.projectiles.Add(projectile);
            }

            StartCoroutine(Cooldown.Start());
        }
    }
Пример #4
0
    protected virtual void Impact(Collision collisionData)
    {
        if (collisionData != null)
        {
            string output = "";
            if (Owner != null)
            {
                if (!CanHitOwner)
                {
                    if (collisionData.gameObject == Owner.gameObject)
                    {
                        Debug.Log(name + " can't hit owner " + Owner.name);
                        return;
                    }
                }
                output += Owner.name + " with ";
            }
            output += name;
            //Debug.Log(collisionData.gameObject.name + " was hit by " + output);
            Player playerHit = collisionData.gameObject.GetComponent <Player>();
            if (playerHit != null)
            {
                //player.TakeDamage(Damage);
                if (Owner != null)
                {
                    GameManager.Instance.PlayerTakesDamage(playerHit, Damage, Owner);
                }
                else
                {
                    GameManager.Instance.PlayerTakesDamage(playerHit, Damage);
                }
                //player.Die();
            }

            Health healthComponent = collisionData.collider.GetComponentInParent <Health>();
            if (healthComponent != null)
            {
                healthComponent.UpdateValue(healthComponent.value - Damage);
            }
        }

        impactPosition = transform.position;
        hasImpacted    = true;
        Explosive explosive = GetComponent <Explosive>();

        if (explosive != null)
        {
            explosive.Explode();
        }

        if (DisappearUponImpact)
        {
            if (ServerBehaviour.HasActiveInstance())
            {
                ServerBehaviour.Instance.SendProjectileImpact(this);
            }
            //Debug.Log("Disappear");
            gameObject.SetActive(false);
        }
    }
Пример #5
0
    public void HostGame()
    {
        ServerBehaviour s = gameObject.AddComponent <ServerBehaviour>();

        startGameButton.onClick.AddListener(ServerSend.StartGame);
        startGameButton.gameObject.SetActive(true);
        JoinGame();
    }
Пример #6
0
    public void Cmd_FinishRound()
    {
        ServerBehaviour server = GameObject.Find("GameServer").GetComponent <ServerBehaviour>();

        if (server.state == GameState.Round)
        {
            didFire = true;
            server.FinishRound(ID);
        }
    }
Пример #7
0
 // Cerco il referimento al Server
 public IEnumerator SearchSBCO()
 {
     while (refSB == null)
     {
         refSB = FindObjectOfType <ServerBehaviour>();
         yield return(null);
     }
     Debug.Log("Ho trovato Server Behaviour");
     yield break;
 }
Пример #8
0
    private void OnCollisionEnter(Collision collision)
    {
        Player player = collision.collider.attachedRigidbody?.GetComponent <Player>();

        if (ServerBehaviour.HasActiveInstance() && player != null && player != this)
        {
            Debug.Log("Found server behaviour: " + ServerBehaviour.Instance.name, ServerBehaviour.Instance);
            ServerBehaviour.Instance.PlayerCollision();
        }
    }
Пример #9
0
 private IEnumerator SearchSBCO()
 {
     while (refSB == null)
     {
         Debug.LogError("Non ho trovato refSB");
         refSB = FindObjectOfType <ServerBehaviour>();
         yield return(null);
     }
     Debug.LogError("Ho trovato refSB");
     yield break;
 }
Пример #10
0
 public static void SendAll(ServerMessage serverMessageType, ServerBehaviour sender)
 {
     if (!sender.m_Connections.IsCreated)
     {
         return;
     }
     for (int i = 0; i < sender.m_Connections.Length; i++)
     {
         Send(serverMessageType, sender, sender.m_Connections[i]);
     }
 }
Пример #11
0
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(gameObject);
     }
     else
     {
         _instance = this;
     }
     DontDestroyOnLoad(gameObject);
 }
Пример #12
0
    void Awake()
    {
        serverBehaviour                = GetComponent <ServerBehaviour>();
        serverBehaviour.addAvatar     += AddAvatar;
        serverBehaviour.removeAvatars += RemoveAvatars;

        logManager = GetComponent <LogManager>();
        //scoreCollection = new LookupCollection();

        StartCoroutine("ScaleAvatarsBasedOnScore");

        DontDestroyOnLoad(this);
    }
Пример #13
0
        public static void Send(ServerMessage serverMessageType, ServerBehaviour sender, NetworkConnection receiver)
        {
            var writer = sender.m_Driver.BeginSend(receiver);

            writer.WriteByte((byte)serverMessageType);
            //Debug.Log("Send: " + serverMessageType.ToString() + " to " + receiver.InternalId);
            switch (serverMessageType)
            {
            case ServerMessage.Ping:
            case ServerMessage.TurnStart:
            case ServerMessage.TurnEnd:
            default:
                break;

            case ServerMessage.ConnectionID:
                WriteConnectionID(sender, ref writer, receiver);
                break;

            case ServerMessage.GameStart:
                writer.WriteInt(sender.m_Connections.Length);
                break;

            case ServerMessage.GameOver:
                WriteGameOver(sender, ref writer);
                break;

            case ServerMessage.ScoreUpdate:
                WriteScoreUpdate(sender, ref writer);
                break;

            case ServerMessage.PlayerTakesDamage:
                WritePlayerTakesDamage(sender, ref writer);
                break;

            case ServerMessage.PlayerPositions:
                WriteVector3ListToStream(sender.playerPositions, ref writer);
                break;

            case ServerMessage.PlayerRotations:
                WriteVector3ListToStream(sender.playerRotations, ref writer);
                break;

            case ServerMessage.ProjectilePositions:
                WriteVector3ListToStream(sender.projectilePositions, ref writer);
                break;
                //case ServerMessage.ProjectileImpact:
                //    break;
            }

            sender.m_Driver.EndSend(writer);
        }
Пример #14
0
        private void ServerWork()
        {
            try
            {
                // Application.DoEvents();

                ServerBehaviour b = new ServerBehaviour();
                b.MessageReceived += OnMessageReceived;
                //b.SessionCompleted += OnSessionCompleted;

                _server = new Server(b);
                _server.Run();
            }
            catch (Exception exception)
            {
                using (StreamWriter newTask = new StreamWriter(ConfigurationManager.AppSettings["EmailFolderPath"] + "error.txt", false))
                {
                    newTask.WriteLine(exception.ToString());
                }
            }
        }
Пример #15
0
 public static void WriteScoreUpdate(ServerBehaviour sender, ref DataStreamWriter writer)
 {
     writer.WriteFloat(sender.latestDamageData.m_damage);
 }
Пример #16
0
 private void Start()
 {
     server = GameObject.FindGameObjectWithTag("Server").GetComponent <ServerBehaviour>();
     server.HostGameManager = this;
 }
Пример #17
0
 public ServerManager()
 {
     serverBehaviour = new ServerBehaviour(this);
     game            = new Game(this);
 }
Пример #18
0
 private static void WritePlayerTakesDamage(ServerBehaviour sender, ref DataStreamWriter writer)
 {
     writer.WriteInt(sender.latestDamageData.m_receiver.ID);
     writer.WriteInt(sender.latestDamageData.m_dealer.ID);
     writer.WriteFloat(sender.latestDamageData.m_damage);
 }
Пример #19
0
    void Awake()
    {
        serverBehaviour = GetComponent<ServerBehaviour>();
        serverBehaviour.addAvatar += AddAvatar;
        serverBehaviour.removeAvatars += RemoveAvatars;

        logManager = GetComponent<LogManager>();
        //scoreCollection = new LookupCollection();

        DontDestroyOnLoad(this);
    }
Пример #20
0
 public static void WriteGameOver(ServerBehaviour sender, ref DataStreamWriter writer)
 {
     writer.WriteInt(sender.PlayerIDWinner);
     writer.WriteInt(sender.PlayerIDSecond);
     writer.WriteInt(sender.WinnerScore);
 }
Пример #21
0
 // Server: specialized Send functions
 public static void WriteConnectionID(ServerBehaviour sender, ref DataStreamWriter stream, NetworkConnection receiver)
 {
     stream.WriteInt(receiver.InternalId);
 }