private void InitSensor(MyMwcObjectBuilder_EntityDetector_TypesEnum type, Vector3 size) { MySensorElement sensorElement; if (type == MyMwcObjectBuilder_EntityDetector_TypesEnum.Sphere) { MySphereSensorElement sphereSensorElement = new MySphereSensorElement(); sphereSensorElement.Radius = size.Length() / 2f; sensorElement = sphereSensorElement; EntityDetectorType = MyEntityDetectorType.Sphere; m_radius = sphereSensorElement.Radius; } else if (type == MyMwcObjectBuilder_EntityDetector_TypesEnum.Box) { MyBoxSensorElement boxSensorElement = new MyBoxSensorElement(); boxSensorElement.Size = size; sensorElement = boxSensorElement; EntityDetectorType = MyEntityDetectorType.Box; m_extent = size / 2f; } else { throw new MyMwcExceptionApplicationShouldNotGetHere(); } sensorElement.LocalPosition = Vector3.Zero; MySensorDesc senDesc = new MySensorDesc(); senDesc.m_Element = sensorElement; senDesc.m_Matrix = Matrix.Identity; senDesc.m_SensorEventHandler = this; m_sensor.Inserted = false; m_sensor.LoadFromDesc(senDesc); m_sensor.Active = true; m_size = size; }
protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig) { MyPrefabConfigurationKinematic prefabKinematicConfig = (MyPrefabConfigurationKinematic)prefabConfig; MyMwcObjectBuilder_PrefabKinematic kinematicBuilder = objectBuilder as MyMwcObjectBuilder_PrefabKinematic; MyModel model = MyModels.GetModelOnlyDummies(m_config.ModelLod0Enum); for (int i = 0; i < prefabKinematicConfig.KinematicParts.Count; i++) { MyPrefabConfigurationKinematicPart kinematicPart = prefabKinematicConfig.KinematicParts[i]; MyModelDummy open, close; if (model.Dummies.TryGetValue(kinematicPart.m_open, out open) && model.Dummies.TryGetValue(kinematicPart.m_close, out close)) { float?kinematicPartHealth = kinematicBuilder.KinematicPartsHealth[i]; float?kinematicPartMaxHealth = kinematicBuilder.KinematicPartsMaxHealth[i]; uint? kinematicPartEntityId = kinematicBuilder.KinematicPartsEntityId[i]; // if health is not set or not destroyed, then create part if (kinematicPartHealth == null || kinematicPartHealth != 0) { MyPrefabKinematicPart newPart = new MyPrefabKinematicPart(m_owner); if (kinematicPartEntityId.HasValue) { newPart.EntityId = new MyEntityIdentifier(kinematicPartEntityId.Value); } Parts[i] = newPart; newPart.Init(this, kinematicPart, prefabKinematicConfig.m_openTime, prefabKinematicConfig.m_closeTime, (MyModelsEnum)kinematicPart.m_modelMovingEnum, open.Matrix, close.Matrix, prefabKinematicConfig.MaterialType, prefabKinematicConfig.m_soundLooping, prefabKinematicConfig.m_soundOpening, prefabKinematicConfig.m_soundClosing /*, m_groupMask*/, kinematicPartHealth, kinematicPartMaxHealth, Activated); } } } //make handler m_sensorHandler = new MyPrefabKinematicSensor(this); MySphereSensorElement sensorEl = new MySphereSensorElement(); sensorEl.Radius = DETECT_RADIUS; sensorEl.LocalPosition = new Vector3(0, 0, 0); sensorEl.DetectRigidBodyTypes = MyConstants.RIGIDBODY_TYPE_SHIP; sensorEl.SpecialDetectingAngle = DETECTION_ANGLE; MySensorDesc senDesc = new MySensorDesc(); senDesc.m_Element = sensorEl; senDesc.m_Matrix = WorldMatrix; senDesc.m_SensorEventHandler = m_sensorHandler; m_sensor = new MySensor(); m_sensor.LoadFromDesc(senDesc); MyPhysics.physicsSystem.GetSensorModule().AddSensor(m_sensor); GetOwner().UpdateAABB(); UseProperties = new MyUseProperties(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB); if (kinematicBuilder.UseProperties == null) { UseProperties.Init(MyUseType.FromHUB, MyUseType.FromHUB, 3, 4000, false); } else { UseProperties.Init(kinematicBuilder.UseProperties); } UpdateHudAndCloseStatus(); }