Пример #1
0
    /// <summary>
    /// Internal.
    /// 
    /// Register tire instance to adopt these tire properties.
    /// </summary>
    /// <param name="tire"></param>
    public void Register( TwoBodyTire tire )
    {
      if ( !m_tires.Contains( tire ) )
        m_tires.Add( tire );

      Synchronize( tire );
    }
Пример #2
0
 /// <summary>
 /// Explicit synchronization of all properties to the given
 /// tire instance.
 /// </summary>
 /// <remarks>
 /// This call wont have any effect unless the native instance
 /// of the tire has been created.
 /// </remarks>
 /// <param name="tire">Tire instance to synchronize.</param>
 public void Synchronize( TwoBodyTire tire )
 {
   try {
     m_singleSynchronizeInstance = tire;
     Utils.PropertySynchronizer.Synchronize( this );
   }
   finally {
     m_singleSynchronizeInstance = null;
   }
 }
Пример #3
0
        /// <summary>
        /// Internal.
        ///
        /// Register tire instance to adopt these tire properties.
        /// </summary>
        /// <param name="tire"></param>
        public void Register(TwoBodyTire tire)
        {
            if (!m_tires.Contains(tire))
            {
                m_tires.Add(tire);

                // Synchronizing properties for all shovels. Could be
                // avoided by adding a state so that Propagate only
                // shows current added terrain.
                Utils.PropertySynchronizer.Synchronize(this);
            }
        }
Пример #4
0
        private TwoBodyTire GetOrCreateTireModel(WheelLocation location)
        {
            if (m_tireModels == null || m_tireModels.Length == 0)
            {
                m_tireModels = new TwoBodyTire[4] {
                    null, null, null, null
                };
                var tireModels = GetComponents <TwoBodyTire>();
                if (tireModels.Length == 4)
                {
                    foreach (WheelLocation wl in Enum.GetValues(typeof(WheelLocation)))
                    {
                        var trb = GetOrFindWheel(wl);
                        var rrb = FindChild <RigidBody>(wl.ToString() + "Rim");
                        m_tireModels[(int)wl] = tireModels.FirstOrDefault(tireModel => tireModel.TireRigidBody == trb &&
                                                                          tireModel.RimRigidBody == rrb);
                    }
                }
                else if (tireModels.Length != 0)
                {
                    Debug.LogWarning("Tire models mismatch: Got " + tireModels.Length + ", expecting 0 or 4.", this);
                }
            }

            var iLocation = (int)location;

            if (m_tireModels[iLocation] != null)
            {
                return(m_tireModels[iLocation]);
            }

            var tireRigidBody = GetOrFindWheel(location);
            var rimRigidBody  = FindChild <RigidBody>(location.ToString() + "Rim");

            if (tireRigidBody == null || rimRigidBody == null)
            {
                return(null);
            }

            var locks = (from constraint in GetComponentsInChildren <Constraint>()
                         where constraint.Type == ConstraintType.LockJoint
                         select constraint).ToArray();
            var         tireLock = locks.FirstOrDefault(constraint => constraint.AttachmentPair.Match(tireRigidBody, rimRigidBody));
            TwoBodyTire tire     = gameObject.AddComponent <TwoBodyTire>();

            tire.hideFlags = HideFlags.HideInInspector;
            bool valid = false;

            if (tireLock != null)
            {
                valid = tire.Configure(tireLock, tireRigidBody);
            }
            else
            {
                valid = tire.SetTire(tireRigidBody);
                valid = valid && tire.SetRim(rimRigidBody);
            }
            if (!valid)
            {
                DestroyImmediate(tire);
                return(null);
            }

            m_tireModels[iLocation] = tire;

            return(tire);
        }
Пример #5
0
 /// <summary>
 /// Internal.
 ///
 /// Unregister tire instance from these properties.
 /// </summary>
 /// <param name="tire"></param>
 public void Unregister(TwoBodyTire tire)
 {
     m_tires.Remove(tire);
 }