public GameObject SelectParentbyType(GameObject gameObject, WXUtility.ComponentType type) { if ((UnityEngine.Object)gameObject.transform.parent == (UnityEngine.Object)null) { return(null); } GameObject gameObject2 = gameObject.transform.parent.gameObject; if (WXUtility.componentsOnGameObject(gameObject2).IndexOf(type) != -1) { return(gameObject2); } return(SelectParentbyType(gameObject2, type)); }
public static bool FindNotLegalChild(GameObject gameObject) { if (WXUtility.componentsOnGameObject(gameObject).Count <= 1) { return(true); } for (int i = 0; i < gameObject.transform.childCount; i++) { GameObject childObject = gameObject.transform.GetChild(i).gameObject; if (FindNotLegalChild(childObject)) { return(true); } } return(false); }
public JSONObject GetAvatarNodeData(GameObject gameObject, GameObject animatorGameObject, ref int id, string path = "") { bool currentNodeHasNotLegalChild = FindNotLegalChild(gameObject); if ( ( (UnityEngine.Object)SelectParentbyType( gameObject, WXUtility.ComponentType.Animator ) != (UnityEngine.Object)animatorGameObject || WXUtility .componentsOnGameObject(gameObject) .IndexOf(WXUtility.ComponentType.Animator) != -1 ) && (UnityEngine.Object)gameObject != (UnityEngine.Object)animatorGameObject ) { return(null); } if (currentNodeHasNotLegalChild) { JSONObject nodeJSON = new JSONObject(JSONObject.Type.OBJECT); JSONObject nodeProps = new JSONObject(JSONObject.Type.OBJECT); JSONObject translate = new JSONObject(JSONObject.Type.ARRAY); JSONObject rotation = new JSONObject(JSONObject.Type.ARRAY); JSONObject scale = new JSONObject(JSONObject.Type.ARRAY); Vector3 localPosition = gameObject.transform.localPosition; Quaternion localRotation = gameObject.transform.localRotation; Vector3 localScale = gameObject.transform.localScale; nodeProps.AddField("name", gameObject.name); nodeJSON.AddField("props", nodeProps); translate = new JSONObject(JSONObject.Type.ARRAY); nodeProps.AddField("translate", translate); translate.Add(localPosition.x * -1f); translate.Add(localPosition.y); translate.Add(localPosition.z); rotation = new JSONObject(JSONObject.Type.ARRAY); nodeProps.AddField("rotation", rotation); rotation.Add(localRotation.x * -1f); rotation.Add(localRotation.y); rotation.Add(localRotation.z); rotation.Add(localRotation.w * -1f); scale = new JSONObject(JSONObject.Type.ARRAY); nodeProps.AddField("scale", scale); scale.Add(localScale.x); scale.Add(localScale.y); scale.Add(localScale.z); id = id + 1; if (id > -1) { if (path.Length > 0) { path = path + "/" + gameObject.name; } else { path = gameObject.name; } } JSONObject nodeChildrenArray = new JSONObject(JSONObject.Type.ARRAY); if (gameObject.transform.childCount > 0) { for (int i = 0; i < gameObject.transform.childCount; i++) { JSONObject child = GetAvatarNodeData(gameObject.transform.GetChild(i).gameObject, animatorGameObject, ref id, path); if (child != null) { nodeChildrenArray.Add(child); } } } nodeJSON.AddField("child", nodeChildrenArray); return(nodeJSON); } return(null); }