示例#1
0
 protected virtual void WorldPositionChanged(object source)
 {
     if (this.DetectorPhysics != null && this.DetectorPhysics.Enabled && this.DetectorPhysics != source)
     {
         DetectorPhysics.OnWorldPositionChanged(source);
     }
 }
示例#2
0
        protected override void Closing()
        {
            if (DetectorPhysics != null)
            {
                DetectorPhysics.Close();
                DetectorPhysics = null;
            }

            if (MyFakes.ENABLE_SUBBLOCKS)
            {
                foreach (var pair in SubBlocks)
                {
                    MySlimBlock subBlock = pair.Value;
                    if (subBlock.FatBlock != null)
                    {
                        subBlock.FatBlock.OwnerBlock   = null;
                        subBlock.FatBlock.SubBlockName = null;
                        subBlock.FatBlock.OnClosing   -= SubBlock_OnClosing;
                    }
                }
            }
            SetDamageEffect(false);
            //Moved to RemoveBlockInternal
            //CubeGrid.ChangeOwner(this, OwnerId, 0);
            base.Closing();
        }
示例#3
0
 public override void OnRemovedFromScene(object source)
 {
     base.OnRemovedFromScene(source);
     if (DetectorPhysics != null)
     {
         DetectorPhysics.Deactivate();
     }
 }
示例#4
0
        public override void OnAddedToScene(object source)
        {
            base.OnAddedToScene(source);
            if (DetectorPhysics != null)
            {
                DetectorPhysics.Activate();
            }

            UpdateIsWorking();
        }
示例#5
0
        public void ReloadDetectors(bool refreshNetworks = true)
        {
            m_detectors.Clear();
            m_detectorInteractiveObjects.Clear();

            if (DetectorPhysics != null)
            {
                DetectorPhysics.Close();
            }

            List <HkShape> shapes = new List <HkShape>();
            BoundingBox    aabb   = new BoundingBox(-Vector3.One / 2, Vector3.One / 2);

            if (Render.GetModel() != null)
            {
                foreach (var dummy in Render.GetModel().Dummies)
                {
                    var          dummyLowerCaseKey = dummy.Key.ToLower();
                    const string DETECTOR_PREFIX   = "detector_";
                    if (dummyLowerCaseKey.StartsWith(DETECTOR_PREFIX) && dummyLowerCaseKey.Length > DETECTOR_PREFIX.Length)
                    {
                        String[] parts = dummyLowerCaseKey.Split('_');
                        if (parts.Length < 2)
                        {
                            continue;
                        }

                        var           dummyData = dummy.Value;
                        List <Matrix> matrices;
                        if (!m_detectors.TryGetValue(parts[1], out matrices))
                        {
                            matrices = new List <Matrix>();
                            m_detectors[parts[1]] = matrices;
                        }
                        matrices.Add(Matrix.Invert(dummyData.Matrix));

                        // TODO: this should be nicer
                        int shapeKey          = shapes.Count;
                        var interactiveObject = CreateInteractiveObject(parts[1], dummyLowerCaseKey, dummyData, shapeKey);
                        if (interactiveObject != null)
                        {
                            unsafe
                            {
                                fixed(Vector3 *corner = m_detectorVertices)
                                aabb.GetCornersUnsafe(corner);
                            }
                            for (int i = 0; i < BoundingBox.CornerCount; i++)
                            {
                                m_detectorVertices[i] = Vector3.Transform(m_detectorVertices[i], dummyData.Matrix);
                            }

                            shapes.Add(new HkConvexVerticesShape(m_detectorVertices, BoundingBox.CornerCount, false, 0));
                            m_detectorInteractiveObjects.Add(shapeKey, interactiveObject);
                        }
                    }
                }
            }

            if (shapes.Count > 0)
            {
                var listShape = new HkListShape(shapes.GetInternalArray(), shapes.Count, HkReferencePolicy.TakeOwnership);
                DetectorPhysics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DISABLE_COLLISION_RESPONSE);
                DetectorPhysics.CreateFromCollisionObject((HkShape)listShape, Vector3.Zero, WorldMatrix);
                DetectorPhysics.Enabled = true;
                listShape.Base.RemoveReference();
            }

            /*
             * var inventoryBlock = this as IMyInventoryOwner;
             * if (refreshNetworks && inventoryBlock != null)
             * {
             *  CubeGrid.ConveyorSystem.Remove(inventoryBlock);
             *  CubeGrid.ConveyorSystem.Add(inventoryBlock);
             * }*/
        }