Пример #1
0
        // Gather up info on all colliders in physics range and order them
        private VesselList GetAllVesselColliders()
        {
            VesselList vesselList = new VesselList();

            vesselList.vesselList.Clear();

            // Not sure why we want to do this...
            bool hasEVA = false;

            foreach (Vessel vessel in FlightGlobals.VesselsLoaded)
            {
                if (vessel.isEVA)
                {
                    hasEVA = true;
                }
            }

            // Iterate through vessels in physics range, parts, and colliders
            foreach (Vessel vessel in FlightGlobals.VesselsLoaded)
            {
                VesselList.VesselInfo vesselInfo = new VesselList.VesselInfo();
                vesselInfo.vessel = vessel;
                vesselList.vesselList.Add(vesselInfo);

                foreach (Part part in vessel.parts)
                {
                    VesselList.VesselInfo.PartInfo partInfo = new VesselList.VesselInfo.PartInfo();
                    partInfo.part = part;
                    vesselInfo.partList.Add(partInfo);

                    // Check if there is an MechanicsToolkit part module in this part
                    partInfo.collisionMode = 0;

                    foreach (PartModule partModule in part.Modules)
                    {
                        if (partModule.moduleName == "MechanicsToolkit")
                        {
                            MechanicsToolkit mechanicsToolkit = (MechanicsToolkit)partModule;
                            partInfo.collisionMode = mechanicsToolkit.collisionMode;
                        }
                    }

                    Collider[] componentsInChildren = part.partTransform.GetComponentsInChildren <Collider>(hasEVA);
                    if (componentsInChildren != null)
                    {
                        for (int k = 0; k < componentsInChildren.Length; k++)
                        {
                            Collider collider = componentsInChildren[k];

                            bool addCollider = (collider.gameObject.activeInHierarchy && collider.enabled) ||
                                               ((hasEVA && (collider.tag == "Ladder" || collider.tag == "Airlock")));

                            if (addCollider)
                            {
                                partInfo.colliderList.Add(collider);
                            }
                        }
                    }
                }
            }
            return(vesselList);
        }
Пример #2
0
        private void OnCollisionIgnoreUpdate()
        {
            VesselList vesselList = GetAllVesselColliders();

            // Iterate through the created list of vessels/parts/colliders and enable collisions between them
            for (int v1 = 0; v1 < vesselList.vesselList.Count; v1++)
            {
                for (int v2 = v1; v2 < vesselList.vesselList.Count; v2++)
                {
                    VesselList.VesselInfo vessel1 = vesselList.vesselList[v1];
                    VesselList.VesselInfo vessel2 = vesselList.vesselList[v2];

                    for (int p1 = 0; p1 < vessel1.partList.Count; p1++)
                    {
                        VesselList.VesselInfo.PartInfo part1 = vessel1.partList[p1];

                        for (int p2 = p1 + 1; p2 < vessel2.partList.Count; p2++)
                        {
                            VesselList.VesselInfo.PartInfo part2 = vessel2.partList[p2];

                            bool ignore = false;

                            if (vessel1 == vessel2)
                            {
                                /*
                                 * bool adjacent = false;
                                 * // Enable collisions for adjacent parts?
                                 * if (part1.part.parent == part2.part ||
                                 *  part2.part.parent == part1.part)
                                 *  adjacent = true;
                                 */
                                // A matrix enabling collisions depending on the settings of the two parts
                                bool[][] active = new bool[][]
                                {
                                    /*
                                     * new bool[] { false,     false,      !adjacent,  true},
                                     * new bool[] { false,     true,       !adjacent,  true },
                                     * new bool[] { !adjacent, !adjacent,  !adjacent,  true },
                                     * new bool[] { true,      true,       true,       true },
                                     */
                                    new bool[] { false, false, true },
                                    new bool[] { false, true, true },
                                    new bool[] { true, true, true },
                                };

                                if (!active[(int)part1.collisionMode][(int)part2.collisionMode])
                                {
                                    ignore = true;
                                }
                            }

                            for (int c1 = 0; c1 < part1.colliderList.Count; c1++)
                            {
                                for (int c2 = 0; c2 < part2.colliderList.Count; c2++)
                                {
                                    Collider collider1 = part1.colliderList[c1];
                                    Collider collider2 = part2.colliderList[c2];

                                    Physics.IgnoreCollision(collider1, collider2, ignore);
                                }
                            }
                        }
                    }
                }
            }
        }