Example #1
0
        public static void SaveSettings()
        {
            var configs = new OSCEditorConfigs();

            foreach (var receiver in _receivers)
            {
                var receiverConfig = new OSCEditorReceiverConfig();
                receiverConfig.LocalPort   = receiver.LocalPort;
                receiverConfig.AutoConnect = receiver.IsStarted;

                configs.Receivers.Add(receiverConfig);
            }

            foreach (var transmitter in _transmitters)
            {
                var transmitterConfig = new OSCEditorTransmitterConfig();
                transmitterConfig.RemoteHost    = transmitter.RemoteHost;
                transmitterConfig.RemotePort    = transmitter.RemotePort;
                transmitterConfig.UseBundle     = transmitter.UseBundle;
                transmitterConfig.AutoConnect   = transmitter.IsStarted;
                transmitterConfig.LocalPortMode = transmitter.LocalPortMode;
                transmitterConfig.LocalPort     = transmitter.LocalPort;

                configs.Transmitters.Add(transmitterConfig);
            }

            foreach (var component in _components)
            {
                var componentType = component.GetType();

                var componentConfig = new OSCEditorComponentConfig();
                componentConfig.Type   = componentType.AssemblyQualifiedName;
                componentConfig.Active = component.Active;
                componentConfig.Guid   = OSCEditorUtils.GetTypeGUID(componentType);

                var receiverComponent = component as OSCEditorReceiverComponent;
                if (receiverComponent != null && receiverComponent.Receiver != null)
                {
                    componentConfig.Index = _receivers.IndexOf(receiverComponent.Receiver);
                }
                else
                {
                    var transmitterComponent = component as OSCEditorTransmitterComponent;
                    if (transmitterComponent != null && transmitterComponent.Transmitter != null)
                    {
                        componentConfig.Index = _transmitters.IndexOf(transmitterComponent.Transmitter);
                    }
                }

                configs.Components.Add(componentConfig);
            }

            if (File.Exists(_configsPath))
            {
                File.Delete(_configsPath);
            }

            File.WriteAllText(_configsPath, JsonUtility.ToJson(configs, true));
        }
Example #2
0
        static OSCEditorManager()
        {
            var directory = Path.GetDirectoryName(_configsPath);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            if (!File.Exists(_configsPath))
            {
                var configs = new OSCEditorConfigs();

                configs.Transmitters.Add(new OSCEditorTransmitterConfig
                {
                    RemoteHost    = "127.0.0.1",
                    RemotePort    = 7100,
                    UseBundle     = false,
                    AutoConnect   = true,
                    LocalHostMode = OSCLocalHostMode.Any,
                    LocalHost     = "0.0.0.0",
                    LocalPortMode = OSCLocalPortMode.FromRemotePort,
                    LocalPort     = 7100
                });

                configs.Receivers.Add(new OSCEditorReceiverConfig
                {
                    LocalHostMode = OSCLocalHostMode.Any,
                    LocalHost     = "0.0.0.0",
                    LocalPort     = 7100,
                    AutoConnect   = true
                });

                File.WriteAllText(_configsPath, JsonUtility.ToJson(configs));
            }

            var componentsTypes = OSCEditorUtils.GetTypes(typeof(OSCEditorComponent));

            foreach (var componentType in componentsTypes)
            {
                if (componentType.IsAbstract)
                {
                    continue;
                }

                _components.Add((OSCEditorComponent)Activator.CreateInstance(componentType));
            }

            LoadSettings();
        }