Skip to content

Commit

Permalink
1.2.1 excludeLocal/Global transform params
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Dec 9, 2024
1 parent cfc4713 commit 414d3a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
42 changes: 24 additions & 18 deletions Runtime/OSCQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ public enum FilterMode { All, Include, Exclude }
public FilterMode componentFilterMode = FilterMode.Exclude;
public List<String> filteredComponentNames;
public bool excludeInternalUnityParams;
public bool excludeGlobalTransformParams;
public bool excludeLocalTransformParams;
public bool excludeThisObject = true;

String[] internalUnityParamsNames = { "name", "tag", "useGUILayout", "runInEditMode", "enabled", "hideFlags" };
String[] internalUnityTransformNames = { "localEulerAngles", "right", "up", "forward", "hasChanged", "hierarchyCapacity" };
String[] internalUnityTransformNames = { "localEulerAngles", "eulerAngles", "right", "up", "forward", "hasChanged", "hierarchyCapacity" };
String[] localTransformNames = { "localPosition", "localRotation", "localScale" };
String[] globalTransformNames = { "position", "rotation", "eulerAngles" };
String[] acceptedParamTypes = { "System.String", "System.Char", "System.Boolean", "System.Int32", "System.Int64", "System.Int16", "System.UInt16", "System.Byte", "System.SByte", "System.Double", "System.Single", "UnityEngine.Vector2", "UnityEngine.Vector3", "UnityEngine.Quaternion", "UnityEngine.Color" };

HttpServer httpServer;
Expand Down Expand Up @@ -126,8 +130,8 @@ private void OnEnable()
{
if (propQueryMap == null) propQueryMap = new Dictionary<WSQuery, List<string>>();
if (propQueryPreviousValues == null) propQueryPreviousValues = new Dictionary<string, object>();
if(filteredComponentNames == null) filteredComponentNames = new List<string>();
if(filteredObjects == null) filteredObjects = new List<GameObject>();
if (filteredComponentNames == null) filteredComponentNames = new List<string>();
if (filteredObjects == null) filteredObjects = new List<GameObject>();

if (filteredComponentNames.Count == 0)
{
Expand Down Expand Up @@ -322,7 +326,7 @@ void rebuildDataTree()
foreach (GameObject go in rootObjects)
{
if (!checkFilteredObject(go)) continue;
if(excludeThisObject && go == this.gameObject) continue;
if (excludeThisObject && go == this.gameObject) continue;
string goName = SanitizeName(go.name);
if (!co.HasField(goName)) co.SetField(goName, getObjectData(go, "/" + goName));
}
Expand All @@ -338,7 +342,7 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
JSONObject co = new JSONObject();

bool doNotExposeChildren = false;


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

Expand Down Expand Up @@ -369,7 +373,7 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")

foreach (FieldInfo info in fields)
{
if(info.GetCustomAttribute<DoNotExpose>() != null) continue;
if (info.GetCustomAttribute<DoNotExpose>() != null) continue;

RangeAttribute rangeAttribute = info.GetCustomAttribute<RangeAttribute>();

Expand All @@ -394,19 +398,21 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
{
if (!info.CanWrite) continue;

if(info.GetCustomAttribute<DoNotExpose>() != null) continue;
if (info.GetCustomAttribute<DoNotExpose>() != null) continue;

string propType = info.PropertyType.ToString();
if (!acceptedParamTypes.Contains(propType)) continue;//
//if (propType == "UnityEngine.Component") continue; //fix deprecation error
//if (propType == "UnityEngine.GameObject") continue; //fix deprecation error
//if (propType == "UnityEngine.Matrix4x4") continue; //fix deprecation error
//if (propType == "UnityEngine.Transform") continue; //fix deprecation error
//if (propType == "UnityEngine.Mesh") continue; //fix deprecation error
if (excludeInternalUnityParams)
//if (propType == "UnityEngine.Component") continue; //fix deprecation error
//if (propType == "UnityEngine.GameObject") continue; //fix deprecation error
//if (propType == "UnityEngine.Matrix4x4") continue; //fix deprecation error
//if (propType == "UnityEngine.Transform") continue; //fix deprecation error
//if (propType == "UnityEngine.Mesh") continue; //fix deprecation error
if (excludeInternalUnityParams && internalUnityParamsNames.Contains(info.Name)) continue;
if (compType == "Transform")
{
if (internalUnityParamsNames.Contains(info.Name)) continue;
if (compType == "Transform" && internalUnityTransformNames.Contains(info.Name)) continue;
if (excludeInternalUnityParams && internalUnityTransformNames.Contains(info.Name)) continue;
if (excludeGlobalTransformParams && globalTransformNames.Contains(info.Name)) continue;
if (excludeLocalTransformParams && localTransformNames.Contains(info.Name)) continue;
}


Expand Down Expand Up @@ -457,7 +463,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);
//Debug.Log(go.name + " method : " + info);

ParameterInfo[] paramInfos = info.GetParameters();
bool requiresArguments = false;
Expand Down Expand Up @@ -889,11 +895,11 @@ void sendFeedback(string address, WSQuery query)
case "Vector4":
{
Color color = dataType == "Color" ? (Color)data : (Color)(Vector4)data;

if (oldData != null)
{
Color oldColor = dataType == "Color" ? (Color)oldData : (Color)(Vector4)oldData;
if(color == oldColor) return;
if (color == oldColor) return;
}
m.Append(color.r);
m.Append(color.g);
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": "2023.2",
"unityRelease": "20f1",
"version": "1.2.0"
"version": "1.2.1"
}

0 comments on commit 414d3a8

Please sign in to comment.