Skip to content

Commit

Permalink
Added custom attributes and field check
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Jan 23, 2024
1 parent dbc0302 commit 62bd04d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
37 changes: 29 additions & 8 deletions Runtime/OSCQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
using UnityEngine.VFX;
using UnityEngine.Rendering;



namespace OSCQuery
{
[AttributeUsage(AttributeTargets.Class)]
public class DoNotExpose : Attribute { }

[AttributeUsage(AttributeTargets.Class)]
public class DoNotExposeChildren : Attribute { }

public class CompInfo
{
public CompInfo(Component comp, FieldInfo info)
Expand Down Expand Up @@ -312,7 +320,7 @@ void rebuildDataTree()
{
if (!checkFilteredObject(go)) continue;
string goName = SanitizeName(go.name);
co.SetField(goName, getObjectData(go, "/" + goName));
if (!co.HasField(goName)) co.SetField(goName, getObjectData(go, "/" + goName));
}

queryData.SetField("CONTENTS", co);
Expand All @@ -324,13 +332,9 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
JSONObject o = new JSONObject();
o.SetField("ACCESS", 0);
JSONObject co = new JSONObject();
for (int i = 0; i < go.transform.childCount; i++)
{
GameObject cgo = go.transform.GetChild(i).gameObject;
if (!checkFilteredObject(cgo)) continue;
string cgoName = SanitizeName(cgo.name);
co.SetField(cgoName, getObjectData(cgo, baseAddress + "/" + cgoName));
}

bool doNotExposeChildren = false;


Component[] comps = go.GetComponents<Component>();

Expand All @@ -342,6 +346,9 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
//Debug.Log(go.name+" > Comp : " + compType);
if (!checkFilteredComp(compType)) continue;

DoNotExposeChildren nochildrenAttribute = comp.GetType().GetCustomAttribute<DoNotExposeChildren>();
if (nochildrenAttribute != null) doNotExposeChildren = true;

string compAddress = baseAddress + "/" + compType;

JSONObject cco = new JSONObject();
Expand Down Expand Up @@ -432,6 +439,7 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
foreach (MethodInfo info in methods)
{
if (info.IsSpecialName && (info.Name.StartsWith("set_") || info.Name.StartsWith("get_"))) continue; //do not care for accessors
Debug.Log(go.name + " method : " + info);

ParameterInfo[] paramInfos = info.GetParameters();
bool requiresArguments = false;
Expand Down Expand Up @@ -468,8 +476,21 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
co.SetField(SanitizeName(compType), cco);
}

if (!doNotExposeChildren)
{
for (int i = 0; i < go.transform.childCount; i++)
{
GameObject cgo = go.transform.GetChild(i).gameObject;
if (!checkFilteredObject(cgo)) continue;
string cgoName = SanitizeName(cgo.name);
co.SetField(cgoName, getObjectData(cgo, baseAddress + "/" + cgoName));
}
}

o.SetField("CONTENTS", co);



return o;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"repository": "github:benkper/Unity-OSCQuery",
"unity": "2018.3",
"unityRelease": "0f1",
"version": "1.1.2"
"version": "1.1.3"
}

0 comments on commit 62bd04d

Please sign in to comment.