findTransformsWithCollider() public static method

public static findTransformsWithCollider ( Transform input, List &list ) : void
input UnityEngine.Transform
list List
return void
Exemplo n.º 1
0
        public override void OnUpdate()
        {
            if (!flightStarted)
            {
                return;
            }

            switch (mode)
            {
            case TrackingModes.BROKEN:
                return;

            case TrackingModes.TRACKING:
                if (target.isTarget && powered)
                {
                    pivot1.RotToTarget(target.position);
                    pivot2.RotToTarget(target.position);
                }
                break;

            case TrackingModes.EXTENDING:
                if (!anim.IsPlaying(Animation))
                {
                    mode = TrackingModes.TRACKING;
                }
                break;

            case TrackingModes.RETRACTING:
                if (!anim.IsPlaying(Animation))
                {
                    mode = TrackingModes.RETRACTED;
                }
                break;

            case TrackingModes.RESETTING:
                if (pivot1.RotToOrigin() & pivot2.RotToOrigin())
                {
                    anim[Animation].speed = -Mathf.Abs(anim[Animation].speed);

                    anim.Play(Animation);

                    if (anim[Animation].normalizedTime == 0)
                    {
                        anim[Animation].normalizedTime = 1;
                    }
                    mode = TrackingModes.RETRACTING;
                }
                break;
            }

            if (EnergyDrain1 > 0)
            {
                RequestPower();
            }

            if (vessel != null && RTUtils.PhysicsActive)
            {
                if (willWakeInPanic && animState == 0 && !InControl && !anim.IsPlaying(Animation))
                {
                    SetMode1();
                    UpdateGUI();
                }


                if (MaxQ > 0 && mode != TrackingModes.RETRACTED && vessel.atmDensity > 0 && (Math.Pow(RTUtils.DirectionalSpeed(Pivot2Dir.up, vessel.srf_velocity), 2) * vessel.atmDensity * 0.5) > MaxQ)
                {
                    broken = true;
                    mode   = TrackingModes.BROKEN;
                    List <Transform> toRemove = new List <Transform>();
                    RTUtils.findTransformsWithCollider(part.FindModelTransform(Pivot1Name), ref toRemove);

                    foreach (Transform t in toRemove)
                    {
                        Rigidbody rb = t.gameObject.AddComponent <Rigidbody>();

                        rb.angularDrag     = 0;
                        rb.angularVelocity = part.rigidbody.angularVelocity;
                        rb.drag            = 0;
                        rb.mass            = t.collider.bounds.size.x * t.collider.bounds.size.y * t.collider.bounds.size.z * ShrapnelDensity;
                        rb.velocity        = part.rigidbody.velocity;
                        rb.isKinematic     = false;
                        t.parent           = null;
                        rb.AddForce(UnityEngine.Random.Range(-5, 5), UnityEngine.Random.Range(-5, 5), UnityEngine.Random.Range(-5, 5));
                        rb.AddTorque(UnityEngine.Random.Range(-20, 20), UnityEngine.Random.Range(-20, 20), UnityEngine.Random.Range(-20, 20));

                        DragModel dm = t.gameObject.AddComponent <DragModel>();
                        dm.enabled = true;
                        dm.tf      = t;
                        dm.rb      = rb;
                        dm.dc      = ShrapnelDragCoeff;
                        dm.mb      = vessel.mainBody;
                    }

                    if (this.MaximumDrag > 0)
                    {
                        part.minimum_drag = this.MinimumDrag;
                        part.maximum_drag = this.MaximumDrag;
                    }

                    EnergyDrain = antennaRange = dishRange = 0;
                    part.SendMessage("UpdateGUI");
                    UpdatePA();
                    RTGlobals.network = new RelayNetwork();
                }
            }
        }
        public override void OnUpdate()
        {
            if (!flightStarted || broken)
            {
                return;
            }

            if (EnergyDrain1 > 0)
            {
                RequestPower();
            }

            if (vessel != null && RTUtils.PhysicsActive)
            {
                if (willWakeInPanic && animState == 0 && !InControl && !anim.IsPlaying(Animation))
                {
                    SetMode1();
                    UpdateGUI();
                }

                if (explodeMe && Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, part.transform.position) > 250)
                {
                    explodeMe = false;
                    part.explode();
                }

                if (MaxQ > 0 && animState == 1 && (Math.Pow(vessel.srf_velocity.magnitude, 2) * vessel.atmDensity * 0.5) > MaxQ)
                {
                    if (BreakTransformName == "")
                    {
                        part.decouple(0f);
                        explodeMe = true;
                    }
                    else
                    {
                        broken = true;
                        RTUtils.findTransformsWithCollider(part.FindModelTransform(BreakTransformName), ref toRemove);

                        foreach (Transform t in toRemove)
                        {
                            Rigidbody rb = t.gameObject.AddComponent <Rigidbody>();

                            rb.angularDrag     = part.rigidbody.angularDrag;
                            rb.angularVelocity = part.rigidbody.angularVelocity;
                            rb.drag            = 0;
                            rb.mass            = part.mass / 5;
                            rb.velocity        = part.rigidbody.velocity;
                            rb.isKinematic     = false;
                            t.parent           = null;
                            rb.AddForce(UnityEngine.Random.Range(-5, 5), UnityEngine.Random.Range(-5, 5), UnityEngine.Random.Range(-5, 5));
                            rb.AddTorque(UnityEngine.Random.Range(-20, 20), UnityEngine.Random.Range(-20, 20), UnityEngine.Random.Range(-20, 20));

                            DragModel dm = t.gameObject.AddComponent <DragModel>();
                            dm.enabled = true;
                            dm.tf      = t;
                            dm.rb      = rb;
                            dm.dc      = DragCoeff;
                            dm.mb      = vessel.mainBody;
                        }

                        if (this.MaximumDrag > 0)
                        {
                            part.minimum_drag = this.MinimumDrag;
                            part.maximum_drag = this.MaximumDrag;
                        }
                        EnergyDrain = antennaRange = dishRange = 0;
                        part.SendMessage("UpdateGUI");
                        UpdatePA();
                        RTGlobals.network = new RelayNetwork();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void OnStart(PartModule.StartState state)
        {
            if (broken)
            {
                mode = TrackingModes.BROKEN;
                List <Transform> toRemove = new List <Transform>();
                RTUtils.findTransformsWithCollider(part.FindModelTransform(Pivot1Name), ref toRemove);
                foreach (Transform t in toRemove)
                {
                    Destroy(t.gameObject);
                }

                if (this.MaximumDrag > 0)
                {
                    part.minimum_drag = this.MinimumDrag;
                    part.maximum_drag = this.MaximumDrag;
                }

                EnergyDrain = antennaRange = dishRange = 0;
                part.SendMessage("UpdateGUI");
                UpdatePA();
                RTGlobals.network = new RelayNetwork();
                return;
            }

            Actions["Mode1Action"].guiName  = Events["Mode1Event"].guiName = Mode1Name;
            Actions["Mode0Action"].guiName  = Events["Mode0Event"].guiName = Mode0Name;
            Actions["ActionToggle"].guiName = ToggleName;

            Events["OverrideMode1Event"].guiName = "Override " + Mode1Name;
            Events["OverrideMode0Event"].guiName = "Override " + Mode0Name;

            if (fixAnimLayers)
            {
                int i = 0;
                foreach (AnimationState s in anim)
                {
                    s.layer = i;
                    i++;
                }
            }

            if (animState == 1)
            {
                act1();

                anim[Animation].speed = Mathf.Abs(anim[Animation].speed);

                mode = TrackingModes.TRACKING;

                anim.Play(Animation);
            }
            else
            {
                act0();

                anim[Animation].speed = -Mathf.Abs(anim[Animation].speed);

                mode = TrackingModes.RETRACTED;

                anim.Play(Animation);
            }

            anim[Animation].wrapMode = WrapMode.Clamp;

            base.OnStart(state);

            if (state != StartState.Editor)
            {
                Pivot2Dir = part.FindModelTransform(Pivot2Name);

                pivot1 = new Pivot(part.FindModelTransform(Pivot1Name), Pivot1Speed, Pivot1Range);
                pivot2 = new Pivot(Pivot2Dir, Pivot2Speed, Pivot2Range);

                if (animState == 1)
                {
                    mode = TrackingModes.TRACKING;
                    if (target.isTarget)
                    {
                        pivot1.SnapToTarget(target.position);
                        pivot2.SnapToTarget(target.position);
                    }
                }
            }

            anim[Animation].normalizedTime = animState;
        }
        public override void OnStart(PartModule.StartState state)
        {
            if (broken)
            {
                RTUtils.findTransformsWithCollider(part.FindModelTransform(BreakTransformName), ref toRemove);
                foreach (Transform t in toRemove)
                {
                    Destroy(t.gameObject);
                }
                toRemove.Clear();

                if (this.MaximumDrag > 0)
                {
                    part.minimum_drag = this.MinimumDrag;
                    part.maximum_drag = this.MaximumDrag;
                }

                EnergyDrain = antennaRange = dishRange = 0;
                part.SendMessage("UpdateGUI");
                UpdatePA();
                RTGlobals.network = new RelayNetwork();
                return;
            }


            Actions["Mode1Action"].guiName  = Events["Mode1Event"].guiName = Mode1Name;
            Actions["Mode0Action"].guiName  = Events["Mode0Event"].guiName = Mode0Name;
            Actions["ActionToggle"].guiName = ToggleName;

            Events["OverrideMode1Event"].guiName = "Override " + Mode1Name;
            Events["OverrideMode0Event"].guiName = "Override " + Mode0Name;

            if (animState == 1)
            {
                act1();
            }
            else
            {
                act0();
            }

            if (fixAnimLayers)
            {
                int i = 0;
                foreach (AnimationState s in anim)
                {
                    s.layer = i;
                    i++;
                }
            }

            anim[Animation].normalizedTime = this.animState;

            anim[Animation].wrapMode = WrapMode.Clamp;

            if (state == StartState.Editor)
            {
                if (animPlayStart == 1)
                {
                    SetMode1();
                }
                else if (animPlayStart == -1)
                {
                    SetMode0();
                }
            }

            base.OnStart(state);
        }