internal static void ExtractDesertLights() { StaticModel model = StaticDatabase.GetModelByName("SQUAD_Desert_Runway"); Transform lights1 = model.prefab.transform.FindRecursive("Section1_lights"); string modelName = "SQUAD_Runway_Lights"; StaticModel lightsModel = new StaticModel(); lightsModel.prefab = lights1.gameObject; // dishModel.prefab.transform.parent = null; lightsModel.name = modelName; lightsModel.path = "KerbalKonstructs/" + modelName; lightsModel.configPath = model.path + ".cfg"; lightsModel.keepConvex = true; lightsModel.title = "Desert Runway Lights"; lightsModel.mesh = modelName; lightsModel.category = "Runway"; lightsModel.author = "Squad"; lightsModel.manufacturer = "Squad"; lightsModel.description = "Squad original Desert Runway Lights"; lightsModel.isSquad = true; StaticDatabase.RegisterModel(lightsModel, lightsModel.name); }
internal static void PimpLv2Runway(GameObject modelPrefab) { //StaticModel model = StaticDatabase.GetModelByName("KSC_Runway_level_2"); StaticModel modelLights = StaticDatabase.GetModelByName("SQUAD_Runway_Lights"); int count = 0; foreach (Transform target in modelPrefab.transform.FindAllRecursive("fxTarget")) { GameObject light = GameObject.Instantiate(modelLights.prefab); //light.transform.localPosition = target.localPosition; //light.transform.localRotation = target.localRotation; light.transform.localScale *= 0.6f; light.transform.parent = target.parent.FindRecursiveContains("runway"); //light.transform.parent = modelPrefab.transform; //light.transform.localRotation = model.prefab.transform.localRotation; //light.transform.localPosition = target.localPosition; light.transform.position = target.position; light.transform.rotation = modelPrefab.transform.rotation; light.transform.Translate(light.transform.up * 0.85f); light.transform.Translate(light.transform.right * 50); if (count > 1 && count < 7) { light.transform.Translate(light.transform.right * 55); } light.name = light.transform.parent.name + "_lights"; count++; } }
private static void Initialize() { foreach (DestructibleBuilding building in StaticDatabase.GetModelByName("KSC_VehicleAssemblyBuilding_level_3").prefab.GetComponentsInChildren <DestructibleBuilding>(true)) { if (building.name == "mainBuilding") { demolitionPrefab = building.DemolitionFXPrefab; } } foreach (DestructibleBuilding building in Resources.FindObjectsOfTypeAll <DestructibleBuilding>()) { if (building.name == "CornerLab") { foreach (var bla in building.CollapsibleObjects) { if (bla.SecondaryFXPrefab != null) { secondaryPrefab = bla.SecondaryFXPrefab; } } } } isInitialized = true; }
public static string SpawnObject(string modelName) { StaticModel model = StaticDatabase.GetModelByName(modelName); if (model != null) { return(CareerEditor.instance.SpawnInstance(model, 3f, KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position))); } else { Log.UserError("API:SpawnObject: Could not find selected KK-Model named: " + modelName); return(null); } }
public static void LoadBuilding(ConfigNode cfgNode) { StaticInstance instance = new StaticInstance(); instance.isInSavegame = true; instance.Orientation = Vector3.up; instance.heighReference = HeightReference.Terrain; instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000); instance.Group = "SaveGame"; instance.RadialPosition = ConfigNode.ParseVector3(cfgNode.GetValue("Position")); instance.model = StaticDatabase.GetModelByName(cfgNode.GetValue("ModelName")); if (instance.model == null) { Log.UserError("LoadFromSave: Canot find model named: " + cfgNode.GetValue("ModelName")); instance = null; return; } //instance.mesh = UnityEngine.Object.Instantiate(instance.model.prefab); instance.UUID = cfgNode.GetValue("UUID"); instance.CelestialBody = ConfigUtil.GetCelestialBody(cfgNode.GetValue("Body")); instance.RadiusOffset = float.Parse(cfgNode.GetValue("Altitude")); instance.RotationAngle = float.Parse(cfgNode.GetValue("Rotation")); instance.RefLatitude = KKMath.GetLatitudeInDeg(instance.RadialPosition); instance.RefLongitude = KKMath.GetLongitudeInDeg(instance.RadialPosition); InstanceUtil.CreateGroupCenterIfMissing(instance); if (cfgNode.HasValue("IsScanable")) { bool.TryParse(cfgNode.GetValue("IsScanable"), out instance.isScanable); } bool oldLegacySpawn = KerbalKonstructs.convertLegacyConfigs; instance.Orientate(); KerbalKonstructs.convertLegacyConfigs = oldLegacySpawn; }
internal static void PimpLv2Runway(GameObject modelPrefab, bool state = false) { StaticModel modelLights = StaticDatabase.GetModelByName("SQUAD_Runway_Lights"); //Log.Normal("Prefab name: " + modelPrefab.name); int count = 0; foreach (Transform target in modelPrefab.transform.FindAllRecursive("fxTarget")) { GameObject light = GameObject.Instantiate(modelLights.prefab); light.SetActive(state); //Log.Normal("found target: " + target.parent.name); light.transform.parent = target.parent.FindRecursiveContains("runway"); light.transform.localScale *= 0.6f; light.transform.rotation = modelPrefab.transform.rotation; light.transform.localPosition = new Vector3(6.5f, 0.85f, -1050f + count * 330); light.name = light.transform.parent.name + "_lights"; count++; } }
public static string PlaceStatic(string modelName, string bodyName, double lat, double lng, float alt, float rotation, bool isScanable = false) { StaticModel model = StaticDatabase.GetModelByName(modelName); if (model != null) { StaticInstance instance = new StaticInstance(); instance.isInSavegame = true; instance.heighReference = HeightReference.Terrain; instance.gameObject = UnityEngine.Object.Instantiate(model.prefab); instance.RadiusOffset = alt; instance.CelestialBody = ConfigUtil.GetCelestialBody(bodyName); instance.Group = "Ungrouped"; instance.RadialPosition = KKMath.GetRadiadFromLatLng(instance.CelestialBody, lat, lng); instance.RotationAngle = rotation; instance.Orientation = Vector3.up; instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000); instance.RefLatitude = lat; instance.RefLongitude = lng; instance.model = model; instance.configPath = null; instance.configUrl = null; instance.isScanable = isScanable; instance.SpawnObject(); return(instance.UUID); } Log.UserError("API:PlaceStatic: StaticModel not found in Database: " + modelName); return(null); }
public static void MangleTrackingDishes() { // StrackingStation LV1 // StaticModel model = StaticDatabase.GetModelByName("KSC_TrackingStation_level_1"); List <DishController.Dish> dishes = new List <DishController.Dish>(); DishController controller = model.prefab.AddComponent <DishController>(); controller.fakeTimeWarp = 1f; controller.maxSpeed = 10f; controller.maxElevation = 20f; controller.minElevation = -70f; foreach (Transform dishTransform in model.prefab.transform.FindAllRecursive("TS_dish")) { Log.Normal("Dish: Found Dish"); DishController.Dish dish = new DishController.Dish(); dish.elevationTransform = dishTransform.FindRecursive("dish_antenna"); //dish.elevationInit = new Quaternion(); dish.rotationTransform = dishTransform.FindRecursive("dish_support"); dish.elevationTransform.parent = dish.rotationTransform; dishes.Add(dish); } controller.dishes = dishes.ToArray(); controller.enabled = true; // StrackingStation LV2 // model = StaticDatabase.GetModelByName("KSC_TrackingStation_level_2"); dishes.Clear(); controller = model.prefab.AddComponent <DishController>(); controller.fakeTimeWarp = 1f; controller.maxSpeed = 10f; controller.maxElevation = 20f; controller.minElevation = -70f; foreach (Transform dishTransform in model.prefab.transform.FindAllRecursive("TS_dish")) { Log.Normal("Dish: Found Dish"); DishController.Dish dish = new DishController.Dish(); dish.elevationTransform = dishTransform.FindRecursive("dish_antenna"); //dish.elevationInit = new Quaternion(); dish.rotationTransform = dishTransform.FindRecursive("dish_support"); dish.elevationTransform.parent = dish.rotationTransform; dishes.Add(dish); } controller.dishes = dishes.ToArray(); controller.enabled = true; // Extract LV3 Dish as Extra Dish model = StaticDatabase.GetModelByName("KSC_TrackingStation_level_3"); Transform dishNorth = model.prefab.transform.FindRecursive("dish_north"); string modelName = "SQUAD_LV3_Tracking_Dish"; StaticModel dishModel = new StaticModel(); dishModel.prefab = dishNorth.gameObject; // dishModel.prefab.transform.parent = null; dishModel.name = modelName; dishModel.path = "KerbalKonstructs/" + modelName; dishModel.configPath = model.path + ".cfg"; dishModel.keepConvex = true; dishModel.title = "TrackingStation Lv3 Dish"; dishModel.mesh = modelName; dishModel.category = "Dish"; dishModel.author = "Squad"; dishModel.manufacturer = "Squad"; dishModel.description = "Squad original TrackingStation Lv3 Dish"; dishModel.isSquad = true; StaticDatabase.RegisterModel(dishModel, dishModel.name); }
private static void CreateCollapsables(StaticInstance instance, Transform target, List <DestructibleBuilding.CollapsibleObject> allCollapsibles, string wreckName) { Bounds staticBounds = target.gameObject.GetAllRendererBounds(); GameObject wreckObj = GameObject.Instantiate(StaticDatabase.GetModelByName(wreckName).prefab); //wreckObj.SetActive(true); //Bounds wreckBounds = wreckObj.GetAllRendererBounds(); //wreckObj.SetActive(false); //GameObject.DestroyImmediate(wreckObj); //Log.Normal("Wreck Bounds: " + wreckBounds.size.ToString()); //Log.Normal("Bounds: " + staticBounds.size.ToString()); float wrecksize = 65f; float min = Math.Min(staticBounds.size.x, staticBounds.size.z); float max = Math.Max(staticBounds.size.x, staticBounds.size.z); float scale = min / wrecksize; float times = max / min; int counter = 0; while (times > 0.3f) { float extrascale = Math.Min(times, 1); GameObject replacementObject = GameObject.Instantiate(StaticDatabase.GetModelByName(wreckName).prefab); replacementObject.name = "wreck_" + counter; replacementObject.transform.position = target.position; replacementObject.transform.rotation = target.rotation; replacementObject.transform.parent = instance.wreck.transform; Vector3 localScale = replacementObject.transform.localScale; replacementObject.transform.localScale = new Vector3(localScale.x * scale * extrascale, 0.75f * Math.Min(1f, scale * extrascale), localScale.z * scale * extrascale); replacementObject.SetActive(false); float offset = max / 2 - ((counter - 0.5f) + ((1 + extrascale) / 2)) * (wrecksize * scale); Vector3 pos; if (staticBounds.size.x == max) { pos = new Vector3(offset, 0, 0); } else { pos = new Vector3(0, 0, offset); } replacementObject.transform.localPosition += pos; DestructibleBuilding.CollapsibleObject collapsible = new DestructibleBuilding.CollapsibleObject(); collapsible.collapseBehaviour = DestructibleBuilding.CollapsibleObject.Behaviour.Collapse; collapsible.collapseDuration = 5f; collapsible.collapseObject = target.gameObject; collapsible.repairDuration = 0; collapsible.replaceDelay = 0.8f; collapsible.replacementObject = replacementObject; collapsible.collapseTiltMax = new Vector3(5, 0, 5); collapsible.collapseOffset = new Vector3(0, -staticBounds.size.y / 4, 0); collapsible.SecondaryFXPrefab = secondaryPrefab; collapsible.Init(); // Log.Normal("Added collapsible: " + instance.model.name + " : " + pos.ToString() + " : " + counter); collapsible.sharedWith = instance.destructible; allCollapsibles.Add(collapsible); times -= 1f; counter++; } }