/// <summary>
        /// Called once per frame
        /// When a new mesh is recieved, display it
        /// When L is pressed, load and send a saved Room Mesh file (used for testing without HoloLens)
        /// </summary>
        public override void Update()
        {
            // ERROR TESTING - REMOVE THIS METHOD - NOTHING SPECIAL HAPPENS IN IT ANYMORE
            base.Update();


            //    //AssetBundle object instantiation for testing purposes
            //    if (Input.GetKeyDown("i"))
            //    {
            //        int id1 = PhotonNetwork.AllocateViewID();

            //        photonView.RPC("SpawnNetworkObject", PhotonTargets.AllBuffered, transform.position, transform.rotation, id1, "Cube");
            //    }
            //}

            if (TangoDatabase.LastUpdate != DateTime.MinValue && DateTime.Compare(_lastUpdate, TangoDatabase.LastUpdate) < 0)
            {
                if (TangoDatabase.GetMeshAsBytes() != null)
                {
                    //    Create a material to apply to the mesh
                    Material meshMaterial = new Material(Shader.Find("Diffuse"));

                    //    grab the meshes in the database
                    IEnumerable <Mesh> temp = new List <Mesh>(TangoDatabase.GetMeshAsList());

                    foreach (var mesh in temp)
                    {
                        //        for each mesh in the database, create a game object to represent
                        //        and display the mesh in the scene
                        GameObject obj1 = new GameObject("tangomesh");

                        //        add a mesh filter to the object and assign it the mesh
                        MeshFilter filter = obj1.AddComponent <MeshFilter>();
                        filter.mesh = mesh;

                        //        add a mesh rendererer and add a material to it
                        MeshRenderer rend1 = obj1.AddComponent <MeshRenderer>();
                        rend1.material = meshMaterial;

                        rend1.material.shader = Shader.Find("Custom/UnlitVertexColor");
                    }
                }
                _lastUpdate = TangoDatabase.LastUpdate;
            }
        }
        private float updateTime        = 5f;                  //time tracker to send a new room list to all clients
        #endregion

        /// <summary>
        /// Called once per frame
        /// When a new mesh is recieved, display it
        /// When L is pressed, load and send a saved Room Mesh file (used for testing without HoloLens)
        /// </summary>
        public override void Update()
        {
            base.Update();

            //    //AssetBundle object instantiation for testing purposes
            //    if (Input.GetKeyDown("i"))
            //    {
            //        int id1 = PhotonNetwork.AllocateViewID();

            //        photonView.RPC("SpawnNetworkObject", PhotonTargets.AllBuffered, transform.position, transform.rotation, id1, "Cube");
            //    }
            //}

            //Check to see if a new Tango Room Mesh has been recieved and create a gameobject and render the mesh in gamespace
            if (TangoDatabase.LastUpdate != DateTime.MinValue && DateTime.Compare(_lastUpdate, TangoDatabase.LastUpdate) < 0)
            {
                for (int i = 0; i < TangoDatabase.Rooms.Count; i++)
                {
                    TangoDatabase.TangoRoom T = TangoDatabase.GetRoom(i);

                    if (TangoDatabase.ID < T.ID)
                    {
                        TangoDatabase.ID = T.ID;
                        //    Create a material to apply to the mesh
                        Material meshMaterial = new Material(Shader.Find("Diffuse"));

                        //    grab the meshes in the database
                        IEnumerable <Mesh> temp = new List <Mesh>(TangoDatabase.GetMeshAsList(T));

                        foreach (var mesh in temp)
                        {
                            //        for each mesh in the database, create a game object to represent
                            //        and display the mesh in the scene
                            GameObject obj1 = new GameObject(T.name);

                            //        add a mesh filter to the object and assign it the mesh
                            MeshFilter filter = obj1.AddComponent <MeshFilter>();
                            filter.mesh = mesh;

                            //        add a mesh rendererer and add a material to it
                            MeshRenderer rend1 = obj1.AddComponent <MeshRenderer>();
                            rend1.material = meshMaterial;

                            rend1.material.shader = Shader.Find("Custom/UnlitVertexColor");

                            obj1.tag = "Room";
                            obj1.AddComponent <TangoRoom>();

                            PhotonView parentView = PhotonView.Find(T.parentID);
                            if (parentView != null)
                            {
                                obj1.transform.SetParent(parentView.transform, false);
                            }
                        }
                    }
                }

                foreach (PhotonPlayer p in PhotonNetwork.otherPlayers)
                {
                    SendTangoRoomInfo(p.ID);
                }

                _lastUpdate = TangoDatabase.LastUpdate;
            }

            //Check if the Thread has stopped and join if so
            Thread[] TL = threads.ToArray();
            foreach (Thread T in TL)
            {
                if (T.ThreadState == ThreadState.Stopped)
                {
                    T.Join();
                    //threads.Remove(T);
                }
            }

            //decrement updateTime which controls the TangoRoomInfo sending between clients
            updateTime -= Time.deltaTime;
            if (updateTime <= 0)
            {
                SendTangoRoomInfoAll();
                updateTime = 5f;
            }
        }
Пример #3
0
        private static bool _ThreadFinished            = true;                                  //Check to see that a room request has finished
        #endregion

        //// Ensure not HoloLens

        public override void Update()
        {
            //    if (Database.LastUpdate != DateTime.MinValue && DateTime.Compare(_lastUpdate, Database.LastUpdate) < 0)
            //    {
            //        if (Database.GetMeshAsBytes() != null)
            //        {
            //            //Create a material to apply to the mesh
            //            Material meshMaterial = new Material(Shader.Find("Diffuse"));

            //            //grab the meshes in the database
            //            IEnumerable<Mesh> temp = new List<Mesh>(Database.GetMeshAsList());

            //            foreach (var mesh in temp)
            //            {
            //                //for each mesh in the database, create a game object to represent
            //                //and display the mesh in the scene
            //                GameObject obj1 = new GameObject("mesh");

            //                //add a mesh filter to the object and assign it the mesh
            //                MeshFilter filter = obj1.AddComponent<MeshFilter>();
            //                filter.mesh = mesh;

            //                //add a mesh rendererer and add a material to it
            //                MeshRenderer rend1 = obj1.AddComponent<MeshRenderer>();
            //                rend1.material = meshMaterial;
            //            }
            //        }
            //        _lastUpdate = Database.LastUpdate;
            //    }

            //    //Loading a mesh from a file for testing purposes.
            //    if (Input.GetKeyDown("l"))
            //    {
            //        //Database.UpdateMesh(MeshSaver.Load("RoomMesh"));
            //        var memoryStream = new MemoryStream(File.ReadAllBytes("RoomMesh"));
            //        this.DeleteLocalRoomModelInfo();
            //        Database.UpdateMesh(memoryStream.ToArray());
            //    }

            //    //Testcalls for the added functionality
            //    if (Input.GetKeyDown("s"))
            //    {
            //        this.SendMesh();
            //    }

            //    if (Input.GetKeyDown("d"))
            //    {
            //        this.DeleteRoomInfo();
            //    }

            //    if (Input.GetKeyDown("a"))
            //    {
            //        this.SendAddMesh();
            //    }

            //Check all current Rooms in the database and render any without a current gameobject and mesh renderer
            if (TangoDatabase.LastUpdate != DateTime.MinValue && DateTime.Compare(_lastUpdate, TangoDatabase.LastUpdate) < 0)
            {
                for (int i = 0; i < TangoDatabase.Rooms.Count; i++)
                {
                    TangoDatabase.TangoRoom T = TangoDatabase.GetRoom(i);

                    if (TangoDatabase.ID < T.ID)
                    {
                        TangoDatabase.ID = T.ID;
                        //    Create a material to apply to the mesh
                        Material meshMaterial = new Material(Shader.Find("Diffuse"));

                        //    grab the meshes in the database
                        IEnumerable <Mesh> temp = new List <Mesh>(TangoDatabase.GetMeshAsList(T));

                        foreach (var mesh in temp)
                        {
                            //        for each mesh in the database, create a game object to represent
                            //        and display the mesh in the scene
                            GameObject obj1 = new GameObject(T.name);

                            //        add a mesh filter to the object and assign it the mesh
                            MeshFilter filter = obj1.AddComponent <MeshFilter>();
                            filter.mesh = mesh;

                            //        add a mesh rendererer and add a material to it
                            MeshRenderer rend1 = obj1.AddComponent <MeshRenderer>();
                            rend1.material = meshMaterial;

                            rend1.material.shader = Shader.Find("Custom/UnlitVertexColor");

                            obj1.tag = "Room";
                            obj1.AddComponent <TangoRoom>();

                            Transform parentXform = PhotonView.Find(T.parentID).transform;
                            obj1.transform.SetParent(parentXform, false);
                        }
                    }
                }
            }

            //Check to see that no rooms are currently being recieved and then check if there is a room to request
            if (_ThreadFinished == true)
            {
                if (TangoRoomStack.Count > 0)
                {
                    ReceiveTangoMeshStack();
                }
            }

            //check to see if a thread has stopped and join it
            Thread[] TL = threads.ToArray();
            foreach (Thread T in TL)
            {
                if (T.ThreadState == ThreadState.Stopped)
                {
                    T.Join();
                    //threads.Remove(T);
                }
            }
        }
        public override void ReceiveTangoMesh(string networkConfig)
        {
            this.DeleteLocalMesh();
            var networkConfigArray = networkConfig.Split(':');

            TcpClient client = new TcpClient();

            client.Connect(IPAddress.Parse(networkConfigArray[0]), Int32.Parse(networkConfigArray[1]));

            using (var stream = client.GetStream())
            {
                byte[] data = new byte[1024];

                Debug.Log("Start receiving mesh.");
                using (MemoryStream ms = new MemoryStream())
                {
                    int numBytesRead;
                    while ((numBytesRead = stream.Read(data, 0, data.Length)) > 0)
                    {
                        ms.Write(data, 0, numBytesRead);
                    }
                    Debug.Log("Finish receiving mesh: size = " + ms.Length);
                    client.Close();

                    //DONE RECIEVING MESH FROM THE MASTER SERVER, NOW UPDATE IT

                    TangoDatabase.UpdateMesh(ms.ToArray());
                    Debug.Log("You updated the meshes in the database");
                }
            }

            client.Close();


            //CREATE AND DRAW THEM MESHES------------------------------------------------------
            Debug.Log("Checking for them meshes in ze database");

            //goes into the if statement if the database is not NULL
            if (TangoDatabase.GetMeshAsList() != null)
            {
                //Create a material to apply to the mesh
                Material meshMaterial = new Material(Shader.Find("Diffuse"));

                //grab the meshes in the database
                IEnumerable <Mesh> temp = new List <Mesh>(TangoDatabase.GetMeshAsList());

                foreach (var mesh in temp)
                {
                    //for each mesh in the database, create a game object to represent
                    //and display the mesh in the scene
                    GameObject obj1 = new GameObject("mesh");

                    //add a mesh filter to the object and assign it the mesh
                    MeshFilter filter = obj1.AddComponent <MeshFilter>();
                    filter.mesh = mesh;

                    //add a mesh rendererer and add a material to it
                    MeshRenderer rend1 = obj1.AddComponent <MeshRenderer>();
                    rend1.material = meshMaterial;
                }
            }
            else
            {
                UnityEngine.Debug.Log("YO... your mesh is empty...");
            }
            //END OF CREATING AND DRAWING THE MEESHES------------------------------------------
        }