void Start() { synchronizationContext = SynchronizationContext.Current; //メインスレッドのコンテキストを保存 receiver.LoadVRM(Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "default.vrm")); http = new HTTP("http://127.0.0.1:39451/"); http.processor = CommandProcessor; System.Diagnostics.Process.Start("http://127.0.0.1:39451/"); //IPアドレスリスト IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName()); status.ip = ""; foreach (var ip in ips) { //IPv4のみ if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { status.ip += ip.ToString() + "<br>"; } } status.ip = status.ip.Trim(); //初期化 saveData.loadvrm = new CMD_LoadVRM(); saveData.camera = new CMD_Camera(); saveData.bgcolor = new CMD_BG_Color(); //自動ログイン var config = new DVRAuthConfiguration(TokenManager.DVRSDK_ClientId, new UnitySettingStore(), new UniWebRequest(), new NewtonsoftJsonSerializer()); Authentication.Instance.Init(config); Task <bool> autologin = Authentication.Instance.TryAutoLogin(async(ok) => { if (ok) { status.DVRC_AuthState = "AUTHENTICATION_OK"; await GetAvatarsList(); } else { status.DVRC_AuthState = ""; } }); }
void Start() { synchronizationContext = SynchronizationContext.Current; //sedss_server = GetComponent<SEDSS_Server>(); //sedss_server.SetPassword(null); sedss_client = GetComponent <SEDSS_Client>(); sedss_client.SetPassword(null); var uosc = externalReceiver.gameObject.GetComponent <uOSC.uOscServer>(); uosc.enabled = false; //初期はオフにしておくことで起動時のポートを反映する server = new MemoryMappedFileServer(); server.ReceivedEvent += Server_Received; server.Start("Oredayo_UI_Connection"); Debug.Log(startTime); Application.logMessageReceived += ApplicationLogHandler; Application.logMessageReceivedThreaded += ApplicationLogHandler; Debug.Log("PipeServer started"); synchronizationContext.Post(async(arg) => { await server.SendCommandAsync(new PipeCommands.Hello { startTime = this.startTime }); }, null); //自動ログイン var config = new DVRAuthConfiguration(TokenManager.DVRSDK_ClientId, new UnitySettingStore(), new UniWebRequest(), new NewtonsoftJsonSerializer()); Authentication.Instance.Init(config); Task <bool> autologin = Authentication.Instance.TryAutoLogin(async(ok) => { if (ok) { Debug.Log("AUTHENTICATION_OK"); await server.SendCommandAsync(new PipeCommands.LoginDVRConnectResult { key = "LOGIN OK" }); await GetAvatarsList(); } }); }
private void Server_Received(object sender, DataReceivedEventArgs e) { synchronizationContext.Post(async(arg) => { //-----------システム系---------------- if (e.CommandType == typeof(PipeCommands.Hello)) { //Helloが来たらHelloを返す。すると初期値が送られてくる。 await server.SendCommandAsync(new PipeCommands.Hello { startTime = this.startTime }); Debug.Log(">Hello"); } else if (e.CommandType == typeof(PipeCommands.Bye)) { //Unity側終了処理 /* #if UNITY_EDITOR * UnityEditor.EditorApplication.isPlaying = false; #else * Application.Quit(); #endif */ Debug.Log(">Bye"); } //-----------基本設定---------------- //===========探索=========== else if (e.CommandType == typeof(PipeCommands.DiscoverRequest)) { var d = (PipeCommands.DiscoverRequest)e.Data; //探索開始 var req = GetComponent <EasyDeviceDiscoveryProtocolClient.Requester>(); req.servicePort = port; req.StartDiscover(() => { //次のデバイスに更新されないうちに取得しておく string ip = req.responseIpAddress; int port = req.responseServicePort; string name = req.deivceName; int found = req.foundDevices; //探索完了 synchronizationContext.Post(async(a) => { Debug.Log("DiscoverResponse"); await server.SendCommandAsync(new PipeCommands.DiscoverResponse { ip = ip, port = port, name = name, found = found, }); }, null); }); } //===========VRMライセンス応答=========== else if (e.CommandType == typeof(PipeCommands.VRMLicenceAnser)) { var d = (PipeCommands.VRMLicenceAnser)e.Data; if (d.Agree) { loader.Agree(); } else { loader.DisAgree(); } } //===========VRM読み込み=========== else if (e.CommandType == typeof(PipeCommands.LoadVRM)) { var d = (PipeCommands.LoadVRM)e.Data; Debug.Log("LoadVRM: " + d.filepath); //許諾画面を出す if (File.Exists(d.filepath)) { loader.LoadRequest(d.filepath, (path, bytes) => { synchronizationContext.Post((args) => { Debug.Log("Load start"); externalReceiver.LoadVRMFromData(bytes); hidePanel.SetActive(d.hide); }, null); }); //許諾応答要求を出す await server.SendCommandAsync(new PipeCommands.VRMLicenceCheck { skip = d.skip }); } } //===========DVRConnect Login=========== else if (e.CommandType == typeof(PipeCommands.LoginDVRConnect)) { var d = (PipeCommands.LoginDVRConnect)e.Data; Debug.Log("LoginDVRConnect"); synchronizationContext.Post(async(args) => { var config = new DVRAuthConfiguration(TokenManager.DVRSDK_ClientId, new UnitySettingStore(), new UniWebRequest(), new NewtonsoftJsonSerializer()); Authentication.Instance.Init(config); Authentication.Instance.Authorize( openBrowser: async(OpenBrowserResponse url) => { Application.OpenURL(url.VerificationUri); //KEYを応答する await server.SendCommandAsync(new PipeCommands.LoginDVRConnectResult { key = url.UserCode }); }, onAuthSuccess: async isSuccess => { if (isSuccess) { Debug.Log("AUTHENTICATION_OK"); await server.SendCommandAsync(new PipeCommands.LoginDVRConnectResult { key = "LOGIN OK" }); await GetAvatarsList(); } else { Debug.Log("AUTHENTICATION_FAILED"); await server.SendCommandAsync(new PipeCommands.LoginDVRConnectResult { key = "LOGIN ERROR" }); } }, onAuthError: async exception => { Debug.Log("AUTHENTICATION_FAILED"); Debug.LogError(exception); await server.SendCommandAsync(new PipeCommands.LoginDVRConnectResult { key = "LOGIN ERROR" }); }); }, null); } //===========DVRConnect Logout=========== else if (e.CommandType == typeof(PipeCommands.LogoutDVRConnect)) { var d = (PipeCommands.LogoutDVRConnect)e.Data; Debug.Log("LogoutDVRConnect"); synchronizationContext.Post(async(args) => { var config = new DVRAuthConfiguration(TokenManager.DVRSDK_ClientId, new UnitySettingStore(), new UniWebRequest(), new NewtonsoftJsonSerializer()); Authentication.Instance.Init(config); await Authentication.Instance.DoLogout(); await server.SendCommandAsync(new PipeCommands.LoginDVRConnectResult { key = "LOGOUT" }); }, null); } //===========DVRConnect Load=========== else if (e.CommandType == typeof(PipeCommands.LoadDVRConnect)) { var d = (PipeCommands.LoadDVRConnect)e.Data; Debug.Log("LoadDVRConnect : " + d.index.ToString()); synchronizationContext.Post(async(args) => { var avatars = await Authentication.Instance.Okami.GetAvatarsAsync(); var currentAvatar = avatars[d.index]; await LoadAvatarFromDVRSDK(currentAvatar); }, null); } //===========DVRConnect GetAvatar=========== else if (e.CommandType == typeof(PipeCommands.GetAvatarDVRConnect)) { Debug.Log("GetAvatarDVRConnect"); synchronizationContext.Post(async(args) => { await GetAvatarsList(); }, null); } //===========背景読み込み=========== else if (e.CommandType == typeof(PipeCommands.LoadBackground)) { var d = (PipeCommands.LoadBackground)e.Data; Debug.Log("LoadBackground: " + d.filepath); //TODO: 背景読み込み処理 if (d.filepath != null && d.filepath != "") { uWC.gameObject.SetActive(false); //VRMの場合 if (d.filepath.ToLower().EndsWith(".vrm")) { Destroy(backgroundObject); bgtexture = null; backgroundObject = null; //ファイルからモデルを読み込む //バイナリの読み込み if (File.Exists(d.filepath)) { //許諾画面を出す loader.LoadRequest(d.filepath, (path, bytes) => { //読み込み VRMImporterContext vrmImporter = new VRMImporterContext(); vrmImporter.ParseGlb(bytes); vrmImporter.LoadAsync(() => { GameObject Model = vrmImporter.Root; //backgroundObjectの下にぶら下げる backgroundObject = new GameObject(); backgroundObject.transform.SetParent(rootLockerTransform, false); backgroundObject.name = "backgroundObject"; //最後に設定されていた位置に設定 if (lastBackgroundPos != null) { if (lastBackgroundPos.cameraTaget) { //カメラターゲット時は、カメラアームに backgroundObject.transform.SetParent(cameraArm, false); } else { //そうでないときは独立した位置に backgroundObject.transform.SetParent(rootLockerTransform, false); } backgroundObject.transform.localPosition = new Vector3(lastBackgroundPos.Px, lastBackgroundPos.Py, lastBackgroundPos.Pz); backgroundObject.transform.localRotation = Quaternion.Euler(lastBackgroundPos.Rx, lastBackgroundPos.Ry, lastBackgroundPos.Rz); backgroundObject.transform.localScale = new Vector3(lastBackgroundPos.scale, lastBackgroundPos.scale, lastBackgroundPos.scale); } //その下にモデルをぶら下げる Model.transform.SetParent(backgroundObject.transform, false); vrmImporter.EnableUpdateWhenOffscreen(); vrmImporter.ShowMeshes(); }); }); //許諾応答要求を出す await server.SendCommandAsync(new PipeCommands.VRMLicenceCheck { }); } else { Debug.LogError("VRM load failed."); } } //画像の場合 else if (d.filepath.ToLower().EndsWith(".png")) { Destroy(backgroundObject); bgtexture = null; backgroundObject = null; if (File.Exists(d.filepath)) { backgroundObject = GameObject.CreatePrimitive(PrimitiveType.Quad); backgroundObject.transform.SetParent(rootLockerTransform, false); //最後に設定されていた位置に設定 if (lastBackgroundPos != null) { if (lastBackgroundPos.cameraTaget) { //カメラターゲット時は、カメラアームに backgroundObject.transform.SetParent(cameraArm, false); } else { //そうでないときは独立した位置に backgroundObject.transform.SetParent(rootLockerTransform, false); } backgroundObject.transform.localPosition = new Vector3(lastBackgroundPos.Px, lastBackgroundPos.Py, lastBackgroundPos.Pz); backgroundObject.transform.localRotation = Quaternion.Euler(lastBackgroundPos.Rx, lastBackgroundPos.Ry, lastBackgroundPos.Rz); } backgroundObjectUrl = "file://" + d.filepath; StartCoroutine("LoadTexture"); } } else { await server.SendCommandAsync(new PipeCommands.SendMessage { Message = "その背景は対応していません" }); } } } else if (e.CommandType == typeof(PipeCommands.RemoveBackground)) { Destroy(backgroundObject); backgroundObject = null; } //===========カメラ位置=========== else if (e.CommandType == typeof(PipeCommands.CameraControl)) { var d = (PipeCommands.CameraControl)e.Data; lookAtModel.zaxis = d.Rz; lookAtModel.height = d.Height; cameraArm.localPosition = new Vector3(0, d.Height, 0); cameraArm.localRotation = Quaternion.Euler(d.Rx, d.Ry, 0); camera_comp.transform.localPosition = new Vector3(0, 0, d.Zoom); camera_comp.fieldOfView = d.Fov; //ライト連動 //カメラのを持ってくる lightArm.localPosition = new Vector3(0, lookAtModel.height, 0); lightLookAtModel.height = lookAtModel.height; light_comp.transform.localPosition = new Vector3(0, 0, light_comp.transform.localPosition.z); } //===========ライト位置=========== else if (e.CommandType == typeof(PipeCommands.LightControl)) { var d = (PipeCommands.LightControl)e.Data; lightLookAtModel.height = lookAtModel.height; //カメラのを持ってくる lightLookAtModel.zaxis = d.Rz; lightArm.localPosition = new Vector3(0, lookAtModel.height, 0); light_comp.transform.localPosition = new Vector3(0, 0, d.Distance); light_comp.range = d.Range; light_comp.spotAngle = d.SpotAngle; switch (d.Type) { case PipeCommands.LightType.Directional: lightArm.localRotation = Quaternion.Euler(0, 0, 0); light_comp.transform.localRotation = Quaternion.Euler(d.Rx, d.Ry, d.Rz); lightLookAtModel.enabled = false; light_comp.type = LightType.Directional; break; case PipeCommands.LightType.Point: lightArm.localRotation = Quaternion.Euler(d.Rx, d.Ry, 0); lightLookAtModel.enabled = true; light_comp.type = LightType.Point; break; case PipeCommands.LightType.Spot: lightArm.localRotation = Quaternion.Euler(d.Rx, d.Ry, 0); lightLookAtModel.enabled = true; light_comp.type = LightType.Spot; break; default: lightArm.localRotation = Quaternion.Euler(0, 0, 0); light_comp.transform.localRotation = Quaternion.Euler(d.Rx, d.Ry, d.Rz); lightLookAtModel.enabled = false; light_comp.type = LightType.Directional; break; } } //===========背景オブジェクト位置=========== else if (e.CommandType == typeof(PipeCommands.BackgroundObjectControl)) { var d = (PipeCommands.BackgroundObjectControl)e.Data; lastBackgroundPos = d; uWC.partialWindowTitle = d.windowTtitle; if (d.windowCapture) { if (!uWC.gameObject.activeSelf) { uWC.gameObject.SetActive(true); if (backgroundObject != null) { Destroy(backgroundObject); backgroundObject = null; } } if (d.cameraTaget) { //カメラターゲット時は、カメラアームに uWC.transform.SetParent(cameraArm, false); } else { //そうでないときは独立した位置に uWC.transform.SetParent(rootLockerTransform, false); } uWC.transform.localPosition = new Vector3(d.Px, d.Py, d.Pz); uWC.transform.localRotation = Quaternion.Euler(d.Rx, d.Ry, d.Rz); uWC.scalePer1000Pixel = d.scale; } else { uWC.gameObject.SetActive(false); if (backgroundObject != null) { if (d.cameraTaget) { //カメラターゲット時は、カメラアームに backgroundObject.transform.SetParent(cameraArm, false); } else { //そうでないときは独立した位置に backgroundObject.transform.SetParent(rootLockerTransform, false); } backgroundObject.transform.localPosition = new Vector3(d.Px, d.Py, d.Pz); backgroundObject.transform.localRotation = Quaternion.Euler(d.Rx, d.Ry, d.Rz); if (bgtexture != null) { backgroundObject.transform.localScale = new Vector3(d.scale, d.scale * (float)bgtexture.height / (float)bgtexture.width, d.scale); } else { backgroundObject.transform.localScale = new Vector3(d.scale, d.scale, d.scale); } } } } //-----------詳細設定---------------- //===========EVMC4U=========== else if (e.CommandType == typeof(PipeCommands.EVMC4UControl)) { var d = (PipeCommands.EVMC4UControl)e.Data; var uosc = externalReceiver.gameObject.GetComponent <uOSC.uOscServer>(); //uOSCのポートを書き換え FieldInfo fieldInfo = typeof(uOSC.uOscServer).GetField("port", BindingFlags.NonPublic | BindingFlags.Instance); fieldInfo.SetValue(uosc, d.Port); port = d.Port; uosc.enabled = d.Enable; externalReceiver.Freeze = d.Freeze; externalReceiver.BoneFilter = d.BoneFilterValue; externalReceiver.BonePositionFilterEnable = d.BoneFilterEnable; externalReceiver.BoneRotationFilterEnable = d.BoneFilterEnable; externalReceiver.BlendShapeFilter = d.BlendShapeFilterValue; externalReceiver.BlendShapeFilterEnable = d.BlendShapeFilterEnable; } else if (e.CommandType == typeof(PipeCommands.EVMC4UTakePhotoCommand)) { var d = (PipeCommands.EVMC4UTakePhotoCommand)e.Data; GetComponent <HiResolutionPhotoCamera>().shot = true; } //===========Window=========== else if (e.CommandType == typeof(PipeCommands.WindowControl)) { var d = (PipeCommands.WindowControl)e.Data; windowManagerEx.SetThroughMouseClick(d.Transparent); windowManagerEx.SetWindowBackgroundTransparent(d.Transparent, backgroundColor); windowManagerEx.SetWindowBorder(d.NoBorder); windowManagerEx.SetWindowAlwaysTopMost(d.ForceForeground); } //===========Root位置=========== else if (e.CommandType == typeof(PipeCommands.RootPositionControl)) { var d = (PipeCommands.RootPositionControl)e.Data; cameraRootLocker.Lock = d.CameraLock; lookAtModel.enabled = d.CameraLock; lightRootLocker.Lock = d.LightLock; backgroundRootLocker.Lock = d.BackgroundLock; } //===========外部連携=========== else if (e.CommandType == typeof(PipeCommands.ExternalControl)) { var d = (PipeCommands.ExternalControl)e.Data; //TODO: OBS連動など } //===========仮想Webカメラ=========== else if (e.CommandType == typeof(PipeCommands.VirtualWebCamera)) { var d = (PipeCommands.VirtualWebCamera)e.Data; unityCapture.enabled = d.Enable; } //===========SEDSSサーバー=========== /* * else if (e.CommandType == typeof(PipeCommands.SEDSSServerControl)) * { * var d = (PipeCommands.SEDSSServerControl)e.Data; * * sedss_server.SetPassword(d.Password); * * //サーバー起動終了 * if (d.Enable) * { * ServerExchangePath = d.ExchangeFilePath; * sedss_server.StartServer(); * Debug.Log("[SEDSS Server] サーバー起動"); * } * else { * ServerExchangePath = null; * sedss_server.StopServer(); * Debug.Log("[SEDSS Server] サーバー停止"); * } * * sedss_server.OnDataUploaded = (bytes, id) => { * Debug.Log("[SEDSS Server] アップロードを受けました"); * externalReceiver.LoadVRMFromData(bytes); * return; * }; * sedss_server.OnDownloadRequest = (id) => * { * if (File.Exists(d.ExchangeFilePath)) * { * Debug.Log("[SEDSS Server] ダウンロード要求を受けました"); * byte[] data = File.ReadAllBytes(ServerExchangePath); * return data; * } * else { * Debug.LogError("[SEDSS Server] ダウンロード要求を受けましたがファイルが存在しません"); * return new byte[0]; * } * }; * } */ //===========SEDSSクライアント=========== else if (e.CommandType == typeof(PipeCommands.SEDSSClientRequestCommand)) { var d = (PipeCommands.SEDSSClientRequestCommand)e.Data; sedss_client.SetPassword(d.Password); sedss_client.SetAddress(d.Address); int port = 0; if (int.TryParse(d.Port, out port)) { sedss_client.port = port; if (d.RequestType == PipeCommands.SEDSS_RequestType.Downdload) { sedss_client.Download(d.ID, (bytes, id) => { Debug.Log("[SEDSS Client] ダウンロード完了"); externalReceiver.LoadVRMFromData(bytes); synchronizationContext.Post(async(a) => { await server.SendCommandAsync(new PipeCommands.SEDSSResult { ok = true }); hidePanel.SetActive(false); }, null); }, (err, id) => { Debug.LogError("[SEDSS Client] ダウンロード失敗(waidayoを再起動してもう一度お試しください)"); synchronizationContext.Post(async(a) => { await server.SendCommandAsync(new PipeCommands.SEDSSResult { ok = false }); hidePanel.SetActive(false); }, null); }); } else if (d.RequestType == PipeCommands.SEDSS_RequestType.Upload) { if (File.Exists(d.UploadFilePath)) { byte[] data = File.ReadAllBytes(d.UploadFilePath); sedss_client.Upload(data, d.ID, (id) => { Debug.Log("[SEDSS Client] アップロード完了"); synchronizationContext.Post(async(a) => { await server.SendCommandAsync(new PipeCommands.SEDSSResult { ok = true }); hidePanel.SetActive(false); }, null); }, (err, id) => { Debug.LogError("[SEDSS Client] アップロード失敗(waidayoを再起動してもう一度お試しください)"); synchronizationContext.Post(async(a) => { await server.SendCommandAsync(new PipeCommands.SEDSSResult { ok = false }); hidePanel.SetActive(false); }, null); }); } else { Debug.LogError("アップロードファイルが存在しません"); synchronizationContext.Post(async(a) => { await server.SendCommandAsync(new PipeCommands.SEDSSResult { ok = false }); }, null); } } else { Debug.LogError("不正なリクエスト"); synchronizationContext.Post(async(a) => { await server.SendCommandAsync(new PipeCommands.SEDSSResult { ok = false }); }, null); } } else { Debug.LogError("不正なポート番号"); synchronizationContext.Post(async(a) => { await server.SendCommandAsync(new PipeCommands.SEDSSResult { ok = false }); }, null); } } //-----------色設定---------------- //===========背景色=========== else if (e.CommandType == typeof(PipeCommands.BackgrounColor)) { var d = (PipeCommands.BackgrounColor)e.Data; Color c = new Color(d.r / 255f, d.g / 255f, d.b / 255f); backgroundColor = c; windowManagerEx.SetWindowBackgroundTransparent(false, c); } //===========ライト色=========== else if (e.CommandType == typeof(PipeCommands.LightColor)) { var d = (PipeCommands.LightColor)e.Data; light_comp.color = new Color(d.r / 255f, d.g / 255f, d.b / 255f); } //===========環境光=========== else if (e.CommandType == typeof(PipeCommands.EnvironmentColor)) { var d = (PipeCommands.EnvironmentColor)e.Data; RenderSettings.ambientLight = new Color(d.r / 255f, d.g / 255f, d.b / 255f); } //===========PostProcessing=========== else if (e.CommandType == typeof(PipeCommands.PostProcessingControl)) { var d = (PipeCommands.PostProcessingControl)e.Data; //アンチエイリアス if (d.AntiAliasingEnable) { PPSLayer.antialiasingMode = PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing; } else { PPSLayer.antialiasingMode = PostProcessLayer.Antialiasing.None; } var p = PPSVolume.sharedProfile; //ブルーム var bloom = p.GetSetting <Bloom>(); bloom.active = true; bloom.enabled.value = d.BloomEnable; bloom.intensity.value = d.BloomIntensity; bloom.threshold.value = d.BloomThreshold; //DoF var dof = p.GetSetting <DepthOfField>(); dof.active = true; dof.enabled.value = d.DoFEnable; dof.focusDistance.value = d.DoFFocusDistance; dof.aperture.value = d.DoFAperture; dof.focalLength.value = d.DoFFocusLength; switch (d.DoFMaxBlurSize) { case 1: dof.kernelSize.value = KernelSize.Small; break; case 2: dof.kernelSize.value = KernelSize.Medium; break; case 3: dof.kernelSize.value = KernelSize.Large; break; case 4: dof.kernelSize.value = KernelSize.VeryLarge; break; default: dof.kernelSize.value = KernelSize.Medium; break; } //CG var cg = p.GetSetting <ColorGrading>(); cg.active = true; cg.enabled.value = d.CGEnable; cg.temperature.value = d.CGTemperature; cg.saturation.value = d.CGSaturation; cg.contrast.value = d.CGContrast; var v = p.GetSetting <Vignette>(); v.active = true; v.enabled.value = d.VEnable; v.intensity.value = d.VIntensity; v.smoothness.value = d.VSmoothness; v.roundness.value = d.VRounded; var ca = p.GetSetting <ChromaticAberration>(); ca.active = true; ca.enabled.value = d.CAEnable; ca.intensity.value = d.CAIntensity; PPSVolume.sharedProfile = p; } else { //未対応のなにか } }, null); }
//コマンド処理 string CommandProcessor(string commandJson) { //汎用ステータス応答 if (commandJson == null) { status.connected = false; if (lastPacketTime != communicationValidator.time) { status.connected = true; lastPacketTime = communicationValidator.time; } return(JsonUtility.ToJson(status)); } //Jsonをコマンド解析 var c = JsonUtility.FromJson <CMD_Command>(commandJson); Debug.Log(c.command); //各コマンド処理 if (c.command == "Load") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_Load>(commandJson); synchronizationContext.Post(_ => { FileBrowser.HideDialog(); if (modalObject != null) { Destroy(modalObject); modalObject = null; } }, null); if (File.Exists(d.path)) { string data = File.ReadAllText(d.path); Debug.Log("Load: " + d.path); saveData = JsonUtility.FromJson <RES_SaveData>(data); return(JsonUtility.ToJson(saveData)); } else { return(JsonUtility.ToJson(new RES_Response { success = false, message = "File not found", })); } } else if (c.command == "Save") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_Save>(commandJson); synchronizationContext.Post(_ => { FileBrowser.HideDialog(); }, null); File.WriteAllText(d.path, JsonUtility.ToJson(saveData), new UTF8Encoding(false)); Debug.Log("Save: " + d.path); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "Browse") { synchronizationContext.Post(_ => { FileBrowser.SetFilters(true, new FileBrowser.Filter("json", ".json")); FileBrowser.SetDefaultFilter(".json"); StartCoroutine(ShowLoadDialogCoroutine()); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "BrowseVRM") { synchronizationContext.Post(_ => { FileBrowser.SetFilters(true, new FileBrowser.Filter("VRM", ".vrm")); FileBrowser.SetDefaultFilter(".vrm"); StartCoroutine(ShowLoadDialogCoroutineForVRM()); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "Init") { synchronizationContext.Post(_ => { FileBrowser.HideDialog(); }, null); return(JsonUtility.ToJson(new CMD_InitParam { loadvrmPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "default.vrm"), settingPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "Oredayo4V_Setting.json"), })); } else if (c.command == "AutoConnect") { status.deviceFound = false; //メインスレッドに渡す synchronizationContext.Post(_ => { requester.StartDiscover(() => { status.deviceFound = true; }); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "BG_Color") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_BG_Color>(commandJson); //記録する saveData.bgcolor = d; //メインスレッドに渡す synchronizationContext.Post(_ => { BackgroundSphere.material.color = new Color(d.r, d.g, d.b); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "LoadVRM") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_LoadVRM>(commandJson); //空パスならデフォルトを読み込む if (d.path == "") { d.path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "/default.vrm"; } //記録する saveData.loadvrm = d; if (File.Exists(d.path)) { //メインスレッドに渡す synchronizationContext.Post(_ => { FileBrowser.HideDialog(); if (modalObject != null) { Destroy(modalObject); modalObject = null; } receiver.LoadVRM(d.path); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else { return(JsonUtility.ToJson(new RES_Response { success = false, message = "File not found", })); } } else if (c.command == "LoadVRMLicence") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_LoadVRMLicence>(commandJson); //空パスならデフォルトを読み込む if (d.path == "") { d.path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "/default.vrm"; } if (File.Exists(d.path)) { //メインスレッドに渡す synchronizationContext.Post(_ => { FileBrowser.HideDialog(); byte[] bytes = File.ReadAllBytes(d.path); var context = new VRMImporterContext(); context.ParseGlb(bytes); var meta = context.ReadMeta(true); if (modalObject != null) { Destroy(modalObject); modalObject = null; } modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject; var modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>(); modalLocale.SetLocale("en"); var modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>(); modalUI.setMeta(meta); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else { return(JsonUtility.ToJson(new RES_Response { success = false, message = "File not found", })); } } else if (c.command == "Camera") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_Camera>(commandJson); //記録する saveData.camera = d; //メインスレッドに渡す synchronizationContext.Post(_ => { //カメラ制御 cameraBase.transform.localRotation = Quaternion.Euler(d.tilt, d.angle, 0); cameraBody.transform.localRotation = Quaternion.Euler(0, 180, 0); cameraBody.transform.localPosition = new Vector3(0, d.height, d.zoom); cameraBody.fieldOfView = d.fov; }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "PPS") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_PPS>(commandJson); //記録する saveData.pps = d; //メインスレッドに渡す synchronizationContext.Post(_ => { //アンチエイリアス if (d.AntiAliasing_Enable) { PPSLayer.antialiasingMode = PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing; } else { PPSLayer.antialiasingMode = PostProcessLayer.Antialiasing.None; } var p = PPSVolume.sharedProfile; //ブルーム var bloom = p.GetSetting <Bloom>(); bloom.active = true; bloom.enabled.value = d.Bloom_Enable; bloom.intensity.value = d.Bloom_Intensity; bloom.threshold.value = d.Bloom_Threshold; //DoF var dof = p.GetSetting <DepthOfField>(); dof.active = true; dof.enabled.value = d.DepthOfField_Enable; dof.focusDistance.value = d.DepthOfField_FocusDistance; dof.aperture.value = d.DepthOfField_Aperture; dof.focalLength.value = d.DepthOfField_FocusLength; switch (d.DepthOfField_MaxBlurSize) { case 1: dof.kernelSize.value = KernelSize.Small; break; case 2: dof.kernelSize.value = KernelSize.Medium; break; case 3: dof.kernelSize.value = KernelSize.Large; break; case 4: dof.kernelSize.value = KernelSize.VeryLarge; break; default: dof.kernelSize.value = KernelSize.Medium; break; } //CG var cg = p.GetSetting <ColorGrading>(); cg.active = true; cg.enabled.value = d.ColorGrading_Enable; cg.temperature.value = d.ColorGrading_Temperature; cg.saturation.value = d.ColorGrading_Saturation; cg.contrast.value = d.ColorGrading_Contrast; var v = p.GetSetting <Vignette>(); v.active = true; v.enabled.value = d.Vignette_Enable; v.intensity.value = d.Vignette_Intensity; v.smoothness.value = d.Vignette_Smoothness; v.roundness.value = d.Vignette_Rounded; var ca = p.GetSetting <ChromaticAberration>(); ca.active = true; ca.enabled.value = d.ChromaticAberration_Enable; ca.intensity.value = d.ChromaticAberration_Intensity; PPSVolume.sharedProfile = p; }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "Filter") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_Filter>(commandJson); //記録する saveData.filter = d; //メインスレッドに渡す synchronizationContext.Post(_ => { receiver.BoneFilter = d.bone; receiver.BlendShapeFilter = d.blendShape; }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "LoginDVRC") { //メインスレッドに渡す synchronizationContext.Post(_ => { Authentication.Instance.Authorize( openBrowser: url => { status.DVRC_AuthUri = url.VerificationUri; status.DVRC_AuthKey = url.UserCode; status.DVRC_AuthState = "AUTHENTICATION_REQUIRED"; }, onAuthSuccess: async isSuccess => { if (isSuccess) { status.DVRC_AuthState = "AUTHENTICATION_OK"; await GetAvatarsList(); } else { status.DVRC_AuthState = "AUTHENTICATION_FAILED"; } }, onAuthError: exception => { status.DVRC_AuthState = "AUTHENTICATION_FAILED"; Debug.LogError(exception); }); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "LogoutDVRC") { //メインスレッドに渡す synchronizationContext.Post(_ => { var config = new DVRAuthConfiguration(TokenManager.DVRSDK_ClientId, new UnitySettingStore(), new UniWebRequest(), new NewtonsoftJsonSerializer()); Authentication.Instance.Init(config); Authentication.Instance.DoLogout(); status.DVRC_AuthState = "AUTHENTICATION_LOGOUT"; }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "GetAvatarListDVRC") { //メインスレッドに渡す synchronizationContext.Post(async _ => { await GetAvatarsList(); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } else if (c.command == "LoadDVRC") { //Jsonを詳細解析 var d = JsonUtility.FromJson <CMD_LoadDVRC>(commandJson); //メインスレッドに渡す synchronizationContext.Post(async _ => { var avatars = await Authentication.Instance.Okami.GetAvatarsAsync(); var currentAvatar = avatars[d.index]; await LoadAvatarFromDVRSDK(currentAvatar); }, null); return(JsonUtility.ToJson(new RES_Response { success = true, message = "OK", })); } return(JsonUtility.ToJson(new RES_Response { success = false, message = "Command not found", })); }