Skip to content

Commit

Permalink
Add delegate for custom messages
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Jul 27, 2023
1 parent 89fc5ca commit 5846eb3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Runtime/OSCQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public enum FilterMode { All, Include, Exclude }
RegisterService zeroconfService;
RegisterService oscService;

public delegate void OnMessageReceivedEvent(OSCMessage message);
public event OnMessageReceivedEvent onMessageReceived;

void Awake()
{
}
Expand Down Expand Up @@ -296,7 +299,7 @@ void rebuildDataTree()
{
compInfoMap = new Dictionary<string, CompInfo>();

if (rootObject != null) queryData = getObjectData(rootObject, "");
if (rootObject != null) queryData = getObjectData(rootObject, "");
else
{
queryData = new JSONObject("root");
Expand Down Expand Up @@ -396,7 +399,7 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
compInfoMap.Add(fullPath, new CompInfo(comp, info));
}
}

if (compType == "VisualEffect")
{
VisualEffect vfx = comp as VisualEffect;
Expand All @@ -420,7 +423,7 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
}
else if (compType == "Volume")
{
//Volume v = comp as Volume;
//Volume v = comp as Volume;

}
else if (compType != "Transform") //Avoid methods of internal components
Expand Down Expand Up @@ -657,6 +660,7 @@ void ProcessIncomingMessages()
if (info == null)
{
//Debug.LogWarning("Address not found : " + msg.Address);
onMessageReceived?.Invoke(msg);
continue;
}

Expand Down Expand Up @@ -713,7 +717,7 @@ void ProcessIncomingMessages()
case "UnityEngine.Vector4":
{
if (msg.Data.Count == 1) data = (Color)msg.Data[0];
else if (msg.Data.Count >= 3) data = new Color(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[1]), getFloatArg(msg.Data[2]), msg.Data.Count > 3 ? getFloatArg(msg.Data[2] ): 1.0f);
else if (msg.Data.Count >= 3) data = new Color(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[1]), getFloatArg(msg.Data[2]), msg.Data.Count > 3 ? getFloatArg(msg.Data[2]) : 1.0f);
}
break;

Expand Down Expand Up @@ -775,6 +779,7 @@ void ProcessIncomingMessages()
else
{
Debug.LogWarning("Property not found for address : " + msg.Address);
onMessageReceived?.Invoke(msg);
}
}
}
Expand Down Expand Up @@ -966,7 +971,7 @@ void setVFXPropValue(VisualEffect vfx, Type type, string id, object value)
// Helper
float getFloatArg(object data)
{
return (data is int)? (float)(int)data : (float)data;
return (data is int) ? (float)(int)data : (float)data;
}
}
}

0 comments on commit 5846eb3

Please sign in to comment.