private static JObject GetCollidersRecursive(Transform currentLevel) { var collidersOnThis = currentLevel.gameObject.GetComponents <Collider>(); JArray colliderList = null; if (collidersOnThis.Length > 0) { colliderList = ComponentsToJson.Colliders(collidersOnThis); } JArray children = null; if (currentLevel.childCount > 0) { children = new JArray(); foreach (Transform child in currentLevel) { JObject childJson = GetCollidersRecursive(child); if (childJson != null) { children.Add(childJson); } } } if ((colliderList != null) || ((children != null) && (children.Count > 0))) { JObject result = new JObject() { new JProperty("name", currentLevel.name) }; if (colliderList != null) { result.Add(new JProperty("colliders", colliderList)); } if ((children != null) && (children.Count > 0)) { result.Add(new JProperty("children", children)); } return(result); } else { return(null); } }
public static void ExportCarColliders(CommandArg[] args) { if (Terminal.IssuedError) { return; } string name = args[0].String; if (Enum.TryParse(name, out TrainCarType carType)) { GameObject prefab = CarTypes.GetCarPrefab(carType); if (!prefab) { Debug.LogError($"CarType {name} has missing prefab"); return; } Transform colliderRoot = prefab.transform.Find("[colliders]"); if (!colliderRoot) { Debug.LogWarning($"CarType {name} does not have a colliders root transform"); return; } var colliderDict = new JObject(); foreach (string categoryName in colliderCategories) { Transform subTransform = colliderRoot.Find(categoryName); if (subTransform) { Collider[] colliders = subTransform.gameObject.GetComponentsInChildren <Collider>(); var colliderCategory = ComponentsToJson.Colliders(colliders); colliderDict.Add(new JProperty(categoryName, colliderCategory)); } } GameObjectDumper.SendJsonToFile(name, "colliders", colliderDict); } else { Debug.LogWarning("Invalid car type " + name); } }