상속: 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
파일: Weapon.cs 프로젝트: eMsylf/Havocraft
    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);
 }