Skip to content

Commit

Permalink
fix warnings and fix float casting
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Sep 16, 2021
1 parent 3425d0a commit a836309
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Runtime/JSON/Editor/JSONChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void OnGUI()
#if UNITY_2017_1_OR_NEWER
var test = new UnityWebRequest(URL);
test.SendWebRequest();
while (!test.isDone && !test.isNetworkError) ;
while (!test.isDone && !(test.result == UnityWebRequest.Result.ConnectionError)) ;
#else
var test = new WWW(URL);
while (!test.isDone) ;
Expand Down
77 changes: 41 additions & 36 deletions Runtime/OSCQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public enum InfoType { Property, Field, Method, VFX, Material };
public FieldInfo fieldInfo;
public PropertyInfo propInfo;
public MethodInfo methodInfo;
public struct GenericInfo

public struct GenericInfo
{
public GenericInfo(Type type, string name)
{
Expand Down Expand Up @@ -350,7 +350,7 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
{
RangeAttribute rangeAttribute = info.GetCustomAttribute<RangeAttribute>();

Debug.Log(go.name+" > Info field type : " +info.FieldType.ToString() +" /" +compType);
//Debug.Log(go.name+" > Info field type : " +info.FieldType.ToString() +" /" +compType);

JSONObject io = getPropObject(info.FieldType, info.GetValue(comp), rangeAttribute, info.Name == "mainColor");

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

// Debug.Log("Comp type : " + compType);
// Debug.Log("Comp type : " + compType);

if (compType == "VisualEffect")
{
Expand All @@ -406,8 +406,8 @@ JSONObject getObjectData(GameObject go, string baseAddress = "")
{
//Debug.Log("Here " + p.name+" / "+p.type.ToString());
JSONObject io = getPropObject(p.type, getVFXPropValue(vfx, p.type, p.name));
if(io != null)

if (io != null)
{
string sName = SanitizeName(p.name);
string fullPath = compAddress + "/" + sName;
Expand Down Expand Up @@ -563,21 +563,21 @@ JSONObject getPropObject(Type type, object value, RangeAttribute range = null, b
}
break;

/*
case "UnityEngine.Material":
/*
case "UnityEngine.Material":
{
Material m = (Material)value;
if(m != null)
{
Material m = (Material)value;
if(m != null)
int numProps = m.shader.GetPropertyCount();
for(int i=0;i<numProps;i++)
{
int numProps = m.shader.GetPropertyCount();
for(int i=0;i<numProps;i++)
{
m.shader.GetPropertyAttributes(i);
}
m.shader.GetPropertyAttributes(i);
}
}
break;
*/
}
break;
*/
default:
if (type.IsEnum)
{
Expand Down Expand Up @@ -641,27 +641,26 @@ void ProcessIncomingMessages()
string args = "";
msg.Data.ForEach((arg) => args += arg.ToString() + ", ");

Debug.Log("info received : " + msg.Address);
//Debug.Log("info received : " + msg.Address);
if (compInfoMap.ContainsKey(msg.Address))
{
CompInfo info = compInfoMap[msg.Address];
object data = null;

if (info == null)
{
Debug.LogWarning("Address not found : " + msg.Address);
//Debug.LogWarning("Address not found : " + msg.Address);
continue;
}


if (info.infoType == CompInfo.InfoType.Method)
{
int numParams = info.methodInfo.GetParameters().Length;
info.methodInfo.Invoke(info.comp, Enumerable.Repeat(Type.Missing, numParams).ToArray());
continue;
}

Debug.Log(info.genericInfo + "/" + info.type);
string typeString = info.type.ToString();

switch (typeString)
Expand All @@ -687,27 +686,27 @@ void ProcessIncomingMessages()

case "System.Double":
case "System.Single":
data = (float)msg.Data[0];
data = getFloatArg(msg.Data[0]);
break;

case "UnityEngine.Vector2":
data = new Vector2((float)msg.Data[0], (float)msg.Data[1]);
data = new Vector2(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[0]));
break;

case "UnityEngine.Vector3":
data = new Vector3((float)msg.Data[0], (float)msg.Data[1], (float)msg.Data[2]);
data = new Vector3(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[1]), getFloatArg(msg.Data[2]));

break;

case "UnityEngine.Quaternion":
data = Quaternion.Euler(new Vector3((float)msg.Data[0], (float)msg.Data[1], (float)msg.Data[2]));
data = Quaternion.Euler(new Vector3(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[1]), getFloatArg(msg.Data[2])));
break;

case "UnityEngine.Color":
case "UnityEngine.Vector4":
{
if (msg.Data.Count == 1) data = (Color)msg.Data[0];
else if (msg.Data.Count >= 3) data = new Color((float)msg.Data[0], (float)msg.Data[1], (float)msg.Data[2], msg.Data.Count > 3 ? (float)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 All @@ -724,7 +723,7 @@ void ProcessIncomingMessages()
if (field.Name.Equals("value__")) continue;
if (field.Name == msg.Data[0].ToString())
{
Debug.Log("Found enum " + field.Name + " > " + field.GetRawConstantValue());
//Debug.Log("Found enum " + field.Name + " > " + field.GetRawConstantValue());
data = field.GetRawConstantValue();
}
}
Expand Down Expand Up @@ -753,11 +752,11 @@ void ProcessIncomingMessages()
break;

case CompInfo.InfoType.Material:
/* {
int dotIndex = info.comp.GetType().ToString().LastIndexOf(".");
string compType = info.comp.GetType().ToString().Substring(Mathf.Max(dotIndex + 1, 0));
setMaterialPropValue((info.comp as VisualEffect), info.genericInfo.type, info.genericInfo.name, data);
}*/
/* {
int dotIndex = info.comp.GetType().ToString().LastIndexOf(".");
string compType = info.comp.GetType().ToString().Substring(Mathf.Max(dotIndex + 1, 0));
setMaterialPropValue((info.comp as VisualEffect), info.genericInfo.type, info.genericInfo.name, data);
}*/
break;
}
}
Expand Down Expand Up @@ -923,20 +922,20 @@ void setVFXPropValue(VisualEffect vfx, Type type, string id, object value)
case "System.UInt16":
case "System.Byte":
case "System.SByte":
vfx.SetInt(id,(int)value);
vfx.SetInt(id, (int)value);
break;

case "System.Double":
case "System.Single":
vfx.SetFloat(id,(float)value);
vfx.SetFloat(id, (float)value);
break;

case "UnityEngine.Vector2":
vfx.SetVector2(id,(Vector2)value);
vfx.SetVector2(id, (Vector2)value);
break;

case "UnityEngine.Vector3":
vfx.SetVector3(id,(Vector3)value);
vfx.SetVector3(id, (Vector3)value);
break;

case "UnityEngine.Quaternion":
Expand All @@ -949,5 +948,11 @@ void setVFXPropValue(VisualEffect vfx, Type type, string id, object value)
}

}

// Helper
float getFloatArg(object data)
{
return (data is int)? (float)(int)data : (float)data;
}
}
}

0 comments on commit a836309

Please sign in to comment.