public static object ReadComponent(GameObject gameObject, string entire_name, string st, Type gOType, object obj, ReadSimpleProperty ReadSimpleProperty) { ////Debug.unityLogger.logEnabled = false; string parentName = st.Substring(0, st.IndexOf("^")); string child = st.Substring(st.IndexOf("^") + 1, st.Length - st.IndexOf("^") - 1); MyDebugger.MyDebug("component " + entire_name + " parent " + parentName + " child " + child + " goType " + gOType); if (gOType == typeof(GameObject)) { MyDebugger.MyDebug(gameObject.name + " is the GO"); foreach (Component c in gameObject.GetComponents(typeof(MonoBehaviour))) { if (c.GetType().Name.Equals(parentName)) { MyDebugger.MyDebug("component " + c); if (!child.Contains("^")) { MyDebugger.MyDebug(" of type " + c.GetType()); return(ReadSimpleProperty(child, c.GetType(), c)); } else { return(ReadComposedProperty(gameObject, entire_name, child, c.GetType(), c, ReadSimpleProperty)); } } } } return(null); }
public static object ReadComposedProperty(GameObject gameObject, string entire_name, string st, Type objType, object obj, ReadSimpleProperty ReadSimpleProperty) { ////Debug.unityLogger.logEnabled = false; string parentName = st.Substring(0, st.IndexOf("^")); string child = st.Substring(st.IndexOf("^") + 1, st.Length - st.IndexOf("^") - 1); MemberInfo[] members = objType.GetMember(parentName, SensorsUtility.BindingAttr); MyDebugger.MyDebug("members with name " + parentName + " " + members.Length); if (members.Length == 0) { return(ReadComponent(gameObject, entire_name, st, objType, obj, ReadSimpleProperty)); } FieldOrProperty parentProperty = new FieldOrProperty(members[0]); ///MyDebugger.MyDebug(parentProperty.Name()); object parent = parentProperty.GetValue(obj); Type parentType = parent.GetType(); if (!child.Contains("^")) { return(ReadSimpleProperty(child, parentType, parent)); } else { return(ReadComposedProperty(gameObject, entire_name, child, parentType, parent, ReadSimpleProperty)); } }