Inheritance: UnityEngine.MonoBehaviour
コード例 #1
0
        private void Break()
        {
            foreach (Transform t in RTUtil.FindTransformsWithCollider(BreakTransform))
            {
                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.dc      = ShrapnelDragCoeff;
                dm.mb      = vessel.mainBody;
            }

            Events["EventOpen"].guiActive                            =
                Events["EventClose"].guiActive                       =
                    Events["EventToggle"].guiActive                  =
                        Events["EventTarget"].guiActive              =
                            Events["EventOpen"].active               =
                                Events["EventClose"].active          =
                                    Events["EventToggle"].active     =
                                        Events["EventTarget"].active = false;

            Fields["GUI_OmniRange"].guiActive         =
                Fields["GUI_DishRange"].guiActive     =
                    Fields["GUI_EnergyReq"].guiActive = false;

            IsRTBroken = true;
            base.SetState(false);
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
0
        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();
                    }
                }
            }
        }