Пример #1
0
 public void AddSphereInside(GravitySphere sphereInside)
 {
     if (spheresInside.Contains(sphereInside) == false)
     {
         spheresInside.Add(sphereInside);
     }
 }
        private void Repel(GravitySphere sphereToAttract)
        {
            var     rigidbodyToRepel = sphereToAttract.Rigidbody;
            Vector3 direction        = rigidbody.position - rigidbodyToRepel.position;

            direction.Normalize();
            rigidbody.AddForce(direction * rigidbody.mass);
        }
        private void Attract(GravitySphere sphereToAttract)
        {
            var     rigidbodyToAttract = sphereToAttract.Rigidbody;
            Vector3 direction          = rigidbody.position - rigidbodyToAttract.position;
            float   distance           = direction.magnitude;

            if (distance == 0)
            {
                return;
            }

            float   forceMagnitude = G * (rigidbody.mass * rigidbodyToAttract.mass) / Mathf.Pow(distance, 2);
            Vector3 force          = direction.normalized * forceMagnitude;

            rigidbodyToAttract.AddForce(force);
        }
 public void UnregisterSphere(GravitySphere sphere)
 {
     spheres.Remove(sphere);
 }
 public void RegisterSphere(GravitySphere sphere)
 {
     spheres.Add(sphere);
 }
 private void AddToExistingCombineData(int key, GravitySphere sphere)
 {
     combineData[key].AddSphereToCombine(sphere);
 }
 private void CreateCombineData(int key, GravitySphere gravitySphere)
 {
     combineData.Add(key, new SpheresCombineData(gravitySphere, combineTime));
 }
 public void SubscribeToCollisionEvent(GravitySphere gravitySphere)
 {
     gravitySphere.GravityField.OnSphereCollision += OnCollision;
 }
Пример #9
0
 public void AddSphereToCombine(GravitySphere gravitySphere)
 {
     spheresToCombine.Add(gravitySphere);
     largestSphere = GetLargestGravitySphere();
     UpdateProperties();
 }
Пример #10
0
 public SpheresCombineData(GravitySphere sphere, float combineTime)
 {
     spheresToCombine = new List <GravitySphere>();
     this.combineTime = combineTime;
     AddSphereToCombine(sphere);
 }