コード例 #1
0
 public void Break(float collisionSpeed)
 {
     if ((!this.m_broken && !this.lockPosition && collisionSpeed > this.breakForce) || (this.lockPosition && this.m_fixedJoint == null))
     {
         this.m_broken = true;
         if (this.breakEffect != null)
         {
             this.breakEffect.transform.parent = null;
             this.breakEffect.Play();
         }
         this.PlayBreakSFX();
         base.rigidbody.isKinematic = true;
         if (this.chainReactionBreaking)
         {
             Collider[] array = Physics.OverlapSphere(base.transform.position, 2f);
             foreach (Collider collider in array)
             {
                 LevelRigidbody component = collider.GetComponent <LevelRigidbody>();
                 if (component)
                 {
                     component.Break(collisionSpeed);
                 }
             }
         }
         base.transform.position = -Vector3.up * 1000f;
     }
 }
コード例 #2
0
    public void OnDataLoaded()
    {
        this.stepParent = base.transform.Find("StepParent");
        this.endPoint   = base.transform.Find("EndPoint");
        if (this.stepPrefab == null || this.endPoint == null)
        {
            return;
        }
        Vector3 vector    = this.endPoint.position - base.transform.position;
        float   magnitude = vector.magnitude;
        float   f         = magnitude / (this.stepLength + this.stepGap);

        this.steps = new List <Transform>();
        for (int i = 0; i < this.stepParent.childCount; i++)
        {
            Transform child = this.stepParent.GetChild(i);
            this.steps.Add(child);
        }
        int num = this.steps.Count - Mathf.FloorToInt(f);

        if (num > 0)
        {
            for (int j = 0; j < num; j++)
            {
                UnityEngine.Object.DestroyImmediate(this.steps[this.steps.Count - 1].gameObject);
                this.steps.RemoveAt(this.steps.Count - 1);
            }
        }
        int num2 = 0;

        while (this.steps.Count < Mathf.FloorToInt(f) && num2 <= 100)
        {
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.stepPrefab);
            gameObject.transform.parent = this.stepParent;
            gameObject.name             = string.Format("Step{0:000}", this.steps.Count);
            this.steps.Add(gameObject.transform);
            num2++;
        }
        HingeJoint hingeJoint = null;

        for (int k = 0; k < this.steps.Count; k++)
        {
            this.steps[k].localPosition = Vector3.right * ((float)k * (this.stepLength + this.stepGap) + (this.stepLength + this.stepGap) * 0.5f);
            this.steps[k].localRotation = Quaternion.identity;
            HingeJoint component = this.steps[k].GetComponent <HingeJoint>();
            if (hingeJoint != null)
            {
                component.connectedBody = hingeJoint.GetComponent <Rigidbody>();
            }
            component.autoConfigureConnectedAnchor = true;
            hingeJoint = component;
        }
        Transform transform = base.transform.Find("StepRopeParent");

        if (transform != null)
        {
            UnityEngine.Object.DestroyImmediate(transform.gameObject);
        }
        if (transform == null)
        {
            transform        = new GameObject("StepRopeParent").transform;
            transform.parent = base.transform;
        }
        transform.localPosition = Vector3.zero;
        if (this.stepRopes == null)
        {
            this.stepRopes = new List <GameObject>();
        }
        this.stepRopes.Clear();
        for (int l = 0; l < this.steps.Count + 1; l++)
        {
            GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(this.stepRopePrefab);
            gameObject2.name             = string.Format("StepRope{0:000}", l);
            gameObject2.transform.parent = transform;
            if (l < this.steps.Count)
            {
                gameObject2.transform.position = this.steps[l].position;
            }
            else
            {
                gameObject2.transform.position = this.endPoint.position;
            }
            this.stepRopes.Add(gameObject2);
        }
        for (int m = 0; m < this.stepParent.childCount; m++)
        {
            Transform  child2     = this.stepParent.GetChild(m);
            HingeJoint component2 = child2.GetComponent <HingeJoint>();
            if (component2 && this.stepBreakForces.Count > m)
            {
                component2.breakForce = this.stepBreakForces[m];
                if (this.stepBreakForces[m] < 0.1f)
                {
                    this.isBroken = true;
                }
            }
        }
        Transform  transform2 = this.steps[this.steps.Count - 1];
        HingeJoint component3 = this.endPoint.GetComponent <HingeJoint>();

        component3.connectedBody = transform2.GetComponent <Rigidbody>();
        float d = Mathf.Atan2(vector.y, vector.x) * 57.29578f;

        this.stepParent.localEulerAngles = Vector3.forward * d;
        this.endPoint.position           = transform2.position + transform2.right * (this.stepLength * 0.5f + this.stepGap);
        base.transform.rotation          = Quaternion.identity;
        if (Application.isPlaying)
        {
            foreach (Transform transform3 in this.steps)
            {
                BridgeStep     bridgeStep = transform3.GetComponent <BridgeStep>();
                LevelRigidbody component4 = transform3.GetComponent <LevelRigidbody>();
                if (component4)
                {
                    UnityEngine.Object.DestroyImmediate(component4);
                }
                if (!bridgeStep)
                {
                    bridgeStep = transform3.gameObject.AddComponent <BridgeStep>();
                }
                bridgeStep.Init(false);
            }
            LevelRigidbody component5 = this.endPoint.GetComponent <LevelRigidbody>();
            if (component5)
            {
                UnityEngine.Object.DestroyImmediate(component5);
            }
            BridgeStep bridgeStep2 = this.endPoint.GetComponent <BridgeStep>();
            if (!bridgeStep2)
            {
                bridgeStep2 = this.endPoint.gameObject.AddComponent <BridgeStep>();
            }
            bridgeStep2.Init(true);
        }
        this.SubscribeToJointBreaks();
    }