예제 #1
0
        IEnumerator <YieldInstruction> spawn_kit_vessel(ShipConstruct kit_ship)
        {
            //spawn the ship construct
            var bounds = kit_ship.Bounds(kit_ship.Parts[0].localRoot.transform);

            yield return
                (StartCoroutine(vessel_spawner
                                .SpawnShipConstruct(kit_ship,
                                                    SpawnManager.GetSpawnTransform(bounds),
                                                    SpawnManager.GetSpawnOffset(bounds) - bounds.center,
                                                    Vector3.zero)));

            Kit = new VesselKit();
            Open();
        }
예제 #2
0
        IEnumerator spawn_kit_vessel(ShipConstruct kit_ship)
        {
            enable_damper();
            //spawn the ship construct
            var bounds          = kit_ship.Bounds(kit_ship.Parts[0].localRoot.transform);
            var spawn_transform = SpawnManager.GetSpawnTransform(bounds, out var offset);

            vessel_spawner.SpawnShipConstruct(kit_ship,
                                              spawn_transform,
                                              offset - bounds.center,
                                              Vector3.zero);
            yield return(vessel_spawner.WaitForLaunch);

            Kit = new VesselKit();
            Open();
        }
예제 #3
0
        public static void PutShipToGround(ShipConstruct ship, Transform spawnPoint, Vector3 offset)
        {
            var partHeightQuery = new PartHeightQuery(float.MaxValue);
            int count           = ship.parts.Count;

            for (int i = 0; i < count; i++)
            {
                var p = ship[i];
                partHeightQuery.lowestOnParts.Add(p, float.MaxValue);
                Collider[] componentsInChildren = p.GetComponentsInChildren <Collider>();
                int        num = componentsInChildren.Length;
                for (int j = 0; j < num; j++)
                {
                    Collider collider = componentsInChildren[j];
                    if (collider.enabled && collider.gameObject.layer != 21)
                    {
                        partHeightQuery.lowestPoint      = Mathf.Min(partHeightQuery.lowestPoint, collider.bounds.min.y);
                        partHeightQuery.lowestOnParts[p] = Mathf.Min(partHeightQuery.lowestOnParts[p], collider.bounds.min.y);
                    }
                }
            }
            for (int k = 0; k < count; k++)
            {
                ship[k].SendMessage("OnPutToGround", partHeightQuery, SendMessageOptions.DontRequireReceiver);
            }
            Utils.Log("putting ship to ground: " + partHeightQuery.lowestPoint);
            float   angle;
            Vector3 axis;

            spawnPoint.rotation.ToAngleAxis(out angle, out axis);
            var root = ship.parts[0].localRoot.transform;

            offset += spawnPoint.position;
            var CoG = ship.Bounds().center;

            offset -= new Vector3(CoG.x, partHeightQuery.lowestPoint, CoG.z);
            root.Translate(offset, Space.World);
            root.RotateAround(spawnPoint.position, axis, angle);
        }