/// <summary>
        /// Parses the networkConfig string for the clients TCP info and room name to send to the client
        /// Retrieves the room from TangoDatabase based on it's name
        /// Establishes a TCP connection with the client and sends the byte data for the room
        /// </summary>
        /// <param name="networkConfig"></param>
        void SendTangoMeshThread(string networkConfig)
        {
            var    networkConfigArray = networkConfig.Split('~');
            string name = networkConfigArray[2];

            UnityEngine.Debug.Log("Sending Tango Mesh Master Client " + name);

            TcpClient client = new TcpClient();

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

            using (NetworkStream stream = client.GetStream())
            {
                TangoDatabase.TangoRoom T = TangoDatabase.GetRoomByName(name);

                //write the parent id
                var parentData = BitConverter.GetBytes(T.parentID);
                stream.Write(parentData, 0, parentData.Length);

                var data = T._meshes;
                stream.Write(data, 0, data.Length);
                UnityEngine.Debug.Log("Mesh sent: mesh size = " + data.Length);
            }
            client.Close();

            Thread.CurrentThread.Join();
        }
        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);
                }
            }
        }
        /// <summary>
        /// When a TangoRoom is delete, remove it from the list in TangoDatabase.cs
        /// </summary>
        private void OnDestroy()
        {
            TangoDatabase.TangoRoom T = TangoDatabase.GetRoomByName(this.gameObject.name);

            TangoDatabase.DeleteRoom(T);
        }