/// <summary> /// Spawns a new Instance in the Gameworld and registers itself to the Static Database /// </summary> /// <param name="editing"></param> /// <param name="bPreview"></param> internal void Orientate() { // mangle Squads statics CelestialBody.CBUpdate(); InstanceUtil.CreateGroupCenterIfMissing(this); if (!StaticDatabase.HasGroupCenter(groupCenterName)) { Log.UserWarning("cannot load " + configPath); return; } groupCenter = StaticDatabase.GetGroupCenter(groupCenterName); if (RelativePosition.Equals(Vector3.zero)) { Log.Normal("LegacySpawnInstance called for " + groupCenterName + "_" + model.name); LegacySpawnInstance(); gameObject.transform.parent = groupCenter.gameObject.transform; RelativePosition = gameObject.transform.localPosition; Orientation = gameObject.transform.localEulerAngles; } else { gameObject.transform.position = groupCenter.gameObject.transform.position + RelativePosition;; gameObject.transform.parent = groupCenter.gameObject.transform; gameObject.transform.localEulerAngles = Orientation; gameObject.transform.localPosition = RelativePosition; } RefLatitude = (float)CelestialBody.GetLatitudeAndLongitude(gameObject.transform.position).x; RefLongitude = (float)(CelestialBody.GetLatitudeAndLongitude(gameObject.transform.position).y); RadialPosition = radialPosition; StaticDatabase.AddStatic(this); // Add them to the bodys objectlist, so they show up as anomalies // After we got a new Name from StaticDatabase.AddStatic() if (isScanable) { var pqsObjectList = CelestialBody.pqsSurfaceObjects.ToList(); if (!pqsObjectList.Contains((PQSSurfaceObject)groupCenter.pqsCity)) { Log.Normal("Added " + groupCenter.Group + " to scanable Objects"); pqsObjectList.Add(groupCenter.pqsCity as PQSSurfaceObject); } CelestialBody.pqsSurfaceObjects = pqsObjectList.ToArray(); } }
/// <summary> /// Spawns a new Instance in the Gameworld and registers itself to the Static Database /// </summary> /// <param name="editing"></param> /// <param name="bPreview"></param> internal void SpawnObject(Boolean editing = false, Boolean bPreview = false) { // mangle Squads statics if (model.isSquad) { InstanceUtil.MangleSquadStatic(this); } // Objects spawned at runtime should be active, ones spawned at loading not InstanceUtil.SetActiveRecursively(this, editing); Transform[] gameObjectList = gameObject.GetComponentsInChildren <Transform>(); List <GameObject> rendererList = (from t in gameObjectList where t.gameObject.GetComponent <Renderer>() != null select t.gameObject).ToList(); InstanceUtil.SetLayerRecursively(this, 15); if (bPreview && editing) { this.ToggleAllColliders(false); } this.preview = bPreview; if (editing) { KerbalKonstructs.instance.selectObject(this, true, true, bPreview); } InstanceUtil.CreateGroupCenterIfMissing(this); groupCenter = StaticDatabase.allCenters[groupCenterName]; if (RelativePosition.Equals(Vector3.zero)) { Log.Normal("LegacySpawnInstance called for " + configPath); LegacySpawnInstance(); gameObject.transform.parent = groupCenter.gameObject.transform; pqsCity.enabled = false; pqsCity.sphere = null; pqsCity = null; RelativePosition = gameObject.transform.localPosition; Orientation = gameObject.transform.localEulerAngles; } else { gameObject.transform.position = groupCenter.gameObject.transform.position; gameObject.transform.parent = groupCenter.gameObject.transform; gameObject.transform.localPosition = RelativePosition; gameObject.transform.localEulerAngles = Orientation; } //Scaling origScale = gameObject.transform.localScale; // save the original scale for later use gameObject.transform.localScale *= ModelScale; RefLatitude = (float)CelestialBody.GetLatitudeAndLongitude(gameObject.transform.position).x; RefLongitude = (float)(CelestialBody.GetLatitudeAndLongitude(gameObject.transform.position).y); RadialPosition = radialPosition; foreach (StaticModule module in model.modules) { Type moduleType = AssemblyLoader.loadedAssemblies.SelectMany(asm => asm.assembly.GetTypes()).FirstOrDefault(t => t.Namespace == module.moduleNamespace && t.Name == module.moduleClassname); StaticModule mod = gameObject.AddComponent(moduleType) as StaticModule; if (mod != null) { mod.staticInstance = this; foreach (string fieldName in module.moduleFields.Keys) { FieldInfo field = mod.GetType().GetField(fieldName); if (field != null) { field.SetValue(mod, Convert.ChangeType(module.moduleFields[fieldName], field.FieldType)); } else { Log.UserWarning("Field " + fieldName + " does not exist in " + module.moduleClassname); } } } else { Log.UserError("Module " + module.moduleClassname + " could not be loaded in " + gameObject.name); } } foreach (GameObject gorenderer in rendererList) { gorenderer.GetComponent <Renderer>().enabled = true; } StaticDatabase.AddStatic(this); // Add them to the bodys objectlist, so they show up as anomalies // After we got a new Name from StaticDatabase.AddStatic() if (isScanable) { Log.Normal("Added " + gameObject.name + " to scanable Objects"); var pqsObjectList = CelestialBody.pqsSurfaceObjects.ToList(); if (!pqsObjectList.Contains((PQSSurfaceObject)groupCenter.pqsCity)) { pqsObjectList.Add(groupCenter.pqsCity as PQSSurfaceObject); } CelestialBody.pqsSurfaceObjects = pqsObjectList.ToArray(); } }