private void SetLocalCollision(string planetName, bool enabled = true) { var localPlanet = PFUtil.FindLocal(planetName); var cols = localPlanet.GetComponentsInChildren <Collider>(); foreach (var c in cols) { if (c.enabled != enabled) { print("Updating collision " + c.gameObject.name + "=" + enabled); c.enabled = enabled; } } }
public static void LoadPQS(string bodyName) { var localGameObject = PFUtil.FindLocal(bodyName);// localSpace.transform.FindChild(body.name).gameObject; print("load config"); print(typeof(PQSMod).AssemblyQualifiedName); var root = ConfigNode.Load(DataPath + bodyName + ".cfg"); var pqs = localGameObject.GetComponentInChildren <PQS>(); //Remove PQS cities. TODO:Refactor. var mods = localGameObject.GetComponentsInChildren <PQSMod>(true); foreach (var mod in mods) { if (mod.GetType().ToString().Contains("PQSCity")) { mod.modEnabled = false; mod.gameObject.SetActive(false); Destroy(mod.gameObject); print("Removed PQSCity:"); } } for (int ni = 0; ni < root.nodes.Count; ni++) { var node = root.nodes[ni]; if (!node.name.ToLower().StartsWith("pqs")) { continue; } var componentTypeStr = node.name; var componentType = Type.GetType(componentTypeStr + ", Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); if (componentType == null) { componentType = Type.GetType(componentTypeStr + ", PlanetFactory, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); } if (componentType == null) { print("Cant find PQSMod type:" + componentTypeStr); continue; } var component = localGameObject.GetComponentInChildren(componentType); if (component == null) { //print("pqs not found"); if (node.HasValue("modEnabled")) { //print("is pqs mod " + node.GetValue("modEnabled")); if (node.GetValue("modEnabled").ToLower() == "true") { //print("Adding PQSMOD:" + componentTypeStr); var newgob = new GameObject(); var newComponent = (PQSMod)newgob.AddComponent(componentType); newgob.transform.parent = pqs.gameObject.transform; newComponent.sphere = pqs; component = newComponent; } } } if (component != null) { print("Loading Config PQS:");// + Dump.GetGobPath(component.gameObject)); LoadConfiguration(component, node); try { //print("Rebuilding"); var mod = (PQSMod)component; mod.RebuildSphere(); } catch { //print("failed"); } } } if (pqs != null) { pqs.RebuildSphere(); } }