Beispiel #1
0
        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;
        }
Beispiel #2
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);
        }
        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;
        }
        /// <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);
            }
        }
Beispiel #5
0
        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.mesh = UnityEngine.Object.Instantiate(model.prefab);
                instance.RadiusOffset    = alt;
                instance.CelestialBody   = ConfigUtil.GetCelestialBody(bodyName);
                instance.Group           = "SaveGame";
                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.Orientate();

                return(instance.UUID);
            }

            Log.UserError("API:PlaceStatic: StaticModel not found in Database: " + modelName);
            return(null);
        }