Пример #1
0
    public void SendGeneralUpdate()
    {
        if (isConnection() /* && Input.GetKeyDown(KeyCode.U)*/)
        {
            //Debug.Log("Trying to update client on " + watchList.Count + " objects");

            //we have switched to a watch list instead of a queue
            //since this is a dictionary element we need to iterate through
            //using foreach and then referring to the id and Gameobject as
            //kvp.Key and kvp.Value
            DemoCoder encoder = new DemoCoder(1024);
            Henge     henge   = GameObject.Find("Henge").GetComponent <Henge>();
            encoder.addPortal(henge.GetRuneState(), henge.transform);
            // We have removed empty, because we are always sending the henge information
            foreach (KeyValuePair <int, GameObject> kvp in watchList)
            {
                //Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);

                if (encoder.isFull())
                {
                    break;
                }
                //int id = gameObject.GetComponent<NetworkIdentity>().getObjectId();
                EnemyHealth eh = kvp.Value.GetComponent <EnemyHealth>();
                if (eh != null)
                {
                    encoder.addEnemyUpdate(kvp.Key, eh.GetHealth(), kvp.Value.transform);
                }
                else
                {
                    Debug.LogError("Failed to get the Enemy Health for id " + kvp.Key);
                    encoder.addEnemyUpdate(kvp.Key, -1, kvp.Value.transform);
                }
            }

            byte error3;
            foreach (KeyValuePair <int, GameObject> kvp in ARPlayers)
            {
                NetworkTransport.Send(socketId, kvp.Key, myUpdateChannelId, encoder.getArray(), 1024, out error3);
            }
        }
    }