Beispiel #1
0
        protected override ITextureResource PrepareDefaultTexture(Type thisType)
        {
            this.atlasTexture = new TextureAtlasResource(GenerateTexturePath(thisType) + "Animation",
                                                         columns: 4,
                                                         rows: 1,
                                                         isTransparent: true);

            return(this.atlasTexture.Chunk(0, 0));
        }
 public static void Setup(
     IComponentSpriteRenderer spriteRenderer,
     ITextureAtlasResource textureAtlas,
     double totalDuration)
 {
     Setup(spriteRenderer,
           ClientComponentSpriteSheetAnimator.CreateAnimationFrames(textureAtlas),
           totalDuration);
 }
Beispiel #3
0
        protected override ITextureResource PrepareDefaultTexture(Type thisType)
        {
            this.textureAtlasActive = new TextureAtlasResource(
                GenerateTexturePath(thisType),
                columns: 5,
                rows: 1,
                isTransparent: true);

            return(this.textureAtlasActive);
        }
Beispiel #4
0
        protected override ITextureResource PrepareDefaultTexture(Type thisType)
        {
            this.textureAtlasAnimation =
                this.PrepareTextureAtlasAnimation(out var animationFrameDurationSeconds,
                                                  out var animationDrawPositionWorldOffset);
            this.textureAtlasAnimationFrameDurationSeconds    = animationFrameDurationSeconds;
            this.textureAltasAnimationDrawPositionWorldOffset = animationDrawPositionWorldOffset;

            return(base.PrepareDefaultTexture(thisType));
        }
Beispiel #5
0
 private void InitProceduralTextureAtlas()
 {
     if (this.proceduralTextureAtlasPrimary == null)
     {
         this.proceduralTextureAtlasPrimary =
             FloorTextureComposer.CreateProceduralTexture(
                 this.Id + "_Primary",
                 this.texturePrimaryAtlas);
     }
 }
Beispiel #6
0
        protected virtual void ClientSetupExtractorActiveAnimation(
            IStaticWorldObject worldObject,
            ObjectManufacturerPublicState serverPublicState,
            ITextureAtlasResource textureAtlasResource,
            Vector2D positionOffset,
            double frameDurationSeconds,
            bool autoInverseAnimation      = false,
            bool randomizeInitialFrame     = false,
            bool playAnimationSounds       = true,
            OnRefreshActiveState onRefresh = null)
        {
            var clientState = worldObject.GetClientState <StaticObjectClientState>();
            var sceneObject = worldObject.ClientSceneObject;

            var overlayRenderer = Client.Rendering.CreateSpriteRenderer(
                sceneObject,
                TextureResource.NoTexture,
                DrawOrder.Default,
                positionOffset: positionOffset,
                spritePivotPoint: Vector2D.Zero);

            overlayRenderer.DrawOrderOffsetY = -positionOffset.Y - 0.01;

            var spriteSheetAnimator = sceneObject.AddComponent <ClientComponentSpriteSheetAnimator>();

            spriteSheetAnimator.Setup(
                overlayRenderer,
                ClientComponentSpriteSheetAnimator.CreateAnimationFrames(
                    textureAtlasResource,
                    autoInverse: autoInverseAnimation),
                isLooped: true,
                frameDurationSeconds: frameDurationSeconds,
                randomizeInitialFrame: randomizeInitialFrame);

            // we play Active sound for pumping on both up and down position of the oil pump
            var componentActiveState = sceneObject.AddComponent <ClientComponentOilPumpActiveState>();

            componentActiveState.Setup(overlayRenderer, spriteSheetAnimator, worldObject, playAnimationSounds);

            serverPublicState.ClientSubscribe(
                s => s.IsActive,
                callback: RefreshActiveState,
                subscriptionOwner: clientState);

            spriteSheetAnimator.IsEnabled = overlayRenderer.IsEnabled = false;

            RefreshActiveState(serverPublicState.IsActive);

            void RefreshActiveState(bool isActive)
            {
                // ReSharper disable once PossibleNullReferenceException
                componentActiveState.IsActive = isActive;
                onRefresh?.Invoke(isActive);
            }
        }
        protected void ClientSetupManufacturerActiveAnimation(
            IStaticWorldObject worldObject,
            ObjectManufacturerPublicState serverPublicState,
            ITextureAtlasResource textureAtlasResource,
            Vector2D positionOffset,
            double frameDurationSeconds,
            double drawOrderOffsetY        = 0,
            bool autoInverseAnimation      = false,
            OnRefreshActiveState onRefresh = null)
        {
            var clientState = worldObject.GetClientState <StaticObjectClientState>();

            var sceneObject = Client.Scene.GetSceneObject(worldObject);

            var overlayRenderer = Client.Rendering.CreateSpriteRenderer(
                sceneObject,
                TextureResource.NoTexture,
                DrawOrder.Default,
                positionOffset: positionOffset,
                spritePivotPoint: Vector2D.Zero);

            overlayRenderer.DrawOrderOffsetY = drawOrderOffsetY - positionOffset.Y - 0.01;

            var spriteSheetAnimator = sceneObject.AddComponent <ClientComponentSpriteSheetAnimator>();

            spriteSheetAnimator.Setup(
                overlayRenderer,
                ClientComponentSpriteSheetAnimator.CreateAnimationFrames(
                    textureAtlasResource,
                    autoInverse: autoInverseAnimation),
                frameDurationSeconds: frameDurationSeconds);

            var soundEmitterActiveState = this.ClientCreateActiveStateSoundEmitterComponent(worldObject, sceneObject);

            serverPublicState.ClientSubscribe(
                s => s.IsManufacturingActive,
                callback: RefreshActiveState,
                subscriptionOwner: clientState);

            RefreshActiveState(serverPublicState.IsManufacturingActive);

            void RefreshActiveState(bool isActive)
            {
                overlayRenderer.IsEnabled     = isActive;
                spriteSheetAnimator.IsEnabled = isActive;
                if (soundEmitterActiveState != null)
                {
                    soundEmitterActiveState.IsEnabled = isActive;
                }

                onRefresh?.Invoke(isActive);
            }
        }
Beispiel #8
0
        //public ITextureResource[] FramesTextureResources => this.framesTextureResources;

        /// <summary>
        /// Generate textures from atlas.
        /// </summary>
        /// <param name="textureAtlasResource">Texture atlas.</param>
        /// <param name="columns">(optional)</param>
        /// <param name="rowsCount">(optional)</param>
        /// <param name="autoInverse">
        /// (optional) Enable this if you want to append reverse animation. Please note - first and last
        /// frame will be displayed twice.
        /// </param>
        /// <returns></returns>
        public static ITextureResource[] CreateAnimationFrames(
            ITextureAtlasResource textureAtlasResource,
            byte?columns         = null,
            byte?rowsCount       = null,
            byte?onlySpecificRow = null,
            bool autoInverse     = false)
        {
            var atlasColumnsCount = columns ?? textureAtlasResource.AtlasSize.ColumnsCount;
            var atlasRowsCount    = rowsCount ?? textureAtlasResource.AtlasSize.RowsCount;

            int chunksCount;

            if (onlySpecificRow.HasValue)
            {
                chunksCount = atlasColumnsCount;
            }
            else
            {
                chunksCount = atlasColumnsCount * atlasRowsCount;
            }

            var result = new ITextureResource[chunksCount * (autoInverse ? 2 : 1)];

            if (onlySpecificRow.HasValue)
            {
                var row = onlySpecificRow.Value;
                for (byte column = 0; column < atlasColumnsCount; column++)
                {
                    result[column] = textureAtlasResource.Chunk(column, row);
                }
            }
            else
            {
                for (byte row = 0; row < atlasRowsCount; row++)
                {
                    for (byte column = 0; column < atlasColumnsCount; column++)
                    {
                        result[row * atlasColumnsCount + column] = textureAtlasResource.Chunk(column, row);
                    }
                }
            }

            if (autoInverse)
            {
                for (var i = 0; i < chunksCount; i++)
                {
                    result[chunksCount + i] = result[chunksCount - i - 1];
                }
            }

            return(result);
        }
 protected sealed override ITextureResource PrepareDefaultTexture(Type thisType)
 {
     return(this.textureAtlas = this.PrepareDefaultTextureAtlas(thisType));
 }