Exemplo n.º 1
0
        public void SendAddObjectToColleciton(AddToCollectionInfo addToCollectionInfo)
        {
            string collectionName = addToCollectionInfo.collectionName;

            if (!SyncData.collectionNodes.ContainsKey(collectionName))
            {
                NetCommand addCollectionCommand = MixerUtils.BuildAddCollecitonCommand(collectionName);
                AddCommand(addCollectionCommand);
            }

            NetCommand commandAddObjectToCollection = MixerUtils.BuildAddObjectToCollecitonCommand(addToCollectionInfo);

            AddCommand(commandAddObjectToCollection);
            if (!SyncData.sceneCollections.Contains(collectionName))
            {
                NetCommand commandAddCollectionToScene = MixerUtils.BuildAddCollectionToScene(collectionName);
                AddCommand(commandAddCollectionToScene);
            }
        }
Exemplo n.º 2
0
        void Run()
        {
            while (alive)
            {
                NetCommand command = ReadMessage();
                if (command != null)
                {
                    if (command.messageType == MessageType.ClientId ||
                        command.messageType == MessageType.ClientUpdate ||
                        command.messageType == MessageType.ListAllClients ||
                        command.messageType > MessageType.Command)
                    {
                        lock (this)
                        {
                            if (command.messageType == MessageType.ClientIdWrapper)
                            {
                                UnpackFromClientId(command, ref receivedCommands);
                            }
                            else
                            {
                                receivedCommands.Add(command);
                            }
                        }
                    }
                }

                lock (this)
                {
                    if (pendingCommands.Count > 0)
                    {
                        foreach (NetCommand pendingCommand in pendingCommands)
                        {
                            WriteMessage(pendingCommand);
                        }
                        pendingCommands.Clear();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void JoinRoom(string roomName)
        {
            byte[] nameBuffer         = Converter.StringToBytes(roomName);
            byte[] mockVersionBuffer  = Converter.StringToBytes("ignored");
            byte[] versionCheckBuffer = Converter.BoolToBytes(true);
            byte[] buffer             = Converter.ConcatenateBuffers(new List <byte[]> {
                nameBuffer, mockVersionBuffer, mockVersionBuffer, versionCheckBuffer
            });
            NetCommand command = new NetCommand(buffer, MessageType.JoinRoom);

            AddCommand(command);

            string json = VRtistMixer.CreateClientNameAndColor();

            if (null == json)
            {
                return;
            }
            NetCommand commandClientInfo = new NetCommand(Converter.StringToBytes(json), MessageType.SetClientCustomAttribute);

            AddCommand(commandClientInfo);
        }
Exemplo n.º 4
0
        public bool UnpackFromClientId(NetCommand command, ref List <NetCommand> commands)
        {
            int    index    = 0;
            string masterId = Converter.GetString(command.data, ref index);

            // For debug purpose (unity in editor mode when networkSettings.master is empty)
            string currentMasterId = VRtistMixer.GetMasterId();

            if (null == currentMasterId || currentMasterId.Length == 0)
            {
                VRtistMixer.SetMasterId(masterId);
            }

            if (masterId != VRtistMixer.GetMasterId())
            {
                return(false);
            }

            int remainingData = command.data.Length - index;

            while (remainingData > 0)
            {
                int dataLength = Converter.GetInt(command.data, ref index);
                remainingData -= dataLength + sizeof(int);

                dataLength -= sizeof(int);
                int    messageType = Converter.GetInt(command.data, ref index);
                byte[] newBuffer   = new byte[dataLength];

                Buffer.BlockCopy(command.data, index, newBuffer, 0, dataLength);
                index += dataLength;

                NetCommand newCommand = new NetCommand(newBuffer, (MessageType)messageType);
                commands.Add(newCommand);
            }

            return(true);
        }
Exemplo n.º 5
0
        public void SendDuplicate(DuplicateInfos duplicate)
        {
            NetCommand command = MixerUtils.BuildDuplicateCommand(root, duplicate);

            AddCommand(command);
        }
Exemplo n.º 6
0
        public void SendToTrash(SendToTrashInfo sendToTrash)
        {
            NetCommand command = MixerUtils.BuildSendToTrashCommand(root, sendToTrash);

            AddCommand(command);
        }
Exemplo n.º 7
0
        public void SendMaterial(Material material)
        {
            NetCommand command = MixerUtils.BuildMaterialCommand(material);

            AddCommand(command);
        }
Exemplo n.º 8
0
        public void SendQueryObjectData(string name)
        {
            NetCommand command = MixerUtils.BuildSendQueryAnimationData(name);

            AddCommand(command);
        }
Exemplo n.º 9
0
        public void SendShotManagerAction(ShotManagerActionInfo info)
        {
            NetCommand command = MixerUtils.BuildSendShotManagerAction(info);

            AddCommand(command);
        }
Exemplo n.º 10
0
        public void SendBlenderSave()
        {
            NetCommand command = MixerUtils.BuildSendBlenderSave();

            AddCommand(command);
        }
Exemplo n.º 11
0
        public void SendSky(SkySettings skyInfo)
        {
            NetCommand command = MixerUtils.BuildSkyCommand(skyInfo);

            AddCommand(command);
        }
Exemplo n.º 12
0
        public void SendAddObjectToScene(AddObjectToSceneInfo addObjectToScene)
        {
            NetCommand command = MixerUtils.BuildAddObjectToScene(addObjectToScene);

            AddCommand(command);
        }
Exemplo n.º 13
0
        public void SendCamera(CameraInfo cameraInfo)
        {
            NetCommand command = MixerUtils.BuildCameraCommand(root, cameraInfo);

            AddCommand(command);
        }
Exemplo n.º 14
0
        public void SendLight(LightInfo lightInfo)
        {
            NetCommand command = MixerUtils.BuildLightCommand(root, lightInfo);

            AddCommand(command);
        }
Exemplo n.º 15
0
        public void SendAddLookAtConstraint(GameObject gobject, GameObject target)
        {
            NetCommand command = MixerUtils.BuildSendAddLookAtConstraintCommand(gobject, target);

            AddCommand(command);
        }
Exemplo n.º 16
0
        public void SendEmpty(Transform transform)
        {
            NetCommand command = MixerUtils.BuildEmptyCommand(root, transform);

            AddCommand(command);
        }
Exemplo n.º 17
0
        public void SendAssignMaterial(AssignMaterialInfo info)
        {
            NetCommand command = MixerUtils.BuildAssignMaterialCommand(info);

            AddCommand(command);
        }
Exemplo n.º 18
0
        public void RestoreFromTrash(RestoreFromTrashInfo restoreFromTrash)
        {
            NetCommand command = MixerUtils.BuildRestoreFromTrashCommand(root, restoreFromTrash);

            AddCommand(command);
        }
Exemplo n.º 19
0
        public void SendRename(RenameInfo rename)
        {
            NetCommand command = MixerUtils.BuildRenameCommand(root, rename);

            AddCommand(command);
        }
Exemplo n.º 20
0
        public void SendTransform(Transform transform)
        {
            NetCommand command = MixerUtils.BuildTransformCommand(transform);

            AddCommand(command);
        }
Exemplo n.º 21
0
        public void SendMesh(MeshInfos meshInfos)
        {
            NetCommand command = MixerUtils.BuildMeshCommand(root, meshInfos);

            AddCommand(command);
        }
Exemplo n.º 22
0
        public void SendClearAnimations(ClearAnimationInfo info)
        {
            NetCommand command = MixerUtils.BuildSendClearAnimations(info);

            AddCommand(command);
        }
Exemplo n.º 23
0
        public void SendObjectVisibility(Transform transform)
        {
            NetCommand command = MixerUtils.BuildObjectVisibilityCommand(transform);

            AddCommand(command);
        }
Exemplo n.º 24
0
        public void SendBlenderBank(BlenderBankInfo info)
        {
            NetCommand command = MixerUtils.BuildSendBlenderBank(info);

            AddCommand(command);
        }
Exemplo n.º 25
0
        public void SendMoveKeyframe(MoveKeyInfo data)
        {
            NetCommand command = MixerUtils.BuildSendMoveKey(data);

            AddCommand(command);
        }
Exemplo n.º 26
0
        public void SendFrameStartEnd(FrameStartEnd range)
        {
            NetCommand command = MixerUtils.BuildSendFrameStartEndCommand(range.start, range.end);

            AddCommand(command);
        }
Exemplo n.º 27
0
        public void SendDelete(DeleteInfo deleteInfo)
        {
            NetCommand command = MixerUtils.BuildDeleteCommand(root, deleteInfo);

            AddCommand(command);
        }
Exemplo n.º 28
0
        public void SendAnimationCurve(CurveInfo data)
        {
            NetCommand command = MixerUtils.BuildSendAnimationCurve(data);

            AddCommand(command);
        }
Exemplo n.º 29
0
        public void Connect()
        {
            connected = false;
            string[] args = System.Environment.GetCommandLineArgs();
#if UNITY_EDITOR
            // For debug purpose use the network settings
            VRtistMixer.GetNetworkData(ref hostname, ref room, ref port, ref master, ref userName, ref userColor);
#else
            hostname = null;
#endif

            // Read command line
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "--room")
                {
                    room = args[i + 1];
                }
                if (args[i] == "--hostname")
                {
                    hostname = args[i + 1];
                }
                if (args[i] == "--port")
                {
                    Int32.TryParse(args[i + 1], out port);
                }
                if (args[i] == "--master")
                {
                    master = args[i + 1];
                }
                if (args[i] == "--username")
                {
                    userName = args[i + 1];
                }
                if (args[i] == "--usercolor")
                {
                    ColorUtility.TryParseHtmlString(args[i + 1], out userColor);
                }
            }

#if UNITY_EDITOR
            VRtistMixer.SetNetworkData(room, master, userName, userColor);
#endif

            if (null == hostname)
            {
                return;
            }

            IPAddress ipAddress = GetIpAddressFromHostname(hostname);
            if (null == ipAddress)
            {
                return;
            }

            IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);

            // Create a TCP/IP  socket.
            socket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            // Connect the socket to the remote endpoint. Catch any errors.
            try
            {
                socket.Connect(remoteEP);
            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                return;
            }
            catch (SocketException se)
            {
                Console.WriteLine("SocketException : {0}", se.ToString());
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception : {0}", e.ToString());
                return;
            }

            JoinRoom(room);
            connected = true;

            NetCommand command = new NetCommand(new byte[0], MessageType.ClientId);
            AddCommand(command);

            NetCommand commandListClients = new NetCommand(new byte[0], MessageType.ListAllClients);
            AddCommand(commandListClients);

            thread = new Thread(new ThreadStart(Run));
            thread.Start();
        }