public TilemapEntityComponent(EntityComponentDataCreationStruct parameters) : base(parameters)
        {
            var gameMode = GameInstance.GetService <GameModeManager>().ActiveGameMode;

            _drawableElement = GameInstance.GetService <SceneRenderer>().CreateDrawableElement(true);

            _drawableElement.Material = new Material
            {
                Color           = new Color(GetDataOrDefault("Shading", Vector3.One)),
                CastShadow      = true,
                ReceiveShadow   = true,
                UseTransparency = false,
                IsUnlit         = false,
                DiffuseTexture  = gameMode.GetTexture(GetData <string>("Texture"))
            };

            _drawableElement.IsActive = Parent.IsActive;

            var geometryData = CreateTilemapData();

            GameInstance.EnsureExecutedInMainThread(() => _drawableElement.Mesh = new Mesh(GameInstance.GraphicsDevice, geometryData, holdGeometryData: false));

            if (!Parent.IsInitializing)
            {
                _drawableElement.EndInitialzing();
            }
        }
Beispiel #2
0
        public ModelEntityComponent(EntityComponentDataCreationStruct parameters) : base(parameters)
        {
            _drawableElement = GameInstance.GetService<SceneRenderer>().CreateDrawableElement(true);
            IsBillboard = GetDataOrDefault("IsBillboard", false);

            var modelReference = GetData<string>("MeshReference");
            var useTransparency = GetDataOrDefault("UseTransparency", false);
            var gameMode = GameInstance.GetService<GameModeManager>().ActiveGameMode;

            if (!string.IsNullOrEmpty(modelReference))
            {
                var primitiveMesh = gameMode.GetPrimitiveMesh(modelReference);
                if (primitiveMesh != null)
                {
                    _drawableElement.Mesh = primitiveMesh;
                    _drawableElement.Material = new Material();
                }
                else
                {
                    var modelMesh = gameMode.GetModel(modelReference).First();
                    _drawableElement.Mesh = modelMesh.Mesh;
                    _drawableElement.Material = modelMesh.Material;

                }

                _drawableElement.Material.Color = new Color(GetDataOrDefault("Shading", Vector3.One));
                _drawableElement.Material.CastShadow = true;
                _drawableElement.Material.ReceiveShadow = !useTransparency;
                _drawableElement.Material.UseTransparency = useTransparency;
                _drawableElement.Material.IsUnlit = false;
            }

            _regions = new List<TextureRegion>();
            var textures = GetEnumeratedData<string>("Texture");
            var regions = GetEnumeratedData<Rectangle>("Rectangle");

            if (textures.Length == 1)
            {
                AddTextureRegion(gameMode.GetTexture(textures[0]), regions.Length == 0 ? (Rectangle?)null : regions[0]);
            }
            else
            {
                for (var i = 0; i < textures.Length; i++)
                {
                    AddTextureRegion(gameMode.GetTexture(textures[0]), i >= regions.Length ? (Rectangle?)null : regions[i]);
                }
            }

            SetTexture(0);

            _drawableElement.IsActive = Parent.IsActive;
            if (!Parent.IsInitializing) _drawableElement.EndInitialzing();
        }
 public override void OnInitialized()
 {
     _drawableElement.EndInitialzing();
 }