Beispiel #1
0
        internal static MyEntity SpawnPrefab(string name, out IMyTextPanel lcd, bool isDisplay = false)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    lcd = null;
                    return(null);
                }

                PrefabBuilder.CubeBlocks.Clear(); // need no leftovers from previous spawns

                if (isDisplay)
                {
                    PrefabTextPanel.SubtypeName     = name;
                    PrefabTextPanel.FontColor       = new Vector4(1, 1, 1, 1);
                    PrefabTextPanel.BackgroundColor = new Vector4(0, 0, 0, 0);
                    PrefabTextPanel.FontSize        = DISPLAY_FONT_SIZE;
                    PrefabBuilder.CubeBlocks.Add(PrefabTextPanel);
                    var def = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(typeof(MyObjectBuilder_TextPanel), name)) as MyTextPanelDefinition;

                    if (def != null)
                    {
                        def.TextureResolution = 256;
                    }
                }
                else
                {
                    PrefabCubeBlock.SubtypeName = name;
                    PrefabBuilder.CubeBlocks.Add(PrefabCubeBlock);
                }

                MyEntities.RemapObjectBuilder(PrefabBuilder);
                var ent = MyEntities.CreateFromObjectBuilder(PrefabBuilder, true);
                ent.IsPreview = true;  // don't sync on MP
                ent.SyncFlag  = false; // don't sync on MP
                ent.Save      = false; // don't save this entity

                MyEntities.Add(ent, true);
                var lcdSlim = ((IMyCubeGrid)ent).GetCubeBlock(Vector3I.Zero);
                lcd = lcdSlim.FatBlock as IMyTextPanel;
                //lcd.Render.CastShadows = false;
                //lcd.Render.Transparency = 0.5f;
                //lcd.Render.NeedsResolveCastShadow = false;
                //lcd.Render.EnableColorMaskHsv = false;
                //lcd.Render.DrawInAllCascades = false;

                //lcd.Render.UpdateRenderObject(false, true);
                //lcd.Render.UpdateRenderObject(true, true);
                //lcd.Render.RemoveRenderObjects();
                //lcd.Render.AddRenderObjects();
                lcd.SetEmissiveParts("ScreenArea", Color.White, 1f);
                lcd.SetEmissiveParts("Edges", Color.Teal, 0.5f);

                lcd.ContentType = ContentType.TEXT_AND_IMAGE;

                return(ent);
            }
            catch (Exception ex) { Log.Line($"Exception in SpawnPrefab: {ex}"); }

            lcd = null;
            return(null);
        }