public void CreatePreviewInstance(StaticModel model) { StaticInstance instance = new StaticInstance(); GroupCenter groupCenter = null;//XXX StaticsEditorGUI.GetCloesedCenter(FlightGlobals.ActiveVessel.transform.position); if (groupCenter == null) { MiscUtils.HUDMessage("No Local GroupCenter found. Create one, then try again"); } //instance.mesh = GameObject.Instantiate(model.prefab); instance.RadiusOffset = (float)FlightGlobals.ActiveVessel.altitude; instance.CelestialBody = KerbalKonstructs.instance.GetCurrentBody(); instance.Group = groupCenter.Group; instance.RadialPosition = KerbalKonstructs.instance.GetCurrentBody().transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position); instance.RotationAngle = 0f; instance.Orientation = Vector3.up; instance.VisibilityRange = 25000f; instance.configPath = KerbalKonstructs.newInstancePath + "/" + model.name + "-instances.cfg"; instance.configUrl = null; instance.model = model; instance.Orientate(); instance.Activate(); KerbalKonstructs.SelectInstance(instance, true); currPreview = instance; }
/// <summary> /// Spawns an Instance of an defined StaticModel /// </summary> /// <param name="model"></param> /// <param name="fOffset"></param> /// <param name="vPosition"></param> /// <param name="fAngle"></param> /// <returns></returns> public string SpawnInstance(StaticModel model, float fOffset, Vector3 vPosition) { StaticInstance instance = new StaticInstance(); instance.Orientation = Vector3.up; instance.heighReference = HeightReference.Terrain; instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000); instance.Group = "SaveGame"; instance.RadialPosition = vPosition; instance.model = model; if (instance.model == null) { Log.UserError("LoadFromSave: Canot find model named: " + model.name); instance = null; } //instance.mesh = UnityEngine.Object.Instantiate(instance.model.prefab); instance.CelestialBody = KerbalKonstructs.instance.GetCurrentBody(); instance.RadiusOffset = fOffset; instance.RotationAngle = 0; instance.RefLatitude = KKMath.GetLatitudeInDeg(instance.RadialPosition); instance.RefLongitude = KKMath.GetLongitudeInDeg(instance.RadialPosition); InstanceUtil.CreateGroupCenterIfMissing(instance); bool oldLegacySpawn = KerbalKonstructs.convertLegacyConfigs; instance.Orientate(); instance.Activate(); KerbalKonstructs.convertLegacyConfigs = oldLegacySpawn; KerbalKonstructs.SelectInstance(instance, true); selectedInstance = instance; startPosition = selectedInstance.position; instance.Update(); instance.isInSavegame = true; instance.HighlightObject(XKCDColors.FreshGreen); this.Open(); return(instance.UUID); }
/// <summary> /// Spawns an Instance of an defined StaticModel /// </summary> /// <param name="model"></param> /// <param name="fOffset"></param> /// <param name="vPosition"></param> /// <param name="fAngle"></param> /// <returns></returns> internal void SpawnInstance(StaticModel model, GroupCenter groupCenter, Vector3 position, Vector3 rotation) { StaticInstance instance = new StaticInstance(); instance.model = model; //instance.mesh = UnityEngine.Object.Instantiate(model.prefab); instance.CelestialBody = FlightGlobals.currentMainBody; instance.groupCenter = groupCenter; instance.Group = groupCenter.Group; instance.transform.position = position; instance.transform.parent = groupCenter.gameObject.transform; instance.RelativePosition = instance.transform.localPosition; instance.Orientation = rotation; if (!Directory.Exists(KSPUtil.ApplicationRootPath + "GameData/" + KerbalKonstructs.newInstancePath)) { Directory.CreateDirectory(KSPUtil.ApplicationRootPath + "GameData/" + KerbalKonstructs.newInstancePath); } instance.configPath = KerbalKonstructs.newInstancePath + "/" + model.name + "-instances.cfg"; instance.configUrl = null; enableColliders = false; enableColliders2 = false; instance.Orientate(); instance.Activate(); KerbalKonstructs.SelectInstance(instance, true); GrassColor2 grassMod = instance.gameObject.GetComponent <GrassColor2>(); if (grassMod != null) { grassMod.UpdateCallBack(StaticsEditorGUI.defaultGrassPreset); } }