コード例 #1
0
        /// <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);
        }
コード例 #2
0
        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;
        }