public AutomationSettingSync(IMessageSender sender) : base(sender)
        {
            var setting = AutomationSetting.Default;

            IsAutomationEnabled = new RProperty <bool>(setting.IsAutomationEnabled, v =>
            {
                if (IsReadyToReceive())
                {
                    StartReceiveInput();
                }
                else
                {
                    StopReceiveInput();
                }
            });

            AutomationPortNumber = new RProperty <int>(setting.AutomationPortNumber, i =>
            {
                if (IsReadyToReceive())
                {
                    //ポート番号が変わった場合、止めて再スタートする
                    if (_receiver.IsRunning)
                    {
                        StopReceiveInput();
                    }
                    StartReceiveInput();
                }
                else
                {
                    StopReceiveInput();
                }
            });
        }
        public WordToMotionSettingSync(IMessageSender sender, IMessageReceiver receiver) : base(sender)
        {
            var settings = WordToMotionSetting.Default;
            var factory  = MessageFactory.Instance;

            _motionRequests      = MotionRequestCollection.LoadDefault();
            _midiNoteToMotionMap = MidiNoteToMotionMap.LoadDefault();

            PreviewDataSender = new WordToMotionItemPreviewDataSender(sender);

            SelectedDeviceType = new RProperty <int>(settings.SelectedDeviceType, i => SendMessage(factory.SetDeviceTypeToStartWordToMotion(i)));
            ItemsContentString = new RProperty <string>(settings.ItemsContentString, s => SendMessage(factory.ReloadMotionRequests(s)));
            MidiNoteMapString  = new RProperty <string>(settings.MidiNoteMapString, s => SendMessage(factory.LoadMidiNoteToMotionMap(s)));
            EnablePreview      = new RProperty <bool>(false, b =>
            {
                SendMessage(factory.EnableWordToMotionPreview(b));
                if (b)
                {
                    PreviewDataSender.Start();
                }
                else
                {
                    PreviewDataSender.End();
                }
            });

            MidiNoteReceiver = new MidiNoteReceiver(receiver);
            //NOTE: このStartは通信とかではないので、すぐ始めちゃってOK
            MidiNoteReceiver.Start();


            //NOTE: この2つの呼び出しにより、必ずデフォルト設定をUnity側に通知する+シリアライズ文字列が空ではなくなる
            SaveMidiNoteMap();
            SaveMotionRequests();
        }
        public LayoutSettingSync(IMessageSender sender) : base(sender)
        {
            var s       = LayoutSetting.Default;
            var factory = MessageFactory.Instance;

            CameraFov      = new RProperty <int>(s.CameraFov, i => SendMessage(factory.CameraFov(i)));
            EnableMidiRead = new RProperty <bool>(
                s.EnableMidiRead, b => SendMessage(factory.EnableMidiRead(b))
                );
            MidiControllerVisibility = new RProperty <bool>(
                s.MidiControllerVisibility, b => SendMessage(factory.MidiControllerVisibility(b))
                );

            CameraPosition = new RProperty <string>(s.CameraPosition, v => SendMessage(factory.SetCustomCameraPosition(v)));
            DeviceLayout   = new RProperty <string>(s.DeviceLayout, v => SendMessage(factory.SetDeviceLayout(v)));

            //NOTE: ここは初期値が空なのであんまり深い意味はない。
            QuickSave1 = new RProperty <string>(s.QuickSave1);
            QuickSave2 = new RProperty <string>(s.QuickSave2);
            QuickSave3 = new RProperty <string>(s.QuickSave3);

            HidVisibility          = new RProperty <bool>(s.HidVisibility, b => SendMessage(factory.HidVisibility(b)));
            PenVisibility          = new RProperty <bool>(s.PenVisibility, b => SendMessage(factory.SetPenVisibility(b)));
            SelectedTypingEffectId = new RProperty <int>(s.SelectedTypingEffectId, i => SendMessage(factory.SetKeyboardTypingEffectType(i)));

            EnableFreeCameraMode   = new RProperty <bool>(false, b => OnEnableFreeCameraModeChanged(b));
            EnableDeviceFreeLayout = new RProperty <bool>(false, v => SendMessage(factory.EnableDeviceFreeLayout(v)));
        }
        private SaveLoadDataViewModel(RootSettingSync?rootModel, SaveFileManager model, bool isLoadMode, Action actToClose)
        {
            _rootModel    = rootModel;
            _model        = model;
            _actToClose   = actToClose;
            Items         = new ReadOnlyObservableCollection <SaveLoadFileItemViewModel>(_items);
            CancelCommand = new ActionCommand(CloseDialog);

            //NOTE: SaveモードではUIも出ないし何も使わない値なのでfalseのまま放置しとけばOK、という値
            LoadCharacterWhenSettingLoaded
                = new RProperty <bool>(_rootModel?.LoadCharacterWhenLoadInternalFile?.Value ?? false);
            LoadNonCharacterWhenSettingLoaded
                = new RProperty <bool>(_rootModel?.LoadNonCharacterWhenLoadInternalFile?.Value ?? false);

            IsLoadMode = isLoadMode;
            Refresh();
        }
        internal ExternalTrackerViewModel(
            ExternalTrackerSettingSync model,
            MotionSettingSync motionModel,
            IMessageSender sender,
            IMessageReceiver receiver
            ) : base(sender)
        {
            _model       = model;
            _motionModel = motionModel;

            //この辺はModel/VMの接続とかコマンド周りの設定
            UpdateTrackSourceType();
            model.TrackSourceType.PropertyChanged        += (_, __) => UpdateTrackSourceType();
            model.EnableExternalTracking.PropertyChanged += (_, __) => UpdateShouldNotifyMissingBlendShapeClipNames();

            MissingBlendShapeNames = new RProperty <string>(
                "", _ => UpdateShouldNotifyMissingBlendShapeClipNames()
                );

            model.FaceSwitchSettingReloaded += (_, __) =>
            {
                if (!model.IsLoading)
                {
                    LoadFaceSwitchSetting();
                }
            };
            model.Loaded += (_, __) => LoadFaceSwitchSetting();

            RefreshIFacialMocapTargetCommand = new ActionCommand(
                () => NetworkEnvironmentUtils.SendIFacialMocapDataReceiveRequest(IFacialMocapTargetIpAddress.Value)
                );
            OpenInstructionUrlCommand                = new ActionCommand(OpenInstructionUrl);
            OpenPerfectSyncTipsUrlCommand            = new ActionCommand(OpenPerfectSyncTipsUrl);
            OpenIFMTroubleShootCommand               = new ActionCommand(OpenIFMTroubleShoot);
            EndExTrackerIfNeededCommand              = new ActionCommand(EndExTrackerIfNeeded);
            ShowMissingBlendShapeNotificationCommand = new ActionCommand(ShowMissingBlendShapeNotification);
            ResetSettingsCommand = new ActionCommand(
                () => SettingResetUtils.ResetSingleCategoryAsync(_model.ResetToDefault)
                );

            //TODO: メッセージ受信の処理もモデル側案件のはず…うーん…
            receiver.ReceivedCommand += OnMessageReceived;

            LoadFaceSwitchSetting();
        }
        public LightSettingSync(IMessageSender sender) : base(sender)
        {
            var s       = LightSetting.Default;
            var factory = MessageFactory.Instance;

            //モデルのプロパティ変更=Unityへの変更通知としてバインド。
            //エフェクト関係は設定項目がシンプルなため、例外はほぼ無い(色関係のメッセージ送信がちょっと特殊なくらい)

            ImageQualityNames = new ReadOnlyObservableCollection <string>(_imageQualityNames);
            ImageQuality      = new RProperty <string>("", s => SendMessage(factory.SetImageQuality(s)));
            HalfFpsMode       = new RProperty <bool>(s.HalfFpsMode, v => SendMessage(factory.SetHalfFpsMode(v)));

            LightIntensity = new RProperty <int>(s.LightIntensity, i => SendMessage(factory.LightIntensity(i)));
            LightYaw       = new RProperty <int>(s.LightYaw, i => SendMessage(factory.LightYaw(i)));
            LightPitch     = new RProperty <int>(s.LightPitch, i => SendMessage(factory.LightPitch(i)));

            Action sendLightColor = () =>
                                    SendMessage(factory.LightColor(LightR?.Value ?? 255, LightG?.Value ?? 255, LightB?.Value ?? 255));

            LightR = new RProperty <int>(s.LightR, _ => sendLightColor());
            LightG = new RProperty <int>(s.LightG, _ => sendLightColor());
            LightB = new RProperty <int>(s.LightB, _ => sendLightColor());

            EnableShadow      = new RProperty <bool>(s.EnableShadow, b => SendMessage(factory.ShadowEnable(b)));
            ShadowIntensity   = new RProperty <int>(s.ShadowIntensity, i => SendMessage(factory.ShadowIntensity(i)));
            ShadowYaw         = new RProperty <int>(s.ShadowYaw, i => SendMessage(factory.ShadowYaw(i)));
            ShadowPitch       = new RProperty <int>(s.ShadowPitch, i => SendMessage(factory.ShadowPitch(i)));
            ShadowDepthOffset = new RProperty <int>(s.ShadowDepthOffset, i => SendMessage(factory.ShadowDepthOffset(i)));

            BloomIntensity = new RProperty <int>(s.BloomIntensity, i => SendMessage(factory.BloomIntensity(i)));
            BloomThreshold = new RProperty <int>(s.BloomThreshold, i => SendMessage(factory.BloomThreshold(i)));
            Action sendBloomColor = () =>
                                    SendMessage(factory.BloomColor(BloomR?.Value ?? 255, BloomG?.Value ?? 255, BloomB?.Value ?? 255));

            BloomR = new RProperty <int>(s.BloomR, _ => sendBloomColor());
            BloomG = new RProperty <int>(s.BloomG, _ => sendBloomColor());
            BloomB = new RProperty <int>(s.BloomB, _ => sendBloomColor());

            EnableWind   = new RProperty <bool>(s.EnableWind, b => SendMessage(factory.WindEnable(b)));
            WindStrength = new RProperty <int>(s.WindStrength, i => SendMessage(factory.WindStrength(i)));
            WindInterval = new RProperty <int>(s.WindInterval, i => SendMessage(factory.WindInterval(i)));
            WindYaw      = new RProperty <int>(s.WindYaw, i => SendMessage(factory.WindYaw(i)));
        }
        public RootSettingSync(IMessageSender sender, IMessageReceiver receiver)
        {
            AvailableLanguageNames = new ReadOnlyObservableCollection <string>(_availableLanguageNames);

            _sender = sender;

            Window          = new WindowSettingSync(sender);
            Motion          = new MotionSettingSync(sender);
            Layout          = new LayoutSettingSync(sender);
            Gamepad         = new GamepadSettingSync(sender);
            Light           = new LightSettingSync(sender);
            WordToMotion    = new WordToMotionSettingSync(sender, receiver);
            ExternalTracker = new ExternalTrackerSettingSync(sender);
            Automation      = new AutomationSettingSync(sender);

            //NOTE; LanguageSelectorとの二重管理っぽくて若干アレだがこのままで行く
            //初期値Defaultを入れることで、起動直後にPCのカルチャベースで言語を指定しなきゃダメかどうか判別する
            LanguageName = new RProperty <string>("Default", s =>
            {
                LanguageSelector.Instance.LanguageName = s;
            });
        }
        public ExternalTrackerSettingSync(IMessageSender sender) : base(sender)
        {
            var setting = ExternalTrackerSetting.Default;
            var factory = MessageFactory.Instance;

            //NOTE: ひとまず初期値を入れておくと非null保証できて都合がいい、という話
            _faceSwitchSetting = ExternalTrackerFaceSwitchSetting.LoadDefault();

            EnableExternalTracking = new RProperty <bool>(
                setting.EnableExternalTracking, b => SendMessage(factory.ExTrackerEnable(b))
                );
            EnableExternalTrackerLipSync = new RProperty <bool>(
                setting.EnableExternalTrackerLipSync, b => SendMessage(factory.ExTrackerEnableLipSync(b))
                );
            EnableExternalTrackerEmphasizeExpression = new RProperty <bool>(
                setting.EnableExternalTrackerEmphasizeExpression, b => SendMessage(factory.ExTrackerEnableEmphasizeExpression(b))
                );
            EnableExternalTrackerPerfectSync = new RProperty <bool>(
                setting.EnableExternalTrackerPerfectSync, b => SendMessage(factory.ExTrackerEnablePerfectSync(b))
                );

            TrackSourceType = new RProperty <int>(setting.TrackSourceType, i => SendMessage(factory.ExTrackerSetSource(i)));
            //NOTE: このアドレスはコマンド実行時に使うため、書き換わってもメッセージは送らない
            IFacialMocapTargetIpAddress = new RProperty <string>(setting.IFacialMocapTargetIpAddress);

            CalibrateData = new RProperty <string>(
                setting.CalibrateData, s => SendMessage(factory.ExTrackerSetCalibrateData(s))
                );

            SerializedFaceSwitchSetting = new RProperty <string>(
                setting.SerializedFaceSwitchSetting, v => SendMessage(factory.ExTrackerSetFaceSwitchSetting(v))
                );

            //NOTE: この時点で、とりあえずデフォルト設定がUnityに送られる
            SaveFaceSwitchSetting();
        }
        public MotionSettingSync(IMessageSender sender) : base(sender)
        {
            var factory = MessageFactory.Instance;
            var setting = MotionSetting.Default;

            //NOTE: 長大になってるのはプロパティの初期化仕様によるもの。半手動でテキスト変換して作ってます

            EnableNoHandTrackMode = new RProperty <bool>(setting.EnableNoHandTrackMode, v => SendMessage(factory.EnableNoHandTrackMode(v)));

            EnableFaceTracking          = new RProperty <bool>(setting.EnableFaceTracking, v => SendMessage(factory.EnableFaceTracking(v)));
            AutoBlinkDuringFaceTracking = new RProperty <bool>(setting.AutoBlinkDuringFaceTracking, v => SendMessage(factory.AutoBlinkDuringFaceTracking(v)));
            EnableBodyLeanZ             = new RProperty <bool>(setting.EnableBodyLeanZ, v => SendMessage(factory.EnableBodyLeanZ(v)));
            EnableBlinkAdjust           = new RProperty <bool>(setting.EnableBlinkAdjust, v =>
            {
                SendMessage(factory.EnableHeadRotationBasedBlinkAdjust(v));
                SendMessage(factory.EnableLipSyncBasedBlinkAdjust(v));
            });
            EnableVoiceBasedMotion            = new RProperty <bool>(setting.EnableVoiceBasedMotion, v => SendMessage(factory.EnableVoiceBasedMotion(v)));
            DisableFaceTrackingHorizontalFlip = new RProperty <bool>(setting.DisableFaceTrackingHorizontalFlip, v => SendMessage(factory.DisableFaceTrackingHorizontalFlip(v)));

            EnableWebCamHighPowerMode = new RProperty <bool>(setting.EnableWebCamHighPowerMode, v => SendMessage(factory.EnableWebCamHighPowerMode(v)));

            EnableImageBasedHandTracking = new RProperty <bool>(
                setting.EnableImageBasedHandTracking,
                v => SendMessage(factory.EnableImageBasedHandTracking(v)));
            ShowEffectDuringHandTracking = new RProperty <bool>(
                setting.ShowEffectDuringHandTracking,
                v => SendMessage(factory.ShowEffectDuringHandTracking(v)));
            DisableHandTrackingHorizontalFlip = new RProperty <bool>(
                setting.DisableHandTrackingHorizontalFlip,
                v => SendMessage(factory.DisableHandTrackingHorizontalFlip(v)));
            EnableSendHandTrackingResult = new RProperty <bool>(
                false,
                v => SendMessage(factory.EnableSendHandTrackingResult(v)));

            CameraDeviceName  = new RProperty <string>(setting.CameraDeviceName, v => SendMessage(factory.SetCameraDeviceName(v)));
            CalibrateFaceData = new RProperty <string>(setting.CalibrateFaceData, v => SendMessage(factory.SetCalibrateFaceData(v)));

            FaceDefaultFun  = new RProperty <int>(setting.FaceDefaultFun, v => SendMessage(factory.FaceDefaultFun(v)));
            FaceNeutralClip = new RProperty <string>(setting.FaceNeutralClip, v => SendMessage(factory.FaceNeutralClip(v)));
            FaceOffsetClip  = new RProperty <string>(setting.FaceOffsetClip, v => SendMessage(factory.FaceOffsetClip(v)));

            //TODO: 排他のタイミング次第でRadioButtonが使えなくなってしまうので要検証
            UseLookAtPointNone = new RProperty <bool>(setting.UseLookAtPointNone, v =>
            {
                if (v)
                {
                    SendMessage(factory.LookAtStyle(LookAtStyles.UseLookAtPointNone));
                    UseLookAtPointMousePointer?.Set(false);
                    UseLookAtPointMainCamera?.Set(false);
                }
            });

            UseLookAtPointMousePointer = new RProperty <bool>(setting.UseLookAtPointMousePointer, v =>
            {
                if (v)
                {
                    SendMessage(factory.LookAtStyle(LookAtStyles.UseLookAtPointMousePointer));
                    UseLookAtPointNone.Value = false;
                    UseLookAtPointMainCamera?.Set(false);
                }
            });

            UseLookAtPointMainCamera = new RProperty <bool>(setting.UseLookAtPointMainCamera, v =>
            {
                if (v)
                {
                    SendMessage(factory.LookAtStyle(LookAtStyles.UseLookAtPointMainCamera));
                    UseLookAtPointNone.Value         = false;
                    UseLookAtPointMousePointer.Value = false;
                }
            });

            EyeBoneRotationScale = new RProperty <int>(setting.EyeBoneRotationScale, v => SendMessage(factory.SetEyeBoneRotationScale(v)));

            EnableLipSync = new RProperty <bool>(setting.EnableLipSync, v => SendMessage(factory.EnableLipSync(v)));
            LipSyncMicrophoneDeviceName = new RProperty <string>(setting.LipSyncMicrophoneDeviceName, v => SendMessage(factory.SetMicrophoneDeviceName(v)));
            MicrophoneSensitivity       = new RProperty <int>(setting.MicrophoneSensitivity, v => SendMessage(factory.SetMicrophoneSensitivity(v)));

            EnableHidRandomTyping      = new RProperty <bool>(setting.EnableHidRandomTyping, v => SendMessage(factory.EnableHidRandomTyping(v)));
            EnableShoulderMotionModify = new RProperty <bool>(setting.EnableShoulderMotionModify, v => SendMessage(factory.EnableShoulderMotionModify(v)));
            EnableHandDownTimeout      = new RProperty <bool>(setting.EnableHandDownTimeout, v => SendMessage(factory.EnableTypingHandDownTimeout(v)));
            WaistWidth         = new RProperty <int>(setting.WaistWidth, v => SendMessage(factory.SetWaistWidth(v)));
            ElbowCloseStrength = new RProperty <int>(setting.ElbowCloseStrength, v => SendMessage(factory.SetElbowCloseStrength(v)));

            EnableFpsAssumedRightHand = new RProperty <bool>(setting.EnableFpsAssumedRightHand, v => SendMessage(factory.EnableFpsAssumedRightHand(v)));

            ShowPresentationPointer  = new RProperty <bool>(setting.ShowPresentationPointer);
            PresentationArmRadiusMin = new RProperty <int>(setting.PresentationArmRadiusMin, v => SendMessage(factory.PresentationArmRadiusMin(v)));

            LengthFromWristToTip    = new RProperty <int>(setting.LengthFromWristToTip, v => SendMessage(factory.LengthFromWristToTip(v)));
            HandYOffsetBasic        = new RProperty <int>(setting.HandYOffsetBasic, v => SendMessage(factory.HandYOffsetBasic(v)));
            HandYOffsetAfterKeyDown = new RProperty <int>(setting.HandYOffsetAfterKeyDown, v => SendMessage(factory.HandYOffsetAfterKeyDown(v)));

            EnableWaitMotion = new RProperty <bool>(setting.EnableWaitMotion, v => SendMessage(factory.EnableWaitMotion(v)));
            WaitMotionScale  = new RProperty <int>(setting.WaitMotionScale, v => SendMessage(factory.WaitMotionScale(v)));
            WaitMotionPeriod = new RProperty <int>(setting.WaitMotionPeriod, v => SendMessage(factory.WaitMotionPeriod(v)));

            KeyboardAndMouseMotionMode = new RProperty <int>(
                setting.KeyboardAndMouseMotionMode, v => SendMessage(factory.SetKeyboardAndMouseMotionMode(v))
                );
            GamepadMotionMode = new RProperty <int>(
                setting.GamepadMotionMode, v => SendMessage(factory.SetGamepadMotionMode(v))
                );
        }
Exemple #10
0
        internal MotionSettingViewModel(MotionSettingSync model, IMessageSender sender, IMessageReceiver receiver) : base(sender)
        {
            _model = model;

            ResetFaceBasicSettingCommand = new ActionCommand(
                () => SettingResetUtils.ResetSingleCategoryAsync(ResetFaceBasicSetting)
                );
            ResetFaceEyeSettingCommand = new ActionCommand(
                () => SettingResetUtils.ResetSingleCategoryAsync(_model.ResetFaceEyeSetting)
                );
            ResetFaceBlendShapeSettingCommand = new ActionCommand(
                () => SettingResetUtils.ResetSingleCategoryAsync(_model.ResetFaceBlendShapeSetting)
                );
            ResetArmMotionSettingCommand = new ActionCommand(
                () => SettingResetUtils.ResetSingleCategoryAsync(_model.ResetArmSetting)
                );
            ResetHandMotionSettingCommand = new ActionCommand(
                () => SettingResetUtils.ResetSingleCategoryAsync(_model.ResetHandSetting)
                );
            ResetWaitMotionSettingCommand = new ActionCommand(
                () => SettingResetUtils.ResetSingleCategoryAsync(_model.ResetWaitMotionSetting)
                );

            CalibrateFaceCommand = new ActionCommand(() => SendMessage(MessageFactory.Instance.CalibrateFace()));
            OpenFullEditionDownloadUrlCommand = new ActionCommand(() => UrlNavigate.Open("https://baku-dreameater.booth.pm/items/3064040"));
            OpenHandTrackingPageUrlCommand    = new ActionCommand(() => UrlNavigate.Open(LocalizedString.GetString("URL_docs_hand_tracking")));

            ShowMicrophoneVolume = new RProperty <bool>(false, b =>
            {
                SendMessage(MessageFactory.Instance.SetMicrophoneVolumeVisibility(b));
                if (!b)
                {
                    MicrophoneVolumeValue.Value = 0;
                }
            });

            _model.KeyboardAndMouseMotionMode.PropertyChanged += (_, __) => UpdateKeyboardAndMouseMotionMode();
            UpdateKeyboardAndMouseMotionMode();
            _model.GamepadMotionMode.PropertyChanged += (_, __) => UpdateGamepadMotionMode();
            UpdateGamepadMotionMode();

            _model.EyeBoneRotationScale.PropertyChanged += (_, __) => UpdateEyeRotRangeText();
            _model.EnableLipSync.PropertyChanged        += (_, __) =>
            {
                if (!_model.EnableLipSync.Value)
                {
                    ShowMicrophoneVolume.Value = false;
                }
            };

            _model.FaceNeutralClip.PropertyChanged += (_, __) =>
                                                      _blendShapeNameStore.Refresh(_model.FaceNeutralClip.Value, _model.FaceOffsetClip.Value);
            _model.FaceOffsetClip.PropertyChanged += (_, __) =>
                                                     _blendShapeNameStore.Refresh(_model.FaceNeutralClip.Value, _model.FaceOffsetClip.Value);

            //両方trueのときだけポインターを表示したいので、それのチェック
            _model.KeyboardAndMouseMotionMode.PropertyChanged += (_, __) => UpdatePointerVisibility();
            _model.ShowPresentationPointer.PropertyChanged    += (_, __) => UpdatePointerVisibility();
            //通常発生しないが、VMの初期化時点でポインター表示が必要ならそうする
            UpdatePointerVisibility();

            UpdateEyeRotRangeText();

            receiver.ReceivedCommand    += OnReceivedCommand;
            ShowInstallPathWarning.Value = InstallPathChecker.HasMultiByteCharInInstallPath();
        }