Esempio n. 1
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);
            }
        }