void Start() { Globle.LangController = LangController; Globle.AddDataLog("Main", LangController.GetLang("LOG.StartVersion", Globle.APPVersion, Globle.APPBuild)); var ipaddresses = Dns.GetHostAddresses(Dns.GetHostName()); int i = 1; foreach (IPAddress ipaddress in ipaddresses) { if (ipaddress.AddressFamily == AddressFamily.InterNetwork) { Globle.AddDataLog("Main", LangController.GetLang("LOG.AvailableIP", i.ToString(), ipaddress.ToString())); i++; } } Globle.AddDataLog("Main", LangController.GetLang("LOG.SystemLoaded")); Application.targetFrameRate = 60; //自动启动WebSocket和DX Load(); SettingPanelController.ResolutionRatioX.text = MainStorage.ResolutionRatioX.ToString(); SettingPanelController.ResolutionRatioY.text = MainStorage.ResolutionRatioY.ToString(); GetComponent <DXHelper>().renderTextureHeight = MainStorage.ResolutionRatioY; GetComponent <DXHelper>().renderTextureWidth = MainStorage.ResolutionRatioX; MainPanelController.WebSocketToggle.isOn = true; MainPanelController.DXWindowToggle.isOn = true; }
public async void P2PClientStart(string uritext) { try { Globle.AddDataLog("WSC", Globle.LangController.GetLang("LOG.WSCClientStarting")); var uri = new Uri(uritext); P2Pclient = new AWebSocketClient(uri); var addresses = System.Net.Dns.GetHostAddresses(uri.Host); if (addresses.Length == 0) { throw new ArgumentException( Globle.LangController.GetLang("LOG.WSCClientIPFailed"), "" ); } await P2Pclient.ConnectAsync(addresses[0], uri.Port); if (P2Pclient.IsConnected) { P2PClientStatus = true; Globle.AddDataLog("WSC", Globle.LangController.GetLang("LOG.WSCClientStarted")); } else { P2PClientSwitch.isOn = false; Globle.AddDataLog("WSC", Globle.LangController.GetLang("LOG.WSCClientStartedFailed")); } } catch (Exception ex) { P2PClientSwitch.isOn = false; Globle.AddDataLog("WSC", Globle.LangController.GetLang("LOG.WSCClientException", ex.Message)); } }
public SaveArrayInfo LoadUserData(string path) { try { var savePath = path + "/AMGSettings.json"; if (System.IO.File.Exists(savePath)) { StreamReader sr = new StreamReader(savePath, Encoding.Default); String line = sr.ReadToEnd(); sr.Close(); SaveArrayInfo arrayInfo = JsonConvert.DeserializeObject <SaveArrayInfo>(line); Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelConfigLoadSuccess")); return(arrayInfo); } else { Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelConfigUnisset")); return(null); } } catch (Exception err) { Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelConfigLoadException", err.Message)); return(null); } }
public void OnModelSelectionDropdownBoxSelected(int id) { if (id != 0) { Globle.AddDataLog("Model", LangController.GetLang("LOG.SelectModel", ModelSelectionDropdownBox.selectedText.text)); ModelPanelController.SetValueFromModel(); var model = GetModelObjectSelected(); if (model != null) { if (model.GetComponent <Live2DModelController>() != null) { ModelIPDropdownBox.selectedText.text = model.GetComponent <Live2DModelController>().ConnectionUUID; } else if (model.GetComponent <VRMModelController>() != null) { ModelIPDropdownBox.selectedText.text = model.GetComponent <VRMModelController>().ConnectionUUID; } } } else { ModelIPDropdownBox.selectedText.text = "/"; } ResetModelAdvancedPanel(); ResetShortcutPanel(); }
public void GetModelFromName(string name, GameObject parent, GameObject MouseObject) { try { string ModelPath = Application.streamingAssetsPath + "../../../Data/vrm/" + name + ".vrm"; if (System.IO.File.Exists(ModelPath)) { var bytes = File.ReadAllBytes(ModelPath); var context = new VRMImporterContext(); context.ParseGlb(bytes); var metaObject = context.ReadMeta(false); /*Debug.LogFormat("meta: title:{0}", metaObject.Title); * Debug.LogFormat("meta: version:{0}", metaObject.Version); * Debug.LogFormat("meta: author:{0}", metaObject.Author); * Debug.LogFormat("meta: exporterVersion:{0}", metaObject.ExporterVersion);*/ var modelD = Path.GetDirectoryName(ModelPath); context.LoadAsync(() => { OnLoaded(context, parent, metaObject, modelD, MouseObject); }, OnError); } else { throw new Exception(Globle.LangController.GetLang("LOG.FileUnisset")); } } catch (Exception err) { Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelAddationException", err.Message)); } }
public void SaveUserData(string path, string LastDUId, Dictionary <string, string> userdict, Dictionary <string, string> otherdict, Dictionary <string, string> locationdict, Dictionary <string, Dictionary <string, string> > shortcutPair) { try { SaveArrayInfo arrayInfo = new SaveArrayInfo { APPVersion = Globle.APPVersion, LastDUID = LastDUId, ModelAlign = userdict, ModelOtherSettings = otherdict, ModelLocationSettings = locationdict, ShortcutPair = shortcutPair }; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.Formatting = Formatting.Indented; var indentFile = JsonConvert.SerializeObject(arrayInfo, settings); var savePath = path + "/AMGSettings.json"; if (!File.Exists(savePath)) { System.IO.File.Create(savePath).Dispose(); } StreamWriter sw = new StreamWriter(savePath); sw.WriteLine(indentFile); sw.Close(); Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelConfigSaveSuccess", savePath)); } catch (Exception err) { Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelConfigSaveException", err.Message)); } }
public void OnModelConfigLoadButtonClick() { try { var model = SettingPanelController.GetModelObjectSelected(); if (model != null) { if (model.GetComponent <Live2DModelController>() != null) { var controller = model.GetComponent <Live2DModelController>(); var data = SaveController.LoadUserData(controller.ModelPath); controller.SetModelSettings(data.ModelAlign); controller.SetModelOtherSettings(data.ModelOtherSettings); controller.SetModelLocationSettings(data.ModelLocationSettings); if (data.LastDUID != null) { controller.ConnectionUUID = data.LastDUID; } SetValueToCubismShortcut(data.ShortcutPair, model); SetValueFromModel(); SettingPanelController.ResetModelAdvancedPanel(); SettingPanelController.ResetShortcutPanel(); } } } catch (Exception err) { Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelConfigLoadException", err.Message)); } }
public void DanmakuClientStop() { if (Danmakuclient != null) { DanmakuClientStatus = false; Danmakuclient.Close(); Danmakuclient.Dispose(); } Globle.AddDataLog("Danmaku", Globle.LangController.GetLang("LOG.DanmakuClientStopped")); }
public void OnModelIPDropdownBoxSelected(int id) { var model = GetModelObjectSelected(); if (model != null) { if (model.GetComponent <Live2DModelController>() != null) { model.GetComponent <Live2DModelController>().ConnectionUUID = ModelIPDropdownBox.selectedText.text; } Globle.AddDataLog("Model", LangController.GetLang("LOG.SetModelIP", ModelSelectionDropdownBox.selectedText.text, ModelIPDropdownBox.selectedText.text)); } }
public void P2PClientSendBinary(byte[] binary) { try { if (P2Pclient.IsConnected && P2PClientStatus == true) { P2Pclient.SendBinary(binary); } } catch (Exception ex) { P2PClientSwitch.isOn = false; P2PClientStatus = false; Globle.AddDataLog("WSC", Globle.LangController.GetLang("LOG.WSCClientException", ex.Message)); } }
protected sealed override void OnDisconnected(object sender, IContenxt context) { //var ip = ((System.Net.IPEndPoint)context.Session.RemoteEndPoint).Address.ToString(); var ip = context.Session.RemoteEndPoint.ToString(); foreach (var wsclient in Globle.WSClients) { if (wsclient.Value.ip == ip) { Globle.WSClients.Remove(wsclient.Key); break; } } Globle.WSClientsChanged = true; Globle.AddDataLog("XDP", Globle.LangController.GetLang("LOG.XDPClientDisconnect", DateTime.Now.ToString("mm:ss"), context.Session.ToString())); }
public void SocketStart() { try { listener = new NetworkSocket.TcpListener(); listener.Use <WebSocketMiddleware>(); listener.UsePlug <WebSocketPlug>(); listener.Start(8040); Globle.AddDataLog("XDP", Globle.LangController.GetLang("LOG.XDPServerStarted")); } catch (Exception ex) { SocketSwitch.isOn = false; Globle.AddDataLog("XDP", Globle.LangController.GetLang("LOG.XDPServerException", ex.Message, ex.StackTrace)); } }
protected override void OnText(FrameRequest frame) { try { var text = Encoding.UTF8.GetString(frame.Content); Debug.Log(text); //var ip = ((System.Net.IPEndPoint)context.Session.RemoteEndPoint).Address.ToString(); //var ip = context.Session.RemoteEndPoint.ToString(); try { /*var jsonResult = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(text); * var uuid = "USB: " + jsonResult["uuid"].ToString(); * if (Globle.WSClients.ContainsKey(uuid)) * { * Globle.WSClients[uuid].message = text; * Globle.WSClients[uuid].result = jsonResult; * Globle.WSClients[uuid].lastUpdated = DateTime.Now.Date; * } * else * { * var WSC = new WSClientClass(); * WSC.ip = "USB"; * WSC.message = text; * WSC.uuid = jsonResult["uuid"].ToString(); * WSC.result = jsonResult; * WSC.lastUpdated = DateTime.Now.Date; * WSC.isRemote = false; * WSC.isUSB = true; * Globle.WSClients.Add(uuid, WSC); * Globle.WSClientsChanged = true; * }*/ } catch { } } catch (Exception ex) { Globle.AddDataLog("USB", Globle.LangController.GetLang("LOG.DanmakuClientException", ex.Message, ex.StackTrace)); } }
public async void DanmakuClientStart() { try { Globle.AddDataLog("USB", Globle.LangController.GetLang("LOG.DanmakuClientStarting")); var uri = new Uri("wss://danmaku.loli.ren/chat"); Danmakuclient = new DanmakuWebsocketClient(uri, CheckValidationResult); var addresses = System.Net.Dns.GetHostAddresses(uri.Host); if (addresses.Length == 0) { throw new ArgumentException( Globle.LangController.GetLang("LOG.DanmakuClientIPFailed"), "" ); } await Danmakuclient.ConnectAsync(addresses[0], uri.Port); if (Danmakuclient.IsConnected) { DanmakuClientStatus = true; Globle.AddDataLog("Danmaku", Globle.LangController.GetLang("LOG.USBClientStarted")); Danmakuclient.SendText("{\"cmd\":1,\"data\":{ \"roomId\":35119946,\"version\":\"0.2.2\", \"config\":{ \"autoTranslate\":false}}}"); } else { DanmakuClientSwitch.isOn = false; Globle.AddDataLog("Danmaku", Globle.LangController.GetLang("LOG.DanmakuClientStartedFailed")); } } catch (Exception ex) { DanmakuClientSwitch.isOn = false; Globle.AddDataLog("Danmaku", Globle.LangController.GetLang("LOG.DanmakuClientException", ex.Message)); } }
protected override void OnBinary(FrameRequest frame) { try { var text = Encoding.UTF8.GetString(frame.Content); var jsonResult = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(text); var ipMessage = jsonResult["ipMessage"]; foreach (JProperty jp in ipMessage) { var ip = ("P2P") + " : " + jp.Name; var request = jp.Value.ToString(); var jsonResultMessage = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jp.Value.ToString()); if (Globle.WSClients.ContainsKey(ip)) { Globle.WSClients[ip].message = request; Globle.WSClients[ip].result = jsonResultMessage; Globle.WSClients[ip].lastUpdated = DateTime.Now.Date; } else { var WSC = new WSClientClass(); WSC.ip = ip; WSC.message = request; WSC.uuid = jsonResultMessage["uuid"].ToString(); WSC.result = jsonResultMessage; WSC.lastUpdated = DateTime.Now.Date; WSC.isRemote = true; Globle.WSClients.Add(ip, WSC); Globle.WSClientsChanged = true; } } } catch (Exception ex) { Globle.AddDataLog("WSC", Globle.LangController.GetLang("LOG.WSCClientException", ex.Message, ex.StackTrace)); } }
public void RefreshModelIPDropdownBoxDropdown() { if (Globle.WSClients.Count > 0) { var listCount = Globle.WSClients.Count + 1; ModelIPDropdownBox.listItems = new string[listCount]; ModelIPDropdownBox.listItems[0] = "/"; var i = 1; foreach (KeyValuePair <string, WSClientClass> kvp in Globle.WSClients) { ModelIPDropdownBox.listItems[i] = kvp.Key; i++; } } else { var none = new string[1]; none[0] = "/"; ModelIPDropdownBox.listItems = none; } ModelIPDropdownBox.RefreshList(); ModelIPDropdownBox.currentSelection = -1; Globle.AddDataLog("IP", LangController.GetLang("LOG.RefreshIPList")); }
public async void USBClientStart() { try { Globle.AddDataLog("USB", Globle.LangController.GetLang("LOG.USBClientStarting")); var uri = new Uri("ws://127.0.0.1:22546"); USBclient = new USBWebSocketClient(uri); var addresses = System.Net.Dns.GetHostAddresses(uri.Host); if (addresses.Length == 0) { throw new ArgumentException( Globle.LangController.GetLang("LOG.USBClientIPFailed"), "" ); } await USBclient.ConnectAsync(addresses[0], uri.Port); if (USBclient.IsConnected) { USBClientStatus = true; Globle.AddDataLog("USB", Globle.LangController.GetLang("LOG.USBClientStarted")); } else { USBClientSwitch.isOn = false; Globle.AddDataLog("USB", Globle.LangController.GetLang("LOG.USBClientStartedFailed")); } } catch (Exception ex) { USBClientSwitch.isOn = false; Globle.AddDataLog("USB", Globle.LangController.GetLang("LOG.USBClientException", ex.Message)); } }
public void USBClientStop() { if (USBclient != null) { USBClientStatus = false; USBclient.Close(); USBclient.Dispose(); } Globle.AddDataLog("USB", Globle.LangController.GetLang("LOG.USBClientStopped")); var readyToRemove = new ArrayList(); foreach (KeyValuePair <string, WSClientClass> kvp in Globle.WSClients) { if (kvp.Value.isUSB == true) { readyToRemove.Add(kvp.Key); } } foreach (string aa in readyToRemove) { Globle.WSClients.Remove(aa); } Globle.WSClientsChanged = true; }
protected sealed override void OnConnected(object sender, IContenxt context) { Globle.AddDataLog("XDP", Globle.LangController.GetLang("LOG.XDPClientConnect", DateTime.Now.ToString("mm:ss"), context.Session.ToString())); }
public CubismModel GetModelFromName(string name, GameObject parent) { try { string ModelPath = Application.streamingAssetsPath + "../../../Data/live2d/" + name + ".model3.json"; //Debug.Log(ModelPath); if (System.IO.File.Exists(ModelPath)) { var ModelFullName = ModelPath; var model3Json = CubismModel3Json.LoadAtPath(ModelFullName, BuiltinLoadAssetAtPath); var motions = model3Json.FileReferences.Motions.Motions; var model = model3Json.ToModel(true); var Scale = 40f; model.gameObject.transform.localScale += new Vector3(Scale, Scale); CubismRenderController cubisumRenderController = model.GetComponent <CubismRenderController>(); cubisumRenderController.SortingMode = CubismSortingMode.BackToFrontOrder; //处理动画(Motion) Animation animation = model.gameObject.AddComponent <Animation>(); var animationClips = new ArrayList(); var modelD = Path.GetDirectoryName(ModelPath); if (motions != null) { for (var i = 0; i < motions.Length; ++i) { for (var j = 0; j < motions[i].Length; ++j) { string MotionPath = modelD + "/" + motions[i][j].File; CubismMotion3Json cubismMotion3Json = CubismMotion3Json.LoadFrom(File.ReadAllText(MotionPath)); AnimationClip animationClip = cubismMotion3Json.ToAnimationClip(new AnimationClip { legacy = true }, false, false, false, null); var motionName = motions[i][j].File.Substring(0, motions[i][j].File.Length - 13); animationClip.name = motionName; animation.AddClip(animationClip, animationClip.name); animationClips.Add(animationClip.name); //animation.Blend(animationClip.name); } } } //处理姿势 var pose3Json = model3Json.Pose3Json; if (pose3Json != null) { var groups = pose3Json.Groups; var parts = model.Parts; for (var groupIndex = 0; groupIndex < groups.Length; ++groupIndex) { var group = groups[groupIndex]; if (group == null) { continue; } for (var partIndex = 0; partIndex < group.Length; ++partIndex) { var part = parts.FindById(group[partIndex].Id); if (part == null) { continue; } var posePart = part.gameObject.GetComponent <CubismPosePart>(); if (posePart == null) { posePart = part.gameObject.AddComponent <CubismPosePart>(); } posePart.GroupIndex = groupIndex; posePart.PartIndex = partIndex; posePart.Link = group[partIndex].Link; } } model.GetComponent <CubismPoseController>().Refresh(); } //+1 model.name = model.name + "(" + Globle.ModelNum.ToString() + ")"; Globle.ModelNum++; Globle.ModelList.Add(model.gameObject); var modelController = model.gameObject.AddComponent <Live2DModelController>(); modelController.DisplayName = model.name; modelController.ModelPath = modelD; modelController.Animation = animation; modelController.animationClips = animationClips; model.transform.SetParent(parent.transform); model.gameObject.transform.localPosition = new Vector3(0, 0, 0); return(model); } else { throw new Exception(Globle.LangController.GetLang("LOG.FileUnisset")); } } catch (Exception err) { Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelAddationException", err.Message)); } return(null); }
public void SocketStop() { listener.Dispose(); Globle.AddDataLog("XDP", Globle.LangController.GetLang("LOG.XDPServerStopped")); }