예제 #1
0
        private void Execute(SimpleTcpMessage message)
        {
            switch (message.type)
            {
            case Message.Calibration:
            {
                var json    = message.GetString();
                var package = JsonUtility.FromJson <Package>(json);

                VirtualUtility.MatchAndApplyCalibrations(this.m_Environment, package.calibrations);
                this.m_Environment.SetOutputTarget(package.outputTarget);

                try
                {
                    File.WriteAllText(GetPersistentCalibrationFilePath(), json);
                } catch {
                    Debug.LogError("Failed to write calibration to disk.", this);
                }

                goto case Message.Sync;
            }

            case Message.Sync:
            {
                var calibrations         = VirtualUtility.CollectCalibrations(this.m_Environment);
                var highestActiveDisplay = VirtualUtility.GetHighestVirtualDisplay(calibrations);
                var package = new Package(DateTime.Now, this.m_Environment.outputTarget, highestActiveDisplay, calibrations);
                var json    = JsonUtility.ToJson(package);

                this.m_Server.SendMessage(new SimpleTcpMessage(Message.Calibration, json));
                this.m_Server.SendMessage(new SimpleTcpMessage(Message.ShowHelpers, this.showHelpers));
                this.m_Server.SendMessage(new SimpleTcpMessage(Message.LockCameras, this.m_Environment.lockCameras));
                this.m_Server.SendMessage(new SimpleTcpMessage(Message.OnlyCameraDisplay, this.m_RenderSingleCameraDisplay));
                break;
            }

            case Message.ShowHelpers:
                this.showHelpers = message.GetBool();
                this.m_Server.SendMessage(new SimpleTcpMessage(Message.ShowHelpers, this.showHelpers));
                break;

            case Message.LockCameras:
                this.m_Environment.lockCameras = message.GetBool();
                if (this.m_Environment.lockCameras)
                {
                    this.m_Environment.LockCamerasToPosition(this.m_Environment.center);
                }
                this.m_Server.SendMessage(new SimpleTcpMessage(Message.LockCameras, this.m_Environment.lockCameras));
                break;

            case Message.OnlyCameraDisplay:
                RenderSingleCamera(message.GetInt());
                this.m_Server.SendMessage(new SimpleTcpMessage(Message.OnlyCameraDisplay, this.m_RenderSingleCameraDisplay));
                break;

            default:
                Debug.LogWarning("Received unknown calibration message: " + message.type, this);
                break;
            }
        }
예제 #2
0
 public void Start()
 {
     // Try to load the latest calibration in the standalone,
     // so that we do not need to connect with the server everytime.
     if (!Application.isEditor && TryLoadCalibrationsFromDisk(out VirtualOutputTarget outputTarget,
                                                              out VirtualCamera.Calibration[] calibrations))
     {
         VirtualUtility.MatchAndApplyCalibrations(this.m_Environment, calibrations);
         this.m_Environment.SetOutputTarget(outputTarget);
     }
 }