public static Type GetParamType(OscMessageType type)
        {
            Type paramType = null;

            switch (type)
            {
            case OscMessageType.OscMessage: paramType = typeof(OscMessage); break;

            case OscMessageType.Float: paramType = typeof(float); break;

            case OscMessageType.Double: paramType = typeof(double); break;

            case OscMessageType.Int: paramType = typeof(int); break;

            case OscMessageType.Long: paramType = typeof(long); break;

            case OscMessageType.String: paramType = typeof(string); break;

            case OscMessageType.Char: paramType = typeof(char); break;

            case OscMessageType.Bool: paramType = typeof(bool); break;

            case OscMessageType.Color: paramType = typeof(Color32); break;

            case OscMessageType.Blob: paramType = typeof(byte[]); break;

            case OscMessageType.TimeTag: paramType = typeof(OscTimeTag); break;

            case OscMessageType.Midi: paramType = typeof(OscMidiMessage); break;
            }
            return(paramType);
        }
Beispiel #2
0
 bool GetOrCreateMapping(string address, OscMessageType type, out OscMapping mapping)
 {
     mapping = _mappings.Find(m => m.address == address);
     if (mapping == null)
     {
         mapping = new OscMapping(address, type);
         //mapping = ScriptableObject.CreateInstance<OscMapping>();
         //mapping.Init( address, type );
         _mappings.Add(mapping);
     }
     else if (mapping.type != type)
     {
         if (OscGlobals.logWarnings)
         {
             StringBuilder sb = OscDebug.BuildText(this);
             sb.Append("Failed to map address \""); sb.Append(address);
             sb.Append("\" to method with argument type "); sb.Append(type);
             sb.Append(". \nAddress is already mapped to a method with argument type "); sb.Append(mapping.type);
             sb.Append(", either in the editor, or by a script. Only one type per address is allowed.\n");
             Debug.LogWarning(sb.ToString());
         }
         return(false);
     }
     return(true);
 }
Beispiel #3
0
 bool GetOrCreateMapping(string address, OscMessageType type, out OscMapping mapping)
 {
     mapping = _mappings.Find(m => m.address == address);
     if (mapping == null)
     {
         mapping = new OscMapping(address, type);
         _mappings.Add(mapping);
     }
     else if (mapping.type != type)
     {
         Debug.LogWarning(BuildFailedToMapMessage(address, type, mapping.type));
         return(false);
     }
     return(true);
 }
Beispiel #4
0
    void Unmap <T>(Action <T> method, OscMessageType type)
    {
        for (int m = _mappings.Count - 1; m >= 0; m--)
        {
            OscMapping mapping = _mappings[m];

            mapping.Unmap(method.Target, method.Method);

            // If there are no methods mapped to the hanlder left, then remove mapping.
            if (mapping.entryCount == 0)
            {
                _mappings.RemoveAt(m);
            }
        }
        _dirtyMappings = true;
    }
Beispiel #5
0
    void Map <T>(string address, UnityAction <T> method, OscMessageType type)
    {
        // Validate.
        if (!ValidateAddressForMapping(address) || method == null || !ValidateMethodTarget(method.Target, address))
        {
            return;
        }

        // Get or create mapping.
        OscMapping mapping = null;

        GetOrCreateMapping(address, type, out mapping);

        // Add listener.
        switch (type)
        {
        case OscMessageType.OscMessage: mapping.OscMessageHandler.AddPersistentListener(method as UnityAction <OscMessage>); break;

        case OscMessageType.Bool: mapping.BoolHandler.AddPersistentListener(method as UnityAction <bool>); break;

        case OscMessageType.Float: mapping.FloatHandler.AddPersistentListener(method as UnityAction <float>); break;

        case OscMessageType.Int: mapping.IntHandler.AddPersistentListener(method as UnityAction <int>); break;

        case OscMessageType.Char: mapping.CharHandler.AddPersistentListener(method as UnityAction <char>); break;

        case OscMessageType.Color: mapping.ColorHandler.AddPersistentListener(method as UnityAction <Color32>); break;

        case OscMessageType.Midi: mapping.MidiHandler.AddPersistentListener(method as UnityAction <OscMidiMessage>); break;

        case OscMessageType.Double: mapping.DoubleHandler.AddPersistentListener(method as UnityAction <double>); break;

        case OscMessageType.Long: mapping.LongHandler.AddPersistentListener(method as UnityAction <long>); break;

        case OscMessageType.TimeTag: mapping.TimeTagHandler.AddPersistentListener(method as UnityAction <OscTimeTag>); break;

        case OscMessageType.String: mapping.StringHandler.AddPersistentListener(method as UnityAction <string>); break;

        case OscMessageType.Blob: mapping.BlobHandler.AddPersistentListener(method as UnityAction <byte[]>); break;
        }

        // Set dirty flag.
        _dirtyMappings = true;
    }
Beispiel #6
0
    void Map <T>(string address, Action <T> method, OscMessageType type)
    {
        // Validate.
        if (!ValidateAddressForMapping(address) || method == null || !ValidateMethodTarget(method.Target, address))
        {
            return;
        }

        // Get or create mapping.
        OscMapping mapping = null;

        GetOrCreateMapping(address, type, out mapping);

        // Add listener.
        mapping.Map(method.Target, method.Method);

        // Set dirty flag.
        _dirtyMappings = true;
    }
Beispiel #7
0
 bool GetOrCreateMapping(string address, OscMessageType type, out OscMapping mapping)
 {
     mapping = _mappings.Find(m => m.address == address);
     if (mapping == null)
     {
         mapping = new OscMapping(address, type);
         _mappings.Add(mapping);
     }
     else if (mapping.type != type)
     {
         StringBuilder sb = OscDebug.BuildText(this);
         sb.Append("Failed to map address'"); sb.Append(address);
         sb.Append("' to method with argument type '"); sb.Append(type);
         sb.Append("'. Address is already set to receive type '"); sb.Append(mapping.type);
         sb.Append("', either in the editor, or by a script.\nOnly one type per address is allowed.\n");
         Debug.LogWarning(sb.ToString());
         return(false);
     }
     return(true);
 }
 public void Map(Action <byte[]> m)
 {
     _type = OscMessageType.Blob; Map(m.Target, m.Method);
 }
 public void Map(Action <OscTimeTag> m)
 {
     _type = OscMessageType.TimeTag; Map(m.Target, m.Method);
 }
 public void Map(Action <bool> m)
 {
     _type = OscMessageType.Bool; Map(m.Target, m.Method);
 }
 public void Map(Action <Color32> m)
 {
     _type = OscMessageType.Color; Map(m.Target, m.Method);
 }
 public void Map(Action <string> m)
 {
     _type = OscMessageType.String; Map(m.Target, m.Method);
 }
 public void Map(Action <char> m)
 {
     _type = OscMessageType.Char; Map(m.Target, m.Method);
 }
 public void Map(Action <double> m)
 {
     _type = OscMessageType.Double; Map(m.Target, m.Method);
 }
 public void Map(Action <int> m)
 {
     _type = OscMessageType.Int; Map(m.Target, m.Method);
 }
Beispiel #16
0
    void Unmap <T>(UnityAction <T> method, OscMessageType type)
    {
        for (int m = _mappings.Count - 1; m >= 0; m--)
        {
            OscMapping mapping = _mappings[m];

            int eventCount = 0;
            switch (type)
            {
            case OscMessageType.OscMessage:
                mapping.OscMessageHandler.RemovePersistentListener(method as UnityAction <OscMessage>);
                eventCount = mapping.OscMessageHandler.GetPersistentEventCount(); break;

            case OscMessageType.Bool:
                mapping.BoolHandler.RemovePersistentListener(method as UnityAction <bool>);
                eventCount = mapping.BoolHandler.GetPersistentEventCount(); break;

            case OscMessageType.Float:
                mapping.FloatHandler.RemovePersistentListener(method as UnityAction <float>);
                eventCount = mapping.FloatHandler.GetPersistentEventCount(); break;

            case OscMessageType.Int:
                mapping.IntHandler.RemovePersistentListener(method as UnityAction <int>);
                eventCount = mapping.IntHandler.GetPersistentEventCount(); break;

            case OscMessageType.Char:
                mapping.CharHandler.RemovePersistentListener(method as UnityAction <char>);
                eventCount = mapping.CharHandler.GetPersistentEventCount(); break;

            case OscMessageType.Color:
                mapping.ColorHandler.RemovePersistentListener(method as UnityAction <Color32>);
                eventCount = mapping.ColorHandler.GetPersistentEventCount(); break;

            case OscMessageType.Midi:
                mapping.MidiHandler.RemovePersistentListener(method as UnityAction <OscMidiMessage>);
                eventCount = mapping.MidiHandler.GetPersistentEventCount(); break;

            case OscMessageType.Double:
                mapping.DoubleHandler.RemovePersistentListener(method as UnityAction <double>);
                eventCount = mapping.DoubleHandler.GetPersistentEventCount(); break;

            case OscMessageType.Long:
                mapping.LongHandler.RemovePersistentListener(method as UnityAction <long>);
                eventCount = mapping.LongHandler.GetPersistentEventCount(); break;

            case OscMessageType.TimeTag:
                mapping.TimeTagHandler.RemovePersistentListener(method as UnityAction <OscTimeTag>);
                eventCount = mapping.TimeTagHandler.GetPersistentEventCount(); break;

            case OscMessageType.String:
                mapping.StringHandler.RemovePersistentListener(method as UnityAction <string>);
                eventCount = mapping.StringHandler.GetPersistentEventCount(); break;

            case OscMessageType.Blob:
                mapping.BlobHandler.RemovePersistentListener(method as UnityAction <byte[]>);
                eventCount = mapping.BlobHandler.GetPersistentEventCount(); break;
            }

            // If there are no methods mapped to the hanlder left, then remove mapping.
            if (eventCount == 0)
            {
                _mappings.RemoveAt(m);
            }
        }
        _dirtyMappings = true;
    }
 public void Map(Action m)
 {
     _type = OscMessageType.ImpulseNullEmpty; Map(m.Target, m.Method);
 }
 public OscMapping( string address, OscMessageType type )
     : this()
 {
     this.address = address;
     this.type = type;
 }
Beispiel #19
0
    void Map <T>(string address, UnityAction <T> method, OscMessageType type)
    {
        if (string.IsNullOrEmpty(address))
        {
            return;
        }
        if (method == null)
        {
            return;
        }
        if (!ValidateAddressForMapping(address))
        {
            return;
        }

        // Get or create mapping
        OscMapping mapping = null;

        GetOrCreateMapping(address, type, out mapping);

        // Add listener
        switch (type)
        {
        case OscMessageType.OscMessage: mapping.OscMessageHandler.AddListener(method as UnityAction <OscMessage>); break;

        case OscMessageType.Float:              mapping.FloatHandler.AddListener(method as UnityAction <float>); break;

        case OscMessageType.Double:             mapping.DoubleHandler.AddListener(method as UnityAction <double>); break;

        case OscMessageType.Int:                mapping.IntHandler.AddListener(method as UnityAction <int>); break;

        case OscMessageType.Long:               mapping.LongHandler.AddListener(method as UnityAction <long>); break;

        case OscMessageType.String:             mapping.StringHandler.AddListener(method as UnityAction <string>); break;

        case OscMessageType.Char:               mapping.CharHandler.AddListener(method as UnityAction <char>); break;

        case OscMessageType.Bool:               mapping.BoolHandler.AddListener(method as UnityAction <bool>); break;

        case OscMessageType.Color:              mapping.ColorHandler.AddListener(method as UnityAction <Color32>); break;

        case OscMessageType.Blob:               mapping.BlobHandler.AddListener(method as UnityAction <byte[]>); break;

        case OscMessageType.TimeTag:    mapping.TimeTagHandler.AddListener(method as UnityAction <OscTimeTag>); break;
        }

        // Add mapping inspector info (To unmap runtime handler, knowing we did it. Because UnityEvent is a black box)
        mapping.runtimeMethodInfo.Add(method.Method);

        // For display in inspector
        string handlerLabel;

        if (method.Target == null)
        {
            handlerLabel = "delegate";
        }
        else
        {
            handlerLabel = GetMethodLabel(method.Target, method.Method);
        }
        mapping.runtimeMethodLabels.Add(handlerLabel);

        // Set dirty flag
        _dirtyMappings = true;
    }
Beispiel #20
0
 string BuildFailedToMapMessage(string address, OscMessageType type, OscMessageType mappedType)
 {
     return(string.Format(
                "<b>[OscIn]</b> Failed to map address'{0}' to method with argument type '{1}'. Address is already set to receive type '{2}', either in the editor, or by a script. " + Environment.NewLine
                + "Only one type per address is allowed.", address, type, mappedType));
 }
 public OscMapping(string address, OscMessageType type)
 {
     this.address = address;
     _type        = type;
 }
 public void Map(Action <float> m)
 {
     _type = OscMessageType.Float; Map(m.Target, m.Method);
 }