예제 #1
0
 private void Update()
 {
     if (broken_script)
     {
         if (broken_script.broken == false)
         {
             broken_script = null;
             broken_object = null;
         }
     }
     for (int i = 0; i < held_rigids.Count; i++)
     {
         if (held_rigids[i] != null)
         {
             if (held_rigids[i].velocity.magnitude > 20.0f)
             {
                 return;
             }
             if (broken_object)
             {
                 held_rigids[i].AddForce((broken_object.transform.position - held_rigids[i].transform.position).normalized * magnetic_strength);
             }
             else
             {
                 held_rigids[i].AddForce((transform.position - held_rigids[i].transform.position).normalized * magnetic_strength);
             }
         }
     }
 }
예제 #2
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     for (int i = 0; i < held_rigids.Count; i++)
     {
         if (held_rigids[i] == collision.attachedRigidbody)
         {
             return;
         }
     }
     if (collision.tag == "Fixable")
     {
         if (broken_object == null && collision.gameObject.GetComponent <BrokenObject>().broken == true)
         {
             broken_object = collision.gameObject;
             broken_script = broken_object.GetComponent <BrokenObject>();
         }
     }
     if (collision.tag == "Debris")
     {
         if (collision.gameObject.GetComponent <Rigidbody2D>() != null)
         {
             held_rigids.Add(collision.gameObject.GetComponent <Rigidbody2D>());
             collision.gameObject.GetComponent <DebrisChecker>().magnetized = true;
         }
     }
 }
예제 #3
0
 private void OnTriggerExit2D(Collider2D other)
 {
     if (other.tag == "Fixable")
     {
         broken_object = null;
         broken_script = null;
     }
     for (int i = 0; i < held_rigids.Count; i++)
     {
         if (held_rigids[i] == other.gameObject.GetComponent <Rigidbody2D>())
         {
             held_rigids[i].gameObject.GetComponent <DebrisChecker>().magnetized = false;
             held_rigids.RemoveAt(i);
         }
     }
 }
예제 #4
0
        public void ExceptionsThrownInTheConstructorFailGracefully()
        {
            BrokenObject broken = null;

            try
            {
                broken = new BrokenObject();
            }
            catch (Exception)
            {
            }
            finally
            {
                broken?.Dispose();
                broken = null;
            }

            // trigger the finalizer
            CollectGarbage();
        }
예제 #5
0
        public void ExceptionsThrownInTheConstructorFailGracefully()
        {
            BrokenObject broken = null;

            try
            {
                broken = new BrokenObject();
            }
            catch (Exception)
            {
            }
            finally
            {
                broken?.Dispose();
                broken = null;
            }

            // try and trigger the finalizer
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }