Exemplo n.º 1
0
 public void OnEnter(MySensor sensor, MyRigidBody rbo, MyRBElement rbElement)
 {
     if (m_isOn && rbo.m_UserData != null)
     {
         MyEntity entity = (rbo.m_UserData as MyPhysicsBody).Entity;
         if (entity != null && (Parent == null || Parent != entity))
         {
             int  meetCriterias      = 0;
             bool canRegisteForClose = false;
             if (IsEntityMeetCritarias(entity, ref meetCriterias))
             {
                 AddDetectedEntity(entity, meetCriterias);
                 canRegisteForClose = true;
             }
             else
             {
                 if (m_containsCriteriumToReCheck)
                 {
                     if (CanBeEntityObserved(entity))
                     {
                         m_observableEntities.Add(entity);
                         canRegisteForClose = true;
                     }
                 }
             }
             if (canRegisteForClose)
             {
                 RegisterOnCloseHandlers(entity);
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Called when rigid body enters sensor.
        /// </summary>
        /// <param name="rbo">Rigid body that entered.</param>
        public void OnEnter(MySensor sensor, MyRigidBody rbo, MyRBElement rbElement)
        {
            //smallship
            var userData    = rbo.m_UserData;
            var physicsBody = userData as MyPhysicsBody;

            if (physicsBody != null && physicsBody.Entity is MySmallShip)
            {
                m_counter++;
                if (m_counter > 0)
                {
                    m_owner.OrderToOpen();
                }
            }
        }
Exemplo n.º 3
0
        public void OnLeave(MySensor sensor, MyRigidBody rbo, MyRBElement rbElement)
        {
            if (rbo == null)
            {
                return;
            }

            if (m_isOn && rbo.m_UserData != null)
            {
                MyEntity entity = (rbo.m_UserData as MyPhysicsBody).Entity;
                if (entity != null && (Parent == null || Parent != entity))
                {
                    RemoveEntityFromDetectedAndObservable(entity);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called when rigid body leaves sensor.
        /// </summary>
        /// <param name="rbo">Rigid body that left.</param>
        public void OnLeave(MySensor sensor, MyRigidBody rbo, MyRBElement rbElement)
        {
            ////TODO: Temporary solution - there must not be rbo==null, fix the error and change to assert
            //if (rbo == null)
            //    return;
            Debug.Assert(rbo != null);
            //smallship
            var userData    = rbo.m_UserData;
            var physicsBody = userData as MyPhysicsBody;

            if (physicsBody != null && physicsBody.Entity is MySmallShip)
            {
                m_counter--;
                if (m_counter <= 0)
                {
                    m_owner.OrderToClose();
                }
            }
        }
Exemplo n.º 5
0
        //  IMPORTANT: This class isn't realy inicialized by constructor, but by Start()
        //  So don't initialize members here, do it in Start()
        protected virtual void Start(Vector3 position, float scale, MyGroupMask groupMask, bool explosionType)
        {
            Save            = false;
            m_explosionType = explosionType;

            m_createdTime = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            Matrix worldMat = Matrix.Identity;//; Matrix.CreateScale(scale);

            Scale = scale;
            worldMat.Translation = position;

            SetWorldMatrix(worldMat);

            //  This is here because we are restarting the object after it was sleeping in object pool
            this.Physics.Clear();

            if (m_explosionType)
            {
                NeedsUpdate = true;
                this.Physics.PlayCollisionCueEnabled = true;
                //reset the physical radius of object!
                if ((this.Physics as MyPhysicsBody).GetRBElementList().Count > 0)
                {
                    MyRBElement element = (this.Physics as MyPhysicsBody).GetRBElementList()[0];
                    (element as MyRBSphereElement).Radius = this.ModelLod0.BoundingSphere.Radius * scale;
                }

                //this.Physics.Enabled = true;
                this.Physics.GroupMask      = groupMask;
                this.Physics.AngularDamping = MySession.Is25DSector ? 0.5f : 0.1f;
                //this.Physics.Update();
            }
            else
            {
                NeedsUpdate = false;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds the skin element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="b">if set to <c>true</c> [b].</param>
        public void AddElement(MyRBElement element, bool recomputeInertia)
        {
            Debug.Assert(element != null);

            this.rigidBody.AddElement(element, recomputeInertia);
        }