Example #1
0
    /// Update the geometry representation of the level. Used on the server
    /// for visualization.
    public void refreshMesh()
    {
        for (int i = 0; i < levelStructures.GetLength(0); i += 1)
        {
            for (int j = 0; j < levelStructures.GetLength(1); j += 1)
            {
                RegionBlock rb = getRegion(i * blockSize, j * blockSize);

                if (rb != null)
                {
                    GameObject t   = levelViewObjects[i, j];
                    MeshFilter tmf = t.GetComponent <MeshFilter>();
                    rb.convertToMesh(tmf.mesh);
                }
            }
        }
    }
Example #2
0
    /// Create an instance of the geometry representation of the level, which can
    /// then be updated using refreshMesh.
    public void convertToMesh(GameObject regionBlank, Transform transform)
    {
        for (int i = 0; i < levelStructures.GetLength(0); i += 1)
        {
            for (int j = 0; j < levelStructures.GetLength(1); j += 1)
            {
                RegionBlock rb = getRegion(i * blockSize, j * blockSize);

                if (rb != null)
                {
                    Vector3    pos = new Vector3(i * 1.0f, j * 1.0f, 0.0f);
                    GameObject t   = (GameObject)UnityEngine.Object.Instantiate(regionBlank, pos, Quaternion.identity);
                    t.transform.SetParent(transform, false);

                    MeshFilter tmf = t.GetComponent <MeshFilter>();
                    rb.convertToMesh(tmf.mesh);

                    levelViewObjects[i, j] = t;
                }
            }
        }
    }
Example #3
0
    /// Handle incoming updates from the server.
    void ServerCommandHandler(NetworkMessage netMsg)
    {
        switch (netMsg.msgType)
        {
        case LevelMsgType.LevelResponse:
            // Received an updated region block from the server. Update
            // the cache, and ensure that the local visual representation
            // is consistent.
        {
            RegionBlock rb = netMsg.ReadMessage <RegionBlock>();
//                 Debug.Log ("Server Got message: " + rb.blockSize);

            MeshFilter mf = GetComponent <MeshFilter>();
            rb.convertToMesh(mf.mesh);

            Vector2         rbpos  = rb.getPosition();
            Vector3         llbpos = new Vector3(rbpos.x, WorldManager.minLevelHeight, rbpos.y);
            LocalLevelBlock llb    = findLevelBlock(llbpos);
            if (llb == null)
            {
                llb = addLevelBlock(rb, llbpos);

                // llb should now be valid.
                llb.region.placeBlocks(llb.gobject.transform);
            }
            else
            {
                // if version is newer than the one we already have, then update it.
                if (rb.timeLastChanged > llb.region.timeLastChanged)
                {
                    llb.region = rb;
//                         Debug.Log ("Got update ..................................>");
                    llb.region.placeBlocks(llb.gobject.transform);
                }
            }

            flushRegions();
        }
        break;

        case LevelMsgType.PlayerList:
            /// Message containing list of active players.
        {
        }
        break;

        case LevelMsgType.EmoteSingleSender:
            /// Handle incoming emotes from server
        {
            SendEmoteMessageAndClientID m = netMsg.ReadMessage <SendEmoteMessageAndClientID> ();
            displayEmote(m.emoteType, m.netId);
            Debug.Log("Incoming emote to client from server from network id: " + m.netId);
        }
        break;

        case LevelMsgType.PlayerFlagRequest:
        {
            PlayerFlagMessage m = netMsg.ReadMessage <PlayerFlagMessage> ();
            if (m.removed == false)
            {
                //Do UI message to player here informing them of failure to remove flag.
            }
            if (m.removed == true)
            {
                PlayerMove player = ClientScene.localPlayers[0].gameObject.GetComponent <PlayerMove>();
                player.playerFlagPlaced = false;
            }
        }
        break;

        default:
        {
            Debug.Log("Unexpected message type in LocalWorld");
        }
        break;
        }
    }