protected override void ClientInitialize(ClientInitializeData data)
        {
            base.ClientInitialize(data);

            PowerGridSystem.ClientInitializeConsumerOrProducer(data.GameObject);

            // create sound emitter
            var soundEmitter = Client.Audio.CreateSoundEmitter(
                data.GameObject,
                new SoundResource("Objects/Structures/ObjectFridge/Active"),
                isLooped: true,
                volume: 0.35f,
                radius: 1f);

            soundEmitter.CustomMaxDistance = 3.5f;
            this.ClientSetupSoundEmitter(soundEmitter);

            var publicState = data.PublicState;

            publicState.ClientSubscribe(_ => _.ElectricityConsumerState,
                                        _ => RefreshSoundEmitterState(),
                                        data.ClientState);

            RefreshSoundEmitterState();

            void RefreshSoundEmitterState()
            {
                soundEmitter.IsEnabled = publicState.ElectricityConsumerState
                                         == ElectricityConsumerState.PowerOnActive;
            }
        }
예제 #2
0
        protected override void ClientInitialize(ClientInitializeData data)
        {
            base.ClientInitialize(data);

            var worldObject = data.GameObject;
            var publicState = data.PublicState;
            var renderer    = data.ClientState.Renderer;
            var sceneObject = worldObject.ClientSceneObject;

            PowerGridSystem.ClientInitializeConsumerOrProducer(worldObject);
            var soundEmitter = Client.Audio.CreateSoundEmitter(
                worldObject,
                SoundResourceActive,
                is3D: true,
                volume: 1.0f,
                isLooped: true);

            soundEmitter.CustomMinDistance = 3.0f;
            soundEmitter.CustomMaxDistance = 6.0f;

            // add sprite sheet animation for fan sprite
            var componentAnimator = sceneObject.AddComponent <ClientComponentSpriteSheetAnimator>();

            componentAnimator.Setup(renderer,
                                    ClientComponentSpriteSheetAnimator.CreateAnimationFrames(this.textureAtlasActive)
                                    .Skip(1)
                                    .ToArray(),
                                    isLooped: true,
                                    frameDurationSeconds: 6 / 60.0,
                                    randomizeInitialFrame: true);

            publicState.ClientSubscribe(
                _ => _.ElectricityConsumerState,
                _ => RefreshActiveState(),
                data.ClientState);

            RefreshActiveState();

            void RefreshActiveState()
            {
                var isActive = publicState.ElectricityConsumerState
                               == ElectricityConsumerState.PowerOnActive;

                componentAnimator.IsEnabled = isActive;
                soundEmitter.IsEnabled      = isActive;

                if (!isActive)
                {
                    // reset to default texture
                    renderer.TextureResource = this.DefaultTexture;
                }
            }
        }
예제 #3
0
        protected override void ClientInitialize(ClientInitializeData data)
        {
            base.ClientInitialize(data);

            var publicState = data.PublicState;
            var renderer    = data.ClientState.Renderer;

            PowerGridSystem.ClientInitializeConsumerOrProducer(data.GameObject);

            publicState.ClientSubscribe(_ => _.WaterAmountPercent,
                                        _ => RefreshTexture(),
                                        data.ClientState);

            RefreshTexture();

            void RefreshTexture()
            {
                var columnIndex = (1 - publicState.WaterAmountPercent / 100.0)
                                  * (this.textureAtlas.AtlasSize.ColumnsCount - 1);

                renderer.TextureResource = this.textureAtlas.Chunk((byte)Math.Ceiling(columnIndex), 0);
            }
        }
예제 #4
0
 protected override void ClientInitialize(ClientInitializeData data)
 {
     base.ClientInitialize(data);
     PowerGridSystem.ClientInitializeConsumerOrProducer(data.GameObject);
 }