public void Init(MyPrefabKinematic owner, MyPrefabConfigurationKinematicPart config, float openTime, float closeTime, MyModelsEnum modelEnum, Matrix open, Matrix close, MyMaterialType matType, MySoundCuesEnum?loopSound, MySoundCuesEnum?startSound, MySoundCuesEnum?endSound /*, MyGroupMask grpMask*/, float?health, float?maxHealth, bool activated) { m_needsUpdate = config.NeedsUpdate; m_openTime = openTime * 1000; m_closeTime = closeTime * 1000; m_radialState = MAX_RADIAL_STATE;// 0; m_config = config; m_loopSoundCue = loopSound; m_startSoundCue = startSound; m_endSoundCue = endSound; m_openLocalPosition = open.Translation - close.Translation; m_looping = false; m_ownerKinematic = owner; m_lastUpdateTime = 0; MyMwcObjectBuilder_Base objbuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.PrefabKinematicPart, config.PrefabId); objbuilder.EntityId = MyEntityIdentifier.ToNullableInt(EntityId); StringBuilder hudLabelTextSb = null; base.Init(hudLabelTextSb, modelEnum, null, owner, null, objbuilder); if (maxHealth != null) { MaxHealth = maxHealth.Value; } if (health != null) { Health = health.Value; } //LocalMatrix = Matrix.Invert(MyMath.NormalizeMatrix(close)); LocalMatrix = Matrix.CreateTranslation(Vector3.Zero); InitTrianglePhysics(matType, 1.0f, ModelLod0, null, MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC_PART); SetState(KinematicPrefabStateEnum.Sleeping); if (activated) { PersistentFlags &= ~MyPersistentEntityFlags.Deactivated; } else { PersistentFlags |= MyPersistentEntityFlags.Deactivated; } //StartClosing(); }
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(); }