public void process_json_message(StringBuilder sb) { string clientMessage = sb.ToString(); if (clientMessage.Length > 24 && clientMessage.Substring(clientMessage.Length - 25, 25).Equals("UNITY_MESH_JSON_FORMATTED")) { string substring = clientMessage.Substring(0, clientMessage.Length - 25); UnityMesh rec_msh = JsonUtility.FromJson <UnityMesh>(substring); meshqueue.Enqueue(rec_msh); } else { if (clientMessage.Length > 20 && clientMessage.Substring(clientMessage.Length - 21, 21).Equals("UNITY_CAMERA_SETTINGS")) { string substring = clientMessage.Substring(0, clientMessage.Length - 21); UnityCameraSettings cam_settings = JsonUtility.FromJson <UnityCameraSettings>(substring); camsetqueue.Enqueue(cam_settings); } else { if (clientMessage.Length > 14 && clientMessage.Substring(clientMessage.Length - 15, 15).Equals("UNITY_RESET_ALL")) { flag_reset = true; } else if (clientMessage.Length > 12 && clientMessage.Substring(clientMessage.Length - 13, 12).Equals("UNITY_RESET_")) { clearnum = clientMessage.Substring(clientMessage.Length - 1, 1); flag_reset = true; } else { if (clientMessage.Length > 15 && clientMessage.Substring(clientMessage.Length - 16, 16).Equals("UNITY_SCREENSHOT")) { string substring = clientMessage.Substring(0, clientMessage.Length - 16); screenshot_filename = substring; flag_take_screenshot = true; } } } } }
public override int[] Indices4(int stream = 0) { return(UnityMesh.GetIndices(0)); }
public override uint IndexCount(int stream = 0) { return(UnityMesh.GetIndices(0) != null ? (uint)UnityMesh.GetIndices(0).Length : 0); }
// Update is called once per frame void Update() { if (listenIP != _listenIP || listenPort != _listenPort) { try { IPAddress.Parse(listenIP); _listenPort = listenPort; _listenIP = listenIP; } catch (FormatException e) { Debug.LogWarning("Invalid IP address entered."); Debug.LogWarning(e.ToString()); } } if (serverListening != _serverListening) { if (!serverListening) { Debug.Log("Server stopping."); tcpListener.Stop(); } else { tcpListenerThread = new Thread(new ThreadStart(ListenForIncommingRequests)); tcpListenerThread.IsBackground = true; tcpListenerThread.Start(); } _serverListening = serverListening; } QualitySettings.vSyncCount = 0; Application.targetFrameRate = targetFrameRate; if (stringbuilderqueue.Count > 0) { StringBuilder sb = stringbuilderqueue.Dequeue(); process_json_message(sb); } if (camsetqueue.Count > 0) { UnityCameraSettings rec_set = camsetqueue.Dequeue(); rec_set.process_command(cam, modelCamera); } if (meshqueue.Count > 0) { UnityMesh rec_msh = meshqueue.Dequeue(); GameObject ago = null; GameObject parent = null; string[] rec_ids = rec_msh.id.Split(":"[0]); string rec_msh_id = rec_ids[0]; string id_spec = ""; if (rec_ids.Length > 1) { id_spec = rec_ids[1]; } if (godict.ContainsKey(rec_msh_id)) { parent = godict[rec_msh_id]; } else { parent = new GameObject(); parent.name = rec_msh_id; godict[rec_msh_id] = parent; //GameObject button = (GameObject)Instantiate(SampleButton); GameObject prefab = GameObject.Find("Button_clear"); GameObject button = (GameObject)Instantiate(prefab); GameObject panel = GameObject.Find("Panel_visible"); button.transform.SetParent(panel.transform);//Setting button parent //button.SetActive(true); button.GetComponent <Button>().onClick.RemoveAllListeners(); //button.GetComponent<Button>().onClick.AddListener(OnClick);//Setting what button does when clicked button.GetComponent <Button>().onClick.AddListener(() => on_button_click(parent, button)); button.transform.GetChild(0).GetComponent <Text>().text = rec_msh_id; //Changing text Button thebutton = button.GetComponent <Button>(); ColorBlock thecolor = button.GetComponent <Button>().colors; thecolor.normalColor = Color.green; thecolor.highlightedColor = Color.green; thecolor.pressedColor = Color.green; thebutton.colors = thecolor; //godict[rec_msh_id + ":Button"] = button; buttondict[parent.name] = button; } if (rec_msh.triangles.Length > 2) { //triangle mesh string id_tri_msh = rec_msh_id + id_tri + " " + id_spec; if (meshdict.ContainsKey(id_tri_msh) && godict.ContainsKey(id_tri_msh)) { Mesh msh = meshdict [id_tri_msh]; rec_msh.update_tri_mesh(msh); ago = godict [id_tri_msh]; } else { ago = new GameObject(id_tri_msh); //ago.transform.SetParent(parent.transform); godict [id_tri_msh] = ago; Mesh msh = rec_msh.new_tri_mesh(ago, shaders["smooth"]); meshdict [id_tri_msh] = msh; //EditorGUIUtility.PingObject(ago); //Selection.activeGameObject = ago; //ago.transform.SetParent(parent.transform, false); ago.transform.parent = parent.transform; } rec_msh.process_options(godict [id_tri_msh], shaders, "surface"); } if (rec_msh.lines.Length > 1) { //line mesh //string id_tri_msh = rec_msh_id + id_tri + " " + id_spec; string id_line_msh = rec_msh_id + " " + id_spec + " " + id_line; if (meshdict.ContainsKey(id_line_msh) && godict.ContainsKey(id_line_msh)) { //update mesh Mesh msh = meshdict [id_line_msh]; rec_msh.update_line_mesh(msh); ago = godict [id_line_msh]; //? } else { //new mesh ago = new GameObject(id_line_msh); //ago.transform.SetParent(parent.transform); //ago.transform.parent = parent.transform; godict [id_line_msh] = ago; Mesh msh = rec_msh.new_line_mesh(ago, shaders["line"]); meshdict [id_line_msh] = msh; ago.transform.parent = parent.transform; } rec_msh.process_options(godict [id_line_msh], shaders, "line"); } if (rec_msh.points.Length > 0) { //vertex mesh string id_vert_msh = rec_msh_id + id_vert + " " + id_spec; if (meshdict.ContainsKey(id_vert_msh) && godict.ContainsKey(id_vert_msh)) { //update mesh Mesh msh = meshdict [id_vert_msh]; rec_msh.update_vert_mesh(msh); ago = godict [id_vert_msh]; } else { //new mesh ago = new GameObject(id_vert_msh); godict [id_vert_msh] = ago; //ago.transform.SetParent(parent.transform); Mesh msh = rec_msh.new_vert_mesh(ago, shaders["point"]); meshdict [id_vert_msh] = msh; ago.transform.parent = parent.transform; } rec_msh.process_options(godict [id_vert_msh], shaders, "point"); } if (ago != null) { var children = new List <GameObject>(); foreach (Transform child in ago.transform) { children.Add(child.gameObject); } children.ForEach(child => Destroy(child)); rec_msh.draw_text(ago); } if ((rec_msh != null && rec_msh.visible != null && rec_msh.visible[0] && parent != null) || (parent != null && visible_list.Contains(parent.name))) { setVisible(true, parent, buttondict[parent.name]); } else { if (parent != null) { setVisible(false, parent, buttondict[parent.name]); } } ago = null; rec_msh = null; } if (flag_reset) { flag_reset = false; if (clearnum == "all") { reset_all(); } else { try { reset(int.Parse(clearnum)); } catch (Exception e) { Debug.LogWarning("Resetting failed."); Debug.Log(e.ToString()); clearnum = "all"; } } } if (flag_take_screenshot) { if (screenshot_frame == 0) { canvas.SetActive(false); screenshot_frame++; } else { if (screenshot_frame == 1) { ScreenCapture.CaptureScreenshot(screenshot_filename, 2); screenshot_frame++; } else { if (screenshot_frame == 2) { canvas.SetActive(true); Debug.Log("Screenshot taken"); Debug.Log(screenshot_filename); flag_take_screenshot = false; screenshot_filename = ""; screenshot_frame = 0; } } } } }