public static void Init() { if (_tex == null) { _tex = UniOSCUtils.MakeTexture(2, 2, new Color(0.95f, 0.95f, 0.95f, 0.25f)); } }
// void OnGUI(){ // // } /// <summary> /// Renders the GUI of a OSCConnection in the GameView. /// This is different from the rendering in the editor/inspector /// </summary> public void RenderGUI() { if (UniOSCUtils.TEX_CONNECTION_BG == null) { UniOSCUtils.TEX_CONNECTION_BG = UniOSCUtils.MakeTexture(2, 2, UniOSCUtils.CONNECTION_BG); } _gs = new GUIStyle(GUI.skin.box); _gs.normal.background = UniOSCUtils.TEX_CONNECTION_BG; _gs.fontSize = 11; GUILayout.BeginVertical(_gs); #region Header GUILayout.BeginHorizontal(); GUILayout.Label(name); GUILayout.EndHorizontal(); #endregion Header GUILayout.BeginHorizontal(); #region IN GUILayout.BeginVertical(); GUI.backgroundColor = _connected ? UniOSCUtils.CONNECTION_ON_COLOR : UniOSCUtils.CONNECTION_OFF_COLOR; GUIContent gc; StringBuilder sb = new StringBuilder(); sb.AppendLine("OSC IN"); sb.AppendLine(String.Format("Port:{0}", oscPort)); if (_connected) { sb.AppendLine(String.Format("Listening:{0}", localIPAddress)); gc = new GUIContent(sb.ToString()); Rect area = GUILayoutUtility.GetRect(gc, _gs, GUILayout.MinWidth(150f)); GUI.Box(area, gc, _gs); } else { //sb.AppendLine("Not listening"); GUIStyle _gs2 = new GUIStyle(GUI.skin.label); _gs2.normal.background = UniOSCUtils.TEX_CONNECTION_BG; _gs2.fontSize = 11; GUILayout.BeginVertical(_gs); GUILayout.Label(new GUIContent("OSC IN"), _gs); GUILayout.BeginHorizontal(_gs2); GUILayout.Label(new GUIContent("Port:"), _gs2); gc = new GUIContent("65536"); Rect areaPort = GUILayoutUtility.GetRect(gc, _gs, GUILayout.MinWidth(20f)); oscPort = Mathf.Min(UniOSCUtils.MAXPORT, Convert.ToInt32(GUI.TextField(areaPort, oscPort.ToString()))); GUILayout.EndHorizontal(); GUILayout.EndVertical(); } GUI.backgroundColor = Color.white; if (GUILayout.Button(_connected ? "Disconnect":"Connect")) { if (_connected) { DisconnectOSC(); } else { ConnectOSC(); } } GUILayout.EndVertical(); #endregion IN GUILayout.Space(5f); #region OUT GUILayout.BeginVertical(); GUI.backgroundColor = _connectedOut ? UniOSCUtils.CONNECTION_ON_COLOR : UniOSCUtils.CONNECTION_OFF_COLOR; GUIContent gcOut; StringBuilder sb_out = new StringBuilder(); sb_out.AppendLine("OSC OUT"); if (_connectedOut) { sb_out.AppendLine(String.Format("Port:{0}", oscOutPort)); sb_out.AppendLine(String.Format("Sending:{0}", oscOutIPAddress)); gcOut = new GUIContent(sb_out.ToString()); Rect areaOut = GUILayoutUtility.GetRect(gcOut, _gs, GUILayout.MinWidth(150f)); //GUILayoutUtility.GetRect(150,50); GUI.Box(areaOut, gcOut, _gs); } else { //sb_out.AppendLine(String.Format("Not Sending:{0}",oscOutIPAddress)); GUIStyle _gs2 = new GUIStyle(GUI.skin.label); _gs2.normal.background = UniOSCUtils.TEX_CONNECTION_BG; _gs2.fontSize = 11; GUILayout.BeginVertical(_gs); GUILayout.Label(new GUIContent("OSC OUT"), _gs); GUILayout.BeginHorizontal(_gs2); GUILayout.Label(new GUIContent("Port:"), _gs2); gc = new GUIContent("65536"); Rect areaPort = GUILayoutUtility.GetRect(gc, _gs, GUILayout.MinWidth(20f)); oscOutPort = Mathf.Min(UniOSCUtils.MAXPORT, Convert.ToInt32(GUI.TextField(areaPort, oscOutPort.ToString()))); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_gs2); GUILayout.Label(new GUIContent("IP:"), _gs); gc = new GUIContent("255.255.255.255"); Rect areaIp = GUILayoutUtility.GetRect(gc, _gs, GUILayout.MinWidth(100f)); if (_tfgs == null) { _tfgs = new GUIStyle(GUI.skin.textField); } string oscOutIPAddressTemp = GUI.TextField(areaIp, oscOutIPAddress, _tfgs); GUILayout.EndHorizontal(); IPAddress addr; if (UniOSCUtils.ValidateIPAddress(oscOutIPAddressTemp, out addr)) { //oscOutIPAddress = oscOutIPAddressTemp; _tfgs = new GUIStyle(GUI.skin.textField); } else { //When the IP-Address is invalid we get visual feedback _tfgs.normal.textColor = new Color(0.8f, 0.0f, 0.0f, 1f); _tfgs.hover.textColor = new Color(0.9f, 0.0f, 0.0f, 1f); _tfgs.active.textColor = Color.red; _tfgs.focused.textColor = Color.red; } oscOutIPAddress = oscOutIPAddressTemp; GUILayout.EndVertical(); } GUI.backgroundColor = Color.white; if (GUILayout.Button(_connectedOut ? "Disconnect":"Connect")) { if (_connectedOut) { DisconnectOSCOut(); } else { ConnectOSCOut(); } } GUILayout.EndVertical(); #endregion OUT GUILayout.EndHorizontal(); #region session GUILayout.BeginHorizontal(); if (hasOSCSessionFileAttached) { if (!_connectedOut) { GUI.backgroundColor = Color.red; GUI.contentColor = Color.red; } if (GUILayout.Button(new GUIContent("Send Session Data", "Tooltip"))) { SendSessionData(); } GUI.backgroundColor = Color.white; GUI.contentColor = Color.white; } GUILayout.EndHorizontal(); #endregion GUILayout.EndVertical(); }
// void OnGUI(){ // // } /// <summary> /// Renders the GUI of a OSCConnection in the GameView. /// This is different from the rendering in the editor/inspector /// </summary> public void RenderGUI() { if (UniOSCUtils.TEX_CONNECTION_BG == null) { UniOSCUtils.TEX_CONNECTION_BG = UniOSCUtils.MakeTexture(2, 2, UniOSCUtils.CONNECTION_BG); } _gs = new GUIStyle(GUI.skin.box); _gs.normal.background = UniOSCUtils.TEX_CONNECTION_BG; _gs.fontSize = 11; GUILayout.BeginVertical(_gs); #region Header GUILayout.BeginHorizontal(); GUILayout.Label(name); GUILayout.EndHorizontal(); #endregion Header GUILayout.BeginHorizontal(); #region IN GUILayout.BeginVertical(); GUI.backgroundColor = _connected ? UniOSCUtils.CONNECTION_ON_COLOR : UniOSCUtils.CONNECTION_OFF_COLOR; GUIContent gc; StringBuilder sb = new StringBuilder(); sb.AppendLine("OSC IN"); sb.AppendLine(String.Format("Port:{0}", oscPort)); GUIStyle _gs2 = new GUIStyle(GUI.skin.label); _gs2.normal.background = UniOSCUtils.TEX_CONNECTION_BG; _gs2.fontSize = 11; GUILayout.BeginVertical(_gs); GUILayout.Label(new GUIContent("OSC IN"), _gs); GUILayout.BeginHorizontal(_gs2); GUILayout.Label(new GUIContent("Port:"), _gs2); gc = new GUIContent("65535"); Rect areaPort = GUILayoutUtility.GetRect(gc, _gs, GUILayout.MinWidth(20f)); oscPort = Mathf.Min(UniOSCUtils.MAXPORT, Convert.ToInt32(GUI.TextField(areaPort, oscPort.ToString()))); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_gs2); int toolbarInt = 0; toolbarInt = (int)transmissionTypeIn; string[] toolbarStrings = new string[] { "Unicast", "Multicast" }; GUIStyle _gs2b = new GUIStyle(GUI.skin.toggle); _gs2b.fontSize = 12; toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings, _gs2b, GUILayout.Width(75 * toolbarStrings.Count()), GUILayout.Height(25f)); transmissionTypeIn = (OSCsharp.Net.TransmissionType)toolbarInt; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_gs2); GUILayout.Label(new GUIContent("IP:"), _gs); gc = new GUIContent("255.255.255.255"); Rect areaIpIn = GUILayoutUtility.GetRect(gc, _gs, GUILayout.MinWidth(100f)); _tfgs = (transmissionTypeIn == OSCsharp.Net.TransmissionType.Unicast) ? new GUIStyle(GUI.skin.label): new GUIStyle(GUI.skin.textField); if (!hasValidOscIPAddress) { //When the IP-Address is invalid we get visual feedback _tfgs.normal.textColor = new Color(0.8f, 0.0f, 0.0f, 1f); _tfgs.hover.textColor = new Color(0.9f, 0.0f, 0.0f, 1f); _tfgs.active.textColor = Color.red; _tfgs.focused.textColor = Color.red; } if (transmissionTypeIn == OSCsharp.Net.TransmissionType.Unicast) { GUI.Label(areaIpIn, oscInIPAddress, _tfgs); } else { oscInIPAddress = GUI.TextField(areaIpIn, oscInIPAddress, _tfgs); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUI.backgroundColor = Color.white; if (GUILayout.Button(_connected ? "Disconnect":"Connect")) { if (_connected) { DisconnectOSC(); } else { ConnectOSC(); } } GUILayout.EndVertical(); #endregion IN GUILayout.Space(5f); #region OUT GUILayout.BeginVertical(); GUI.backgroundColor = _connectedOut ? UniOSCUtils.CONNECTION_ON_COLOR : UniOSCUtils.CONNECTION_OFF_COLOR; GUIStyle _gs3 = new GUIStyle(GUI.skin.label); _gs3.normal.background = UniOSCUtils.TEX_CONNECTION_BG; _gs3.fontSize = 11; GUILayout.BeginVertical(_gs); GUILayout.Label(new GUIContent("OSC OUT"), _gs); GUILayout.BeginHorizontal(_gs3); GUILayout.Label(new GUIContent("Port:"), _gs3); gc = new GUIContent("65536"); Rect areaPort3 = GUILayoutUtility.GetRect(gc, _gs, GUILayout.MinWidth(20f)); oscOutPort = Mathf.Min(UniOSCUtils.MAXPORT, Convert.ToInt32(GUI.TextField(areaPort3, oscOutPort.ToString()))); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_gs3); int toolbarIntOut = 0; toolbarIntOut = (int)transmissionTypeOut; string[] toolbarStringsOut = new string[] { "Unicast", "Multicast", "Broadcast" }; GUIStyle _gs3b = new GUIStyle(GUI.skin.toggle); _gs3b.fontSize = 12; toolbarIntOut = GUILayout.Toolbar(toolbarIntOut, toolbarStringsOut, _gs3b, GUILayout.Width(75 * toolbarStringsOut.Count()), GUILayout.Height(25f)); transmissionTypeOut = (OSCsharp.Net.TransmissionType)toolbarIntOut; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(_gs3); GUILayout.Label(new GUIContent("IP:"), _gs); gc = new GUIContent("255.255.255.255"); Rect areaIpOut = GUILayoutUtility.GetRect(gc, _gs, GUILayout.MinWidth(100f)); _tfgs = ((int)transmissionTypeOut >= (int)OSCsharp.Net.TransmissionType.Broadcast) ? new GUIStyle(GUI.skin.label) : new GUIStyle(GUI.skin.textField); if (!hasValidOscOutIPAddress) { //When the IP-Address is invalid we get visual feedback _tfgs.normal.textColor = new Color(0.8f, 0.0f, 0.0f, 1f); _tfgs.hover.textColor = new Color(0.9f, 0.0f, 0.0f, 1f); _tfgs.active.textColor = Color.red; _tfgs.focused.textColor = Color.red; } if ((int)transmissionTypeOut >= (int)OSCsharp.Net.TransmissionType.Broadcast) { GUI.Label(areaIpOut, oscOutIPAddress, _tfgs); } else { oscOutIPAddress = GUI.TextField(areaIpOut, oscOutIPAddress, _tfgs); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUI.backgroundColor = Color.white; if (GUILayout.Button(_connectedOut ? "Disconnect":"Connect")) { if (_connectedOut) { DisconnectOSCOut(); } else { ConnectOSCOut(); } } GUILayout.EndVertical(); #endregion OUT GUILayout.EndHorizontal(); #region session GUILayout.BeginHorizontal(); if (hasOSCSessionFileAttached) { if (!_connectedOut) { GUI.backgroundColor = Color.red; GUI.contentColor = Color.red; } if (GUILayout.Button(new GUIContent("Send Session Data", "Tooltip"))) { SendSessionData(); } GUI.backgroundColor = Color.white; GUI.contentColor = Color.white; } GUILayout.EndHorizontal(); #endregion GUILayout.EndVertical(); }