public void DeactivatePrefab(MyPrefabBase prefab) { if (!m_deactivatedPrefabs.Contains(prefab) && prefab.Parent == this) { m_deactivatedPrefabs.Add(prefab); } }
/// <summary> /// Adds entity to scene /// </summary> /// <param name="entity"></param> protected virtual void AddToScene(MyEntity entity) { //add entity into world if possible to ensure we manipulate with object in scene if (!(entity is MyPrefabBase)) { // Quit container edit mode if entity was created in non-edit mode if (m_activeContainer == null && MyEditor.Static.IsEditingPrefabContainer()) { MyEditor.Static.ExitActivePrefabContainer(); } MyEntities.Add(entity); } else { // In case undo/redo is performed on prefab, make sure that its parent container is switched to edit mode MyPrefabBase prefab = (MyPrefabBase)entity; MyEditor.Static.EditPrefabContainer(m_activeContainer); MyEditor.Static.GetEditedPrefabContainer().AddPrefab(prefab); } // adding an entity will make its type selectable Type type = null; if (entity is MyPrefabBase || entity is MyPrefabContainer) { type = typeof(MyPrefabBase); } else if (entity is MyWayPoint) { type = typeof(MyWayPoint); } else if (entity is MyVoxelMap) { type = typeof(MyVoxelMap); } else if (entity is MyDummyPoint) { type = typeof(MyDummyPoint); } else if (entity is MySpawnPoint) { type = typeof(MySpawnPoint); } else if (entity is MyInfluenceSphere) { type = typeof(MyInfluenceSphere); } if (type != null) { MyEntities.SetTypeHidden(type, false); MyEntities.SetTypeSelectable(type, true); } MyEditorGizmo.AddEntityToSelection(entity); }
/// <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); } } }
void EntityClosing(MyEntity entity) { MyPrefabBase prefab = entity as MyPrefabBase; if ((m_destroySolarPanelsFirst.IsAvailable() || m_destroySolarPanelsSecond.IsAvailable()) && (prefab != null && entity is MyPrefabLight == false && prefab.Parent != null && prefab.Parent.EntityId.HasValue && prefab.Parent.EntityId.Value.NumericValue == 42938) ) { --m_panelsLeft; AddPanelPercentNotification(); } }
//public void AssignToFoundationFactory(MyFoundationFactory foundationFactory) //{ // Debug.Assert(m_prefabTypeSingleFlagsCount[(int) PrefabTypesFlagEnum.FoundationFactory] == 0); // m_prefabTypesFlag = m_prefabTypesFlag | PrefabTypesFlagEnum.FoundationFactory; // m_prefabTypeSingleFlagsCount[(int)PrefabTypesFlagEnum.FoundationFactory]++; // if (MyEntities.Exist(this)) // { // MyEntities.Remove(this); // } // foundationFactory.AddChild(this, true); //} // This method is responsible for adding new prefab modules into container public MyEntity CreateAndAddPrefab(string hudLabelText, MyMwcObjectBuilder_PrefabBase prefabBuilder) { if (m_prefabs.Count + 1 >= m_prefabs.Capacity) { return(null); } MyPrefabBase prefab = MyPrefabFactory.GetInstance().CreatePrefab(hudLabelText, this, prefabBuilder); this.AddPrefab(prefab); return((MyEntity)prefab); }
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; } }
protected override bool IsObjectMeetDetectCriterium(IMyObjectToDetect objectToDetect) { if (objectToDetect is MySmallShip) { MySmallShip smallShip = objectToDetect as MySmallShip; return(smallShip.Radar != null); } if (objectToDetect is MyPrefabBase) { MyPrefabBase prefab = objectToDetect as MyPrefabBase; return(prefab.GetOwner().ContainsPrefab(PrefabTypesFlagEnum.LargeShip)); } return(false); }
// 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); }
/// <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> /// 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(); }
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) { }
public void ActivatePrefab(MyPrefabBase prefab) { m_deactivatedPrefabs.Remove(prefab); }
/// <summary> /// CreatePrefab /// </summary> /// <param name="hudLabelText"></param> /// <param name="objBuilder"></param> /// <returns></returns> public MyPrefabBase CreatePrefab(string hudLabelText, MyPrefabContainer prefabContainer, MyMwcObjectBuilder_PrefabBase prefabBuilder) { Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyPrefabFactory.CreatePrefab"); MyPrefabConfiguration config = MyPrefabConstants.GetPrefabConfiguration(prefabBuilder.GetObjectBuilderType(), prefabBuilder.GetObjectBuilderId().Value); Vector3 relativePosition = MyPrefabContainer.GetRelativePositionInAbsoluteCoords(prefabBuilder.PositionInContainer); Matrix prefabLocalOrientation = Matrix.CreateFromYawPitchRoll(prefabBuilder.AnglesInContainer.X, prefabBuilder.AnglesInContainer.Y, prefabBuilder.AnglesInContainer.Z); MyPrefabBase prefab = null; if (config is MyPrefabConfigurationKinematic) { prefab = new MyPrefabKinematic(prefabContainer); } else if (config is MyPrefabConfigurationLight) { prefab = new MyPrefabLight(prefabContainer); } else if (config is MyPrefabConfigurationLargeWeapon) { prefab = new MyPrefabLargeWeapon(prefabContainer); } else if (config is MyPrefabConfigurationSound) { prefab = new MyPrefabSound(prefabContainer); } else if (config is MyPrefabConfigurationParticles) { prefab = new MyPrefabParticles(prefabContainer); } else if (config is MyPrefabConfigurationLargeShip) { prefab = new MyPrefabLargeShip(prefabContainer); } else if (config is MyPrefabConfigurationHangar) { prefab = new MyPrefabHangar(prefabContainer); } else if (config is MyPrefabConfigurationFoundationFactory) { prefab = new MyPrefabFoundationFactory(prefabContainer); } else if (config is MyPrefabConfigurationSecurityControlHUB) { prefab = new MyPrefabSecurityControlHUB(prefabContainer); } else if (config is MyPrefabConfigurationBankNode) { prefab = new MyPrefabBankNode(prefabContainer); } else if (config is MyPrefabConfigurationGenerator) { prefab = new MyPrefabGenerator(prefabContainer); } else if (config is MyPrefabConfigurationScanner) { prefab = new MyPrefabScanner(prefabContainer); } else if (config is MyPrefabConfigurationCamera) { prefab = new MyPrefabCamera(prefabContainer); } else if (config is MyPrefabConfigurationAlarm) { prefab = new MyPrefabAlarm(prefabContainer); } else { prefab = new MyPrefab(prefabContainer); //prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config); } prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config); Render.MyRender.GetRenderProfiler().EndProfilingBlock(); return(prefab); }