private void UpdateDrag(PointerEventData eventData, Camera camera, bool force = false) { var eventPosition = Vector2.zero; if (_handleContainerRectTransform == null || _handleContainerRectTransform.rect.size.x <= 0.0 || _handleContainerRectTransform.rect.size.y <= 0.0 || !RectTransformUtility.ScreenPointToLocalPointInRectangle(_handleContainerRectTransform, eventData.position, camera, out eventPosition)) { return; } eventPosition -= _handleContainerRectTransform.rect.position; var position = Vector2.zero; position.x = eventPosition.x / _handleContainerRectTransform.rect.size.x; position.y = eventPosition.y / _handleContainerRectTransform.rect.size.y; var degrees = Mathf.Atan2(position.x - 0.5f, position.y - 0.5f) / Mathf.PI; var difference = Mathf.Abs(degrees - _previoudDegrees); if (difference > 1.25f && !force) { return; } _previoudDegrees = degrees; NormalizedValue = _reverse ? 1f - OSCUtilities.Map(degrees, -0.8f, 0.8f, 0f, 1f) : OSCUtilities.Map(degrees, -0.8f, 0.8f, 0f, 1f); }
public static Type[] GetTypes(Type type) { var types = new List <Type>(); var guids = AssetDatabase.FindAssets("t:" + nameof(MonoScript)); foreach (var guid in guids) { var assetPath = AssetDatabase.GUIDToAssetPath(guid); var monoScript = AssetDatabase.LoadAssetAtPath <MonoScript>(assetPath); if (monoScript == null) { continue; } var componentType = monoScript.GetClass(); if (componentType == null || !OSCUtilities.IsSubclassOf(componentType, type)) { continue; } types.Add(componentType); } return(types.ToArray()); }
public static IOSCPacket LoadPacket(string filePath) { if (!File.Exists(filePath)) { return(null); } try { return(OSCConverter.Unpack(File.ReadAllBytes(filePath))); } catch (Exception e) { Debug.LogFormat("[OSCEditorUtils] Load packet error: {0}", e); try { var document = new XmlDocument(); document.Load(filePath); return(OSCUtilities.FromBase64String(document.FirstChild.InnerText)); } catch (Exception e2) { Debug.LogFormat("[OSCEditorUtils] Load old format packet error: {0}", e2); } } return(null); }
public static void SaveConsoleMessages(string filePath, List <OSCConsolePacket> list) { var document = new XmlDocument(); var rootElement = (XmlElement)document.AppendChild(document.CreateElement("root")); foreach (var consoleMessage in list) { var messageElement = rootElement.AppendChild(document.CreateElement("message")); var instanceAttribute = document.CreateAttribute("info"); instanceAttribute.InnerText = consoleMessage.Info; var typeAttribute = document.CreateAttribute("type"); typeAttribute.InnerText = consoleMessage.PacketType.ToString(); messageElement.Attributes.Append(instanceAttribute); messageElement.Attributes.Append(typeAttribute); var packetElement = document.CreateElement("packet"); packetElement.InnerText = OSCUtilities.ToBase64String(consoleMessage.Packet); messageElement.AppendChild(packetElement); } document.Save(filePath); }
public void Map(OSCMessage message) { if (OSCUtilities.CompareAddresses(Address, message.Address) && message.Values.Count == Values.Count) { var failed = false; for (int index = 0; index < message.Values.Count; index++) { var mapMessageValue = Values[index]; var messageValue = message.Values[index]; var valueType = messageValue.Type != OSCValueType.False ? messageValue.Type : OSCValueType.True; if (messageValue.Type != valueType) { failed = true; break; } } if (failed) { return; } for (int index = 0; index < message.Values.Count; index++) { var messageValue = message.Values[index]; var mapMessageValue = Values[index]; message.Values[index] = mapMessageValue.Map(messageValue); } } }
public void ReceiveScale(OSCMessage message) { if (message.ToVector3(out var vector)) { ReceiverTextScale.text = vector.ToString(); ReceiverSliderScale.value = OSCUtilities.Map(vector.x, 1, 5, 0, 1); } }
public void ReceiveRotate(OSCMessage message) { if (message.ToVector3(out var vector)) { ReceiverTextRotate.text = vector.ToString(); ReceiverSliderRotate.value = OSCUtilities.Map(vector.z, 0, 360, 0, 1); } }
public void SendPosition(Vector2 value) { _position.x = OSCUtilities.Map(value.x, -1, 1, -100, 100); _position.y = OSCUtilities.Map(value.y, -1, 1, -100, 100); SendVector(_positionAddress, _position); TextPosition.text = _position.ToString(); }
public void SendRotate(float value) { value = OSCUtilities.Map(value, 0, 1, 0, 360); var vector = new Vector3(0, 0, value); SendVector(_rotateAddress, vector); TextRotate.text = vector.ToString(); }
public void SendScale(float value) { value = OSCUtilities.Map(value, 0, 1, 1, 5); var vector = new Vector3(value, value, value); SendVector(_scaleAddress, vector); TextScale.text = vector.ToString(); }
public void ReceivePosition(OSCMessage message) { if (message.ToVector3(out var vector)) { vector = new Vector2(OSCUtilities.Map(vector.x, -100, 100, -1, 1), OSCUtilities.Map(vector.y, -100, 100, -1, 1)); ReceiverTextPosition.text = ((Vector2)vector).ToString(); ReceiverPadPosition.Value = vector; } }
public static OSCEditorReceiver CreateEditorReceiver() { var receiver = new OSCEditorReceiver(); receiver.LocalHostMode = OSCLocalHostMode.Any; receiver.LocalHost = OSCUtilities.GetLocalHost(); receiver.LocalPort = 7100 + _receivers.Count; _receivers.Add(receiver); return(receiver); }
public static OSCEditorTransmitter CreateEditorTransmitter() { var transmitter = new OSCEditorTransmitter(); transmitter.RemotePort = 7100 + _transmitters.Count; transmitter.LocalHostMode = OSCLocalHostMode.Any; transmitter.LocalHost = OSCUtilities.GetLocalHost(); transmitter.LocalPortMode = OSCLocalPortMode.FromRemotePort; transmitter.LocalPort = transmitter.RemotePort; _transmitters.Add(transmitter); return(transmitter); }
public static List <OSCConsolePacket> LoadConsoleMessages(string filePath) { var list = new List <OSCConsolePacket>(); if (!File.Exists(filePath)) { SaveConsoleMessages(filePath, list); return(list); } var document = new XmlDocument(); try { document.Load(filePath); var rootElement = document.FirstChild; foreach (XmlNode messageElement in rootElement.ChildNodes) { var consoleMessage = new OSCConsolePacket(); var instanceAttribute = messageElement.Attributes["info"]; consoleMessage.Info = instanceAttribute.InnerText; var typeAttribute = messageElement.Attributes["type"]; consoleMessage.PacketType = (OSCConsolePacketType)Enum.Parse(typeof(OSCConsolePacketType), typeAttribute.InnerText); var timestampAttribute = messageElement.Attributes["timestamp"]; if (timestampAttribute != null) { consoleMessage.TimeStamp = timestampAttribute.InnerText; } var packetElement = messageElement["packet"]; consoleMessage.Packet = OSCUtilities.FromBase64String(packetElement.InnerText); list.Add(consoleMessage); } } catch (Exception e) { Debug.LogFormat("[OSCConsole] Error: {0}", e); list.Clear(); } return(list); }
public void ReceiveMessage(OSCMessage message) { byte[] bytes; // Get bytes from message if (!message.ToBlob(out bytes)) { return; } // Convert bytes to structure! var structure = OSCUtilities.ByteToStruct <MarshallingStructure>(bytes); Debug.LogFormat("Received structure with data:\nIntValue: {0}\nStringValue: {1}\nFloatValue: {2}", structure.IntValue, structure.StringValue, structure.FloatValue); }
protected void OnEnable() { _receiver = target as OSCReceiver; _localHost = OSCUtilities.GetLocalHost(); _localPortProperty = serializedObject.FindProperty("localPort"); _autoConnectProperty = serializedObject.FindProperty("autoConnect"); _workInEditorProperty = serializedObject.FindProperty("workInEditor"); _mapBundleProperty = serializedObject.FindProperty("mapBundle"); EditorApplication.update += ReceiverEditorUpdate; if (!Application.isPlaying && !_receiver.IsAvaible && _workInEditorProperty.boolValue) { _receiver.Connect(); } }
protected override void OnDidApplyAnimationProperties() { _value = ClampValue(_value); var normal = NormalizedValue; if (_handleImage != null) { normal = OSCUtilities.Map(_handleImage.fillAmount, 0.1f, 0.9f, 0, 1); } UpdateVisuals(); if (Math.Abs(normal - _value) < float.Epsilon) { return; } _onValueChanged.Invoke(_value); }
protected void OnEnable() { _receiver = target as OSCReceiver; _localHostCache = OSCUtilities.GetLocalHost(); _localHostModeProperty = serializedObject.FindProperty("_localHostMode"); _localHostProperty = serializedObject.FindProperty("_localHost"); _localPortProperty = serializedObject.FindProperty("_localPort"); _autoConnectProperty = serializedObject.FindProperty("_autoConnect"); _workInEditorProperty = serializedObject.FindProperty("_workInEditor"); _mapBundleProperty = serializedObject.FindProperty("_mapBundle"); _closeOnPauseProperty = serializedObject.FindProperty("_closeOnPause"); EditorApplication.update += ReceiverEditorUpdate; if (!Application.isPlaying && !_receiver.IsStarted && _workInEditorProperty.boolValue) { _receiver.Connect(); } }
private void UpdateVisuals() { #if UNITY_EDITOR if (!Application.isPlaying) { UpdateCachedReferences(); } #endif if (_handleImage != null) { var fillAmount = OSCUtilities.Map(NormalizedValue, 0, 1, 0.1f, 0.9f); if (_reverse != !_handleImage.fillClockwise) { _handleImage.fillClockwise = !_reverse; } _handleImage.fillAmount = fillAmount; } }
protected virtual void Update() { // POSITION _noisePosition.x += PositionSpeed * Time.deltaTime; _noisePosition.y += PositionSpeed * Time.deltaTime; var position = InformerItem.anchoredPosition3D; position.x = Mathf.PerlinNoise(_noisePosition.x, _noisePosition.x) * PositionDepth; position.y = Mathf.PerlinNoise(_noisePosition.y, _noisePosition.y) * PositionDepth; position.x = OSCUtilities.Map(position.x, 0, PositionDepth, -100, 100); position.y = OSCUtilities.Map(position.y, 0, PositionDepth, -100, 100); InformerItem.anchoredPosition3D = position; //ROTATION _noiseRotation.z += RotationSpeed * Time.deltaTime; var rotation = InformerItem.localEulerAngles; rotation.z = Mathf.PerlinNoise(_noiseRotation.z, _noiseRotation.z) * RotationDepth; rotation.z = OSCUtilities.Map(rotation.z, 0, RotationDepth, 0, 360); InformerItem.localEulerAngles = rotation; //SCALE _noiseScale.x += ScaleSpeed * Time.deltaTime; var scale = InformerItem.localScale; scale.x = Mathf.PerlinNoise(_noiseScale.x, _noiseScale.x) * ScaleDepth; scale.x = scale.y = scale.z = OSCUtilities.Map(scale.x, 0, ScaleDepth, 1, 5); InformerItem.localScale = scale; }
protected void OnEnable() { _transmitter = target as OSCTransmitter; _localHostCache = OSCUtilities.GetLocalHost(); _remoteHostProperty = serializedObject.FindProperty("_remoteHost"); _remotePortProperty = serializedObject.FindProperty("_remotePort"); _autoConnectProperty = serializedObject.FindProperty("_autoConnect"); _workInEditorProperty = serializedObject.FindProperty("_workInEditor"); _mapBundleProperty = serializedObject.FindProperty("_mapBundle"); _useBundleProperty = serializedObject.FindProperty("_useBundle"); _closeOnPauseProperty = serializedObject.FindProperty("_closeOnPause"); _sourceReceiverProperty = serializedObject.FindProperty("_localReceiver"); _localHostModeProperty = serializedObject.FindProperty("_localHostMode"); _localHostProperty = serializedObject.FindProperty("_localHost"); _localPortModeProperty = serializedObject.FindProperty("_localPortMode"); _localPortProperty = serializedObject.FindProperty("_localPort"); if (!Application.isPlaying && !_transmitter.IsStarted && _workInEditorProperty.boolValue) { _transmitter.Connect(); } }
public void Start() { Receiver.Bind(_address, ReceiveMessage); // Create Message var message = new OSCMessage(_address); // Create structure var structure = new MarshallingStructure(); structure.IntValue = 1337; structure.StringValue = "Hello, OSC World!"; structure.FloatValue = 13.37f; // Convert structure to bytes by marshalling! // Marshalling can sometimes be quicker, than any other form of conversion of data in OSC var bytes = OSCUtilities.StructToByte(structure); // Add bytes to message message.AddValue(OSCValue.Blob(bytes)); // Send message Transmitter.Send(message); }
public OSCValue Map(OSCValue value) { //FLOAT MAP if (Type == OSCMapType.Float) { value.FloatValue = OSCUtilities.Map(value.FloatValue, InputMin, InputMax, OutputMin, OutputMax, Clamp); } // FLOAT TO BOOL MAP else if (Type == OSCMapType.FloatToBool) { if (Logic == OSCMapLogic.GreaterOrEquals) { return(OSCValue.Bool(value.FloatValue >= Value)); } if (Logic == OSCMapLogic.Greater) { return(OSCValue.Bool(value.FloatValue > Value)); } if (Logic == OSCMapLogic.LessOrEquals) { return(OSCValue.Bool(value.FloatValue <= Value)); } if (Logic == OSCMapLogic.Less) { return(OSCValue.Bool(value.FloatValue < Value)); } if (Logic == OSCMapLogic.Equals) { return(OSCValue.Bool(Math.Abs(value.FloatValue - Value) <= float.Epsilon)); } } // BOOL TO FLOAT MAP else if (Type == OSCMapType.BoolToFloat) { return(OSCValue.Float(value.BoolValue ? TrueValue : FalseValue)); } // INT MAP else if (Type == OSCMapType.Int) { value.IntValue = (int)OSCUtilities.Map(value.IntValue, InputMin, InputMax, OutputMin, OutputMax, Clamp); } // INT TO BOOL MAP else if (Type == OSCMapType.IntToBool) { if (Logic == OSCMapLogic.GreaterOrEquals) { return(OSCValue.Bool(value.IntValue >= Value)); } if (Logic == OSCMapLogic.Greater) { return(OSCValue.Bool(value.IntValue > Value)); } if (Logic == OSCMapLogic.LessOrEquals) { return(OSCValue.Bool(value.IntValue <= Value)); } if (Logic == OSCMapLogic.Less) { return(OSCValue.Bool(value.IntValue < Value)); } if (Logic == OSCMapLogic.Equals) { return(OSCValue.Bool(Math.Abs(value.IntValue - Value) <= float.Epsilon)); } } // BOOL TO INT MAP else if (Type == OSCMapType.BoolToInt) { return(OSCValue.Int((int)(value.BoolValue ? TrueValue : FalseValue))); } return(value); }
public OSCPanelManager(OSCWindow parentWindow) : base(parentWindow) { _localHost = OSCUtilities.GetLocalHost(); }
public static OSCConsolePacket[] GetConsoleBuffer(bool transmitted, bool received, string filter) { if (ConsoleBuffer == null || ConsoleBuffer.Count == 0) { return(_emptyBuffer); } var requireRebuild = false; if (_previousTransmitted != transmitted || _previousReceived != received || _previousFilter != filter) { _previousTransmitted = transmitted; _previousReceived = received; _previousFilter = filter; requireRebuild = true; } else { requireRebuild = ConsoleBuffer[0] != _lastMessage; } if (!requireRebuild) { return(_tempBuffer); } _lastMessage = ConsoleBuffer[0]; var consoleList = new List <OSCConsolePacket>(); var inverse = filter.StartsWith("!"); if (inverse) { filter = filter.Remove(0, 1); } foreach (var consoleMessage in ConsoleBuffer) { if (transmitted && consoleMessage.PacketType == OSCConsolePacketType.Transmitted || received && consoleMessage.PacketType == OSCConsolePacketType.Received) { if (!string.IsNullOrEmpty(filter)) { var address = consoleMessage.Packet.Address; var compare = OSCUtilities.CompareAddresses(filter, address); if (inverse && compare || !inverse && !compare) { continue; } } consoleList.Add(consoleMessage); } } _tempBuffer = consoleList.ToArray(); return(_tempBuffer); }
public bool IsBundle() { return(OSCUtilities.IsSubclassOf(GetType(), typeof(OSCBundle))); }