diff --git a/Runtime/OSCQuery.cs b/Runtime/OSCQuery.cs index 48b1097..daab276 100644 --- a/Runtime/OSCQuery.cs +++ b/Runtime/OSCQuery.cs @@ -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) @@ -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); @@ -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(); @@ -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(); + if (nochildrenAttribute != null) doNotExposeChildren = true; + string compAddress = baseAddress + "/" + compType; JSONObject cco = new JSONObject(); @@ -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; @@ -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; } diff --git a/package.json b/package.json index bda851e..799638f 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,5 @@ "repository": "github:benkper/Unity-OSCQuery", "unity": "2018.3", "unityRelease": "0f1", - "version": "1.1.2" + "version": "1.1.3" }