public void Init(MyPrefabBase kinematicPartOwner, MyMwcObjectBuilderTypeEnum prefabKinematicPartBuilderType, int? prefabKinematicPartBuilderId, MyModelsEnum modelEnum, MyMaterialType materialType, Matrix kinematicLocalMatrix, float kinematicVelocityMax, MySoundCuesEnum? loopSound, MySoundCuesEnum? loopDamagedSound, MySoundCuesEnum? startSound, MySoundCuesEnum? endSound, float kinematicStart, float kinematicEnd) { m_needsUpdate = true; m_kinematicPartOwner = kinematicPartOwner; m_kinematicLocalMatrix = kinematicLocalMatrix; m_kinematicVelocityMax = kinematicVelocityMax; m_kinematicStart = kinematicStart; m_kinematicEnd = kinematicEnd; m_loopSoundCue = loopSound; m_loopDamagedSoundCue = loopDamagedSound; m_startSoundCue = startSound; m_endSoundCue = endSound; MyMwcObjectBuilder_Base objbuilder = MyMwcObjectBuilder_Base.CreateNewObject(prefabKinematicPartBuilderType, prefabKinematicPartBuilderId); m_config = m_kinematicPartOwner.GetConfiguration(); base.Init(null, modelEnum, null, kinematicPartOwner, null, objbuilder); LocalMatrix = Matrix.Identity; MaterialIndex = m_kinematicPartOwner.MaterialIndex; //InitTrianglePhysics(materialType, 1.0f, ModelLod0, null, MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC_PART); InitBoxPhysics(materialType, ModelLod0, 100, 0, MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC_PART, RigidBodyFlag.RBF_RBO_STATIC); Physics.Enabled = true; m_kinematicPartOwner.OnPositionChanged += OwnerPositionChanged; }
public void Init(MyPrefabBase rotatingOwner, MyModelsEnum modelEnum, MyMaterialType matType, Matrix rotatingLocal, float rotatingVelocityMax, MySoundCuesEnum? loopSound, MySoundCuesEnum? loopDamagedSound, MySoundCuesEnum? startSound, MySoundCuesEnum? endSound, Vector3 rotationVector, bool activated) { m_rotationVector = rotationVector; base.Init(rotatingOwner, MyMwcObjectBuilderTypeEnum.PrefabKinematicRotatingPart, (int)MyMwcObjectBuilder_PrefabKinematicRotatingPart_TypesEnum.DEFAULT, modelEnum, matType, rotatingLocal, rotatingVelocityMax, loopSound, loopDamagedSound, startSound, endSound, 1f, 1f); if (activated) { PersistentFlags &= ~MyPersistentEntityFlags.Deactivated; } else { PersistentFlags |= MyPersistentEntityFlags.Deactivated; } }
public static List<MyPrefabSnapPoint> GetSnapPoints(MyModel model, MyPrefabBase prefab) { List<MyPrefabSnapPoint> snapPoints = new List<MyPrefabSnapPoint>(); foreach (var dummy in model.Dummies) { if (dummy.Key.StartsWith("SNAPPOINT", StringComparison.InvariantCultureIgnoreCase)) { var customData = dummy.Value.CustomData; var snapPoint = new MyPrefabSnapPoint(prefab); // Get rid of scale in rotation part snapPoint.Matrix = Matrix.CreateWorld(dummy.Value.Matrix.Translation, dummy.Value.Matrix.Forward, dummy.Value.Matrix.Up); snapPoint.SnapType = new MyPrefabSnapPoint.MyPrefabSnapPointType("OBJECT_", "", dummy.Value.CustomData); snapPoint.Name = dummy.Key; snapPoints.Add(snapPoint); string targetPostfix = "TARGET_BUILD_TYPE"; foreach (var target in customData) { if (target.Key.StartsWith(targetPostfix)) { string postfix = target.Key.Substring(targetPostfix.Length); snapPoint.SnapTargets.Add(new MyPrefabSnapPoint.MyPrefabSnapPointType( "TARGET_", postfix, dummy.Value.CustomData)); } } } } return snapPoints; }
public MyGuiControlPrefabUse(IMyGuiControlsParent parent, MyPrefabBase prefab) : base(parent, new Vector2(0.452f, 0.127f), prefab) { }
public MyGuiControlPrefabUse(IMyGuiControlsParent parent, MyPrefabBase prefab, MyTexture2D texture) : base(parent, new Vector2(0.452f, 0.127f), prefab, texture) { }
/// <summary> /// Try find generator for prefab which will supply electricity /// </summary> public void FindGeneratorsFor(MyPrefabBase prefab) { int generatorsCount = 0; foreach (var item in m_prefabs) { MyPrefabGenerator generator = item as MyPrefabGenerator; if (generator != null && generator.IsWorking()) { float distanceSqr = generator.GetRange() + WorldVolume.Radius; distanceSqr *= distanceSqr; if(Vector3.DistanceSquared(prefab.GetPosition(), generator.GetPosition()) <= distanceSqr) { //prefab.Generator = generator; //return; generatorsCount++; } } } //prefab.Generator = null; prefab.GeneratorsCount = generatorsCount; }
/// <summary> /// Add prefab into container - reparenting,... /// </summary> /// <param name="prefab"></param> public void AddPrefab(MyPrefabBase prefab) { //@ Add prefab //if (this.Children.Contains(prefab)) //{ // prefab.SetVisible = true; //} //else //{ // this.Children.Add(prefab); // m_prefabs.Add(prefab); //} Debug.Assert(prefab.Parent == this); if (!m_prefabs.Contains(prefab)) { m_prefabs.Add(prefab); } else { prefab.Visible = true; } UpdateAABB(); // update prefab type flags foreach (PrefabTypesFlagEnum prefabTypeSingleFlag in MyPrefabTypesFlagHelper.ParseToSingleFlags(prefab.PrefabTypeFlag)) { // if we added first prefab of this type, then we update prefab types flag in prefab container if (m_prefabTypeSingleFlagsCount[(int)prefabTypeSingleFlag] == 0) { m_prefabTypesFlag = m_prefabTypesFlag | prefabTypeSingleFlag; } m_prefabTypeSingleFlagsCount[(int)prefabTypeSingleFlag]++; if (prefabTypeSingleFlag == PrefabTypesFlagEnum.Vendor) { Debug.Assert(m_prefabTypeSingleFlagsCount[(int)prefabTypeSingleFlag] <= 1, "You can have max 1 vendor in prefab container!"); } } // add prefab to categories dictionary m_prefabsByCategory[(ushort)prefab.PrefabCategory].Add(prefab); if (!m_intializing) { if (prefab is MyPrefabGenerator) { UpdateGenerators(); } else { FindGeneratorsFor(prefab); } } }
// Removes prefab from this container working prefabs list public void RemovePrefab(MyPrefabBase prefab) { this.Children.Remove(prefab); m_prefabs.Remove(prefab); UpdateAABB(); // update prefab type flags foreach (PrefabTypesFlagEnum prefabTypeSingleFlag in MyPrefabTypesFlagHelper.ParseToSingleFlags(prefab.PrefabTypeFlag)) { // if we remove last prefab of this type, then we update prefab types flag in prefab container m_prefabTypeSingleFlagsCount[(int)prefabTypeSingleFlag]--; if (m_prefabTypeSingleFlagsCount[(int)prefabTypeSingleFlag] == 0) { m_prefabTypesFlag = m_prefabTypesFlag & (~prefabTypeSingleFlag); } } // remove prefab from categories dictionary m_prefabsByCategory[(ushort)prefab.PrefabCategory].Remove(prefab); m_deactivatedPrefabs.Remove(prefab); }
public void ActivatePrefab(MyPrefabBase prefab) { m_deactivatedPrefabs.Remove(prefab); }
public void DeactivatePrefab(MyPrefabBase prefab) { if(!m_deactivatedPrefabs.Contains(prefab) && prefab.Parent == this) { m_deactivatedPrefabs.Add(prefab); } }
/// <summary> /// Edit prefab /// </summary> /// <param name="prefab">Prefab</param> public MyGuiScreenEditorPrefab(MyPrefabBase prefab) : base(prefab, new Vector2(0.5f, 0.5f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, null, MyTextsWrapperEnum.EditPrefab) { Init(); }