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();
            }
        }
        public AnimateTexturesEntityComponent(EntityComponentDataCreationStruct parameters) : base(parameters)
        {
            var animationDuration = GetData<float>("AnimationDuration");

            var frameCount = GetData<int>("FrameCount");
            var looping = GetDataOrDefault("Loop", true);

            AddAnimation("Default", Animation.CreateDiscrete(animationDuration, Enumerable.Range(0, frameCount).ToArray(), OnUpdateAnimationFrame, looping));
            PlayAnimation("Default");
        }
Exemple #3
0
        public AnimateTexturesEntityComponent(EntityComponentDataCreationStruct parameters) : base(parameters)
        {
            var animationDuration = GetData <float>("AnimationDuration");

            var frameCount = GetData <int>("FrameCount");
            var looping    = GetDataOrDefault("Loop", true);

            AddAnimation("Default", Animation.CreateDiscrete(animationDuration, Enumerable.Range(0, frameCount).ToArray(), OnUpdateAnimationFrame, looping));
            PlayAnimation("Default");
        }
Exemple #4
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 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 = ReferringEntity.IsActive;
            if (!ReferringEntity.IsInitializing) _drawableElement.EndInitialzing();
        }
Exemple #6
0
        public ScriptTriggerEntityComponent(EntityComponentDataCreationStruct parameters)
            : base(parameters)
        {
            _script  = GetDataOrDefault("Script", "");
            _trigger = GetDataOrDefault("Trigger", "Interaction");
            _message = GetDataOrDefault("Message", "Interact");

            _collider = new Collider(Parent.Scale, isTrigger: true);
            _collider.SetPosition(Parent.GlobalPosition);
            GameInstance.GetService <CollisionManager>().Add(_collider);
            _collider.OnTriggerEnter = OnTriggerEnter;
            _collider.OnTriggerLeave = OnTriggerLeave;

            _uiElement = new InteractionPromptOverworldUIElement(Parent, _message);
            _uiElement.InteractionStarted += InteractionHandler;
        }
        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 = ReferringEntity.IsActive;

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

            if (!ReferringEntity.IsInitializing) _drawableElement.EndInitialzing();
        }
Exemple #8
0
 public CollisionEntityComponent(EntityComponentDataCreationStruct structData) : base(structData)
 {
     Collider = new Collider(GetData <Vector3>("CollisionSize"), GetData <Vector3>("CollisionOffset"));
 }
 public AnimatorEntityComponent(EntityComponentDataCreationStruct parameter) : base(parameter)
 {
 }
        public AnimatorEntityComponent(EntityComponentDataCreationStruct parameter) : base(parameter)
        {

        }
 public DataStorageEntityComponent(EntityComponentDataCreationStruct parameters) : base(parameters)
 { }
 public DataStorageEntityComponent(EntityComponentDataCreationStruct parameters) : base(parameters)
 {
 }
 public CollisionEntityComponent(EntityComponentDataCreationStruct structData) : base(structData)
 {
     Collider = new Collider(GetData<Vector3>("CollisionSize"), GetData<Vector3>("CollisionOffset"));
 }
 public WorldUiOverlayEntityComponent(EntityComponentDataCreationStruct parameters)
     : base(parameters)
 {
 }