Exemplo n.º 1
0
        public ScorePage(
            AssetsLoader assets,
            ISettingsRepository settingsRepository,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _font                = assets.Font;
            _background          = assets.OtherSprites["scoreBackground"];
            _matrixScaleProvider = matrixScaleProvider;

            _titleText          = localizedStringsRepository.Get(GameStringsLoader.ScorePageTitleString);
            _titleScalingObject = new ScalingObject(1f, 1.2f, 1.0f);
            _titleDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 100f),
                Origin   = _font.GetTextCenter(_titleText)
            };

            float textsScale = 0.4f;

            var bestFarts           = settingsRepository.GetOrSetInt(GameScores.BestFartsScoreKey, default);
            var bestNumberOfMeters  = settingsRepository.GetOrSetInt(GameScores.BestNumberOfMetersScoreKey, default);
            var bestVegetablesEaten = settingsRepository.GetOrSetInt(GameScores.BestVegetablesEatenScoreKey, default);

            _scoreInfos = new List <ScoreRecordText>()
            {
                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestNumberOfMetersScoreKey)}{bestNumberOfMeters}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 100f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestVegetablesEatenScoreKey)}{bestVegetablesEaten}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 140f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestFartsScoreKey)}{bestFarts}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 180f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),
            };

            _nTexts        = _scoreInfos.Count;
            _currentTextId = 0;
            _fadeObject    = new FadeObject(TimeSpan.FromMilliseconds(500), Color.White);
            _fadeObject.FadeInCompleted += _textFadeObject_FadeInCompleted;
            _fadeObject.FadeIn();
        }
Exemplo n.º 2
0
        public GameOrchestrator(
            Func <InfartGame> gameFactory,
            Func <MainMenuPage> menuFactory,
            Func <ScorePage> scoreFactory,
            GraphicsDevice graphicsDevice,
            AssetsLoader assets,
            ISettingsRepository settingsRepository,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            IWebPageOpener webPageOpener,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _gameFactory  = gameFactory ?? throw new ArgumentNullException(nameof(gameFactory));
            _menuFactory  = menuFactory ?? throw new ArgumentNullException(nameof(menuFactory));
            _scoreFactory = scoreFactory ?? throw new ArgumentNullException(nameof(scoreFactory));

            _webPageOpener  = webPageOpener ?? throw new ArgumentNullException(nameof(webPageOpener));
            _graphicsDevice = graphicsDevice ?? throw new ArgumentNullException(nameof(graphicsDevice));

            _assets                     = assets ?? throw new ArgumentNullException(nameof(assets));
            _settingsRepository         = settingsRepository ?? throw new ArgumentNullException(nameof(settingsRepository));
            _localizedStringsRepository = localizedStringsRepository ?? throw new ArgumentNullException(nameof(localizedStringsRepository));

            _matrixScaleProvider = matrixScaleProvider ?? throw new ArgumentNullException(nameof(matrixScaleProvider));
            if (_matrixScaleProvider is DynamicScalingMatrixProvider)
            {
                (_matrixScaleProvider as DynamicScalingMatrixProvider).ScaleMatrixChanged += GameOrchestrator_ScaleMatrixChanged;
            }
            RegenerateRenderTarget();

            ShouldEndApplication = false;

            _stateTransition = new FadeObject(_fadeDuration, Color.White);
            _stateTransition.FadeOutCompleted += _stateTransition_FadeOutCompleted;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 运行淡出动画
        /// </summary>
        /// <param name="gameObject">执行对象</param>
        /// <param name="timeInSecond">执行时间</param>
        /// <param name="hidden">执行完毕是否将对象设置为不激活</param>
        /// <param name="material">执行材质</param>
        public FadeObject AddFadeOut(Text text, float timeInSecond, bool hidden)
        {
            if (text != null)
            {
                FadeObject fadeObject = FindFadeObjectByText(text, FadeType.FadeOut);
                if (fadeObject != null)
                {
                    fadeObjects.Remove(fadeObject);
                }

                fadeObject              = new FadeObject();
                fadeObject.gameObject   = text.gameObject;
                fadeObject.timeInSecond = timeInSecond;
                fadeObject.alpha        = 1;
                fadeObject.material     = null;
                fadeObject.text         = text;
                fadeObject.fadeType     = FadeType.FadeOut;
                fadeObject.endReactive  = hidden;
                fadeObjects.Add(fadeObject);

                text.color = new Color(text.color.r, text.color.g, text.color.b, 1);
                return(fadeObject);
            }
            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 运行淡出动画
        /// </summary>
        /// <param name="gameObject">执行对象</param>
        /// <param name="timeInSecond">执行时间</param>
        /// <param name="hidden">执行完毕是否将对象设置为不激活</param>
        /// <param name="material">执行材质</param>
        public FadeObject AddFadeOut(GameObject gameObject, float timeInSecond, bool hidden, Material[] materials)
        {
            FadeObject fadeObject = FindFadeObjectByGameObject(gameObject, FadeType.FadeOut);

            if (fadeObject != null)
            {
                fadeObjects.Remove(fadeObject);
            }

            fadeObject              = new FadeObject();
            fadeObject.gameObject   = gameObject;
            fadeObject.timeInSecond = timeInSecond;
            fadeObject.alpha        = 1;
            fadeObject.materials    = materials;
            fadeObject.fadeType     = FadeType.FadeOut;
            if (materials != null && materials.Length > 0)
            {
                foreach (Material m in materials)
                {
                    m.color = new Color(m.color.r, m.color.g, m.color.b, 1);
                }
            }
            fadeObject.endReactive = hidden;
            fadeObjects.Add(fadeObject);
            return(fadeObject);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 运行淡入动画
        /// </summary>
        /// <param name="gameObject">执行对象</param>
        /// <param name="timeInSecond">执行时间</param>
        /// <param name="material">执行材质</param>
        public FadeObject AddFadeIn(Text text, float timeInSecond)
        {
            if (text != null)
            {
                FadeObject fadeObject = FindFadeObjectByText(text, FadeType.FadeIn);
                if (fadeObject != null)
                {
                    fadeObjects.Remove(fadeObject);
                }

                fadeObject              = new FadeObject();
                fadeObject.gameObject   = text.gameObject;
                fadeObject.timeInSecond = timeInSecond;
                fadeObject.alpha        = 0;
                fadeObject.material     = null;
                fadeObject.text         = text;
                fadeObject.fadeType     = FadeType.FadeIn;
                fadeObjects.Add(fadeObject);

                text.color = new Color(text.color.r, text.color.g, text.color.b, 0);
                if (!text.gameObject.activeSelf)
                {
                    text.gameObject.SetActive(true);
                }
                return(fadeObject);
            }
            return(null);
        }
Exemplo n.º 6
0
        public GameOrchestrator(
            Func <RellowGame> gameFactory,
            Func <MainMenuPage> menuFactory,
            GraphicsDevice graphicsDevice,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            SoundManager soundManager,
            IWebPageOpener webPageOpener)
        {
            _gameFactory    = gameFactory ?? throw new ArgumentNullException(nameof(gameFactory));
            _menuFactory    = menuFactory ?? throw new ArgumentNullException(nameof(menuFactory));
            _webPageOpener  = webPageOpener ?? throw new ArgumentNullException(nameof(webPageOpener));
            _soundManager   = soundManager ?? throw new ArgumentNullException(nameof(soundManager));
            _graphicsDevice = graphicsDevice ?? throw new ArgumentNullException(nameof(graphicsDevice));

            _matrixScaleProvider = matrixScaleProvider ?? throw new ArgumentNullException(nameof(matrixScaleProvider));
            if (_matrixScaleProvider is DynamicScalingMatrixProvider)
            {
                (_matrixScaleProvider as DynamicScalingMatrixProvider).ScaleMatrixChanged += GameOrchestrator_ScaleMatrixChanged;
            }
            RegenerateRenderTarget();

            ShouldEndApplication = false;

            _stateTransition = new FadeObject(_fadeDuration, Color.White);
            _stateTransition.FadeOutCompleted += _stateTransition_FadeOutCompleted;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 运行淡入动画
        /// </summary>
        /// <param name="gameObject">执行对象</param>
        /// <param name="timeInSecond">执行时间</param>
        /// <param name="material">执行材质</param>
        public FadeObject AddFadeIn(GameObject gameObject, float timeInSecond, Material[] materials)
        {
            FadeObject fadeObject = FindFadeObjectByGameObject(gameObject, FadeType.FadeIn);

            if (fadeObject != null)
            {
                fadeObjects.Remove(fadeObject);
            }

            fadeObject              = new FadeObject();
            fadeObject.gameObject   = gameObject;
            fadeObject.timeInSecond = timeInSecond;
            fadeObject.alpha        = 0;
            fadeObject.materials    = materials;
            fadeObject.fadeType     = FadeType.FadeIn;
            if (materials != null && materials.Length > 0)
            {
                foreach (Material m in materials)
                {
                    m.color = new Color(m.color.r, m.color.g, m.color.b, 0);
                }
            }
            if (!gameObject.activeSelf)
            {
                gameObject.SetActive(true);
            }
            fadeObjects.Add(fadeObject);
            return(fadeObject);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 运行淡出动画
        /// </summary>
        /// <param name="gameObject">执行对象</param>
        /// <param name="timeInSecond">执行时间</param>
        /// <param name="hidden">执行完毕是否将对象设置为不激活</param>
        /// <param name="material">执行材质</param>
        public FadeObject AddFadeOut(Image image, float timeInSecond, bool hidden)
        {
            if (image != null)
            {
                FadeObject fadeObject = FindFadeObjectByImage(image, FadeType.FadeOut);
                if (fadeObject != null)
                {
                    fadeObjects.Remove(fadeObject);
                }

                fadeObject              = new FadeObject();
                fadeObject.gameObject   = image.gameObject;
                fadeObject.timeInSecond = timeInSecond;
                fadeObject.alpha        = 1;
                fadeObject.material     = null;
                fadeObject.image        = image;
                fadeObject.fadeType     = FadeType.FadeOut;
                fadeObject.endReactive  = hidden;
                fadeObjects.Add(fadeObject);

                image.color = new Color(image.color.r, image.color.g, image.color.b, 1);
                return(fadeObject);
            }
            return(null);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 运行淡入动画
        /// </summary>
        /// <param name="gameObject">执行对象</param>
        /// <param name="timeInSecond">执行时间</param>
        /// <param name="material">执行材质</param>
        public FadeObject AddFadeIn(Image image, float timeInSecond)
        {
            if (image != null)
            {
                FadeObject fadeObject = FindFadeObjectByImage(image, FadeType.FadeIn);
                if (fadeObject != null)
                {
                    fadeObjects.Remove(fadeObject);
                }

                fadeObject              = new FadeObject();
                fadeObject.gameObject   = image.gameObject;
                fadeObject.timeInSecond = timeInSecond;
                fadeObject.alpha        = 0;
                fadeObject.material     = null;
                fadeObject.image        = image;
                fadeObject.fadeType     = FadeType.FadeIn;
                fadeObjects.Add(fadeObject);

                image.color = new Color(image.color.r, image.color.g, image.color.b, 0);
                if (!image.gameObject.activeSelf)
                {
                    image.gameObject.SetActive(true);
                }
                return(fadeObject);
            }
            return(null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 运行淡入动画
        /// </summary>
        /// <param name="gameObject">执行对象</param>
        /// <param name="timeInSecond">执行时间</param>
        /// <param name="material">执行材质</param>
        public FadeObject AddFadeIn(GameObject gameObject, float timeInSecond, Material material)
        {
            FadeObject fadeObject = FindFadeObjectByGameObject(gameObject, FadeType.FadeIn);

            if (fadeObject != null)
            {
                fadeObjects.Remove(fadeObject);
            }

            fadeObject              = new FadeObject();
            fadeObject.gameObject   = gameObject;
            fadeObject.timeInSecond = timeInSecond;
            fadeObject.alpha        = 0;
            fadeObject.material     = material;
            fadeObject.fadeType     = FadeType.FadeIn;
            if (material != null)
            {
                material.color = new Color(material.color.r, material.color.g, material.color.b, 0);
            }
            if (!gameObject.activeSelf)
            {
                gameObject.SetActive(true);
            }
            fadeObjects.Add(fadeObject);
            return(fadeObject);
        }
Exemplo n.º 11
0
 private void Start()
 {
     rb           = GetComponent <Rigidbody>();
     materializer = GetComponent <Materializer>();
     player       = FindObjectOfType <Character>();
     fader        = GetComponent <FadeObject>();
     stuckSpears  = new List <Spear>();
 }
Exemplo n.º 12
0
 public void FadeAndKill()
 {
     foreach (SpriteRenderer sr in Sprites)
     {
         FadeObject fo = sr.gameObject.AddComponent <FadeObject>();
         fo.OnHide = Kill;
     }
 }
Exemplo n.º 13
0
    public void OpenLeaveGameOptions()
    {
        //leaveGameObj.SetActive(true);
        FadeObject fade = leaveGameObj.GetComponent <FadeObject>();

        if (fade != null)
        {
            fade.FadeIn();
        }
    }
Exemplo n.º 14
0
    public void CancelLeaveGame()
    {
        //leaveGameObj.SetActive(false);
        FadeObject fade = leaveGameObj.GetComponent <FadeObject>();

        if (fade != null)
        {
            fade.FadeOut();
        }
    }
Exemplo n.º 15
0
 /// <summary>
 /// setup all the orbs
 /// </summary>
 private void Awake()
 {
     for (int i = 0; i < Orbs.Length; ++i)
     {
         Orbs[i].GetComponent <Renderer>().material.color = UseLightTheme ? LightColor : DarkColor;
         Orbs[i].SetActive(false);
         FadeObject fade = Orbs[i].GetComponent <FadeObject>();
         fade.ResetFade(0);
     }
 }
Exemplo n.º 16
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Exemplo n.º 17
0
    public void Disperse()
    {
        Transform dematParticles = Instantiate(disperseParticles, transform.position, transform.rotation);

        dematParticles.SetParent(transform);

        var em = disperseParticles.GetComponent <ParticleSystem>().emission;

        em.rateOverTime = transform.localScale.magnitude * 15f;

        var sh = dematParticles.GetComponent <ParticleSystem>().shape;

        sh.shapeType = ParticleSystemShapeType.Mesh;
        if (GetComponent <MeshFilter>())
        {
            sh.mesh = GetComponent <MeshFilter>().mesh;
        }
        else if (GetComponentInChildren <MeshFilter>())
        {
            sh.mesh = GetComponentInChildren <MeshFilter>().mesh;
        }
        sh.scale = transform.localScale;

        if (GetComponent <Artifact>())
        {
            GetComponent <Artifact>().Despawn(10f);
        }
        else
        {
            Destroy(dematParticles.gameObject, 10f);
        }

        if (!GetComponent <FadeObject>())
        {
            fader = gameObject.AddComponent <FadeObject>();
        }

        if (fader != null)
        {
            fader.StartShine(shineEmission, shineInTime);

            shineDelay = KillShine();
            StartCoroutine(shineDelay);

            fadeDelay = DelayedFade();
            StartCoroutine(fadeDelay);
        }

        if (GetComponentInChildren <TrailRenderer>())
        {
            GetComponentInChildren <TrailRenderer>().emitting = false;
        }
    }
Exemplo n.º 18
0
        public void StartLoader()
        {
            for (int i = 0; i < Orbs.Length; ++i)
            {
                Orbs[i].SetActive(false);
                FadeObject fade = Orbs[i].GetComponent <FadeObject>();
                fade.ResetFade(0);
            }

            mStartingLoader   = true;
            mStartingIndex    = 0;
            mRevolutionsCount = 0;
            IsPaused          = false;
        }
        public void StartLoader()
        {
            loadingAnimation = gameObject.GetComponent <LoadingAnimation>();
            for (int i = 0; i < Orbs.Length; ++i)
            {
                Orbs[i].SetActive(false);
                FadeObject fade = Orbs[i].GetComponent <FadeObject>();
                fade.ResetFade(0);
            }

            startingLoader   = true;
            startingIndex    = 0;
            revolutionsCount = 0;
            IsPaused         = false;
        }
        /// <summary>
        /// Starts loading the assets
        /// </summary>
        public void Load()
        {
            var splashScreenTexture = _contentManager.Load <Texture2D>(_splashScreenPath);

            _splashScreenSprite = new Sprite(
                new SpriteDescription()
            {
                X      = 0,
                Y      = 0,
                Width  = splashScreenTexture.Width,
                Height = splashScreenTexture.Height,
                Name   = splashScreenTexture.Name
            },
                splashScreenTexture);
            _splashScreenFadingObject = new FadeObject(TimeSpan.FromSeconds(1), Color.White);
            _splashScreenFadingObject.FadeIn();
            _splashScreenFadingObject.FadeInCompleted  += _splashScreenFadingObject_FadeInCompleted;
            _splashScreenFadingObject.FadeOutCompleted += SplashScreen_FadeOutCompleted;
        }
Exemplo n.º 21
0
    public void fadeInGameObject(GameObject go)
    {
        FadeObject fo = go.GetComponent <FadeObject>();
        float      waitUntilStartTime;

        if (fo == null)
        {
            waitUntilStartTime = 0;
        }
        else
        {
            waitUntilStartTime = fo.waitUntilFadeTime;
        }

        float seconds = 0.05f;

        if (go.GetComponent <CanvasRenderer>() != null)
        {
            StartCoroutine(FadeInGameObject(go.GetComponent <CanvasRenderer>(), seconds, waitUntilStartTime));
        }
    }
Exemplo n.º 22
0
        /// <summary>
        /// 运行淡出动画
        /// </summary>
        /// <param name="gameObject">执行对象</param>
        /// <param name="timeInSecond">执行时间</param>
        /// <param name="hidden">执行完毕是否将对象设置为不激活</param>
        /// <param name="material">执行材质</param>
        public FadeObject AddFadeOut(GameObject gameObject, float timeInSecond, bool hidden, Material material)
        {
            FadeObject fadeObject = FindFadeObjectByGameObject(gameObject, FadeType.FadeOut);

            if (fadeObject != null)
            {
                fadeObjects.Remove(fadeObject);
            }

            fadeObject              = new FadeObject();
            fadeObject.gameObject   = gameObject;
            fadeObject.timeInSecond = timeInSecond;
            fadeObject.alpha        = 1;
            fadeObject.material     = material;
            fadeObject.fadeType     = FadeType.FadeOut;
            if (material != null)
            {
                material.color = new Color(material.color.r, material.color.g, material.color.b, 1);
            }
            fadeObject.endReactive = hidden;
            fadeObjects.Add(fadeObject);
            return(fadeObject);
        }
    private void FadeObstructions(List <GameObject> objectsInWay)
    {
        foreach (GameObject go in objectsInWay)
        {
            // If the object is already hidden
            FadeObject hiddenObject = HiddenObjects.FirstOrDefault(x => x.GameObject == go);
            if (hiddenObject == null)
            {
                // Get the object fade options
                FadeObjectOptions fadeObjectOptions = go.GetComponent <FadeObjectOptions>();

                // If the maximum fade is set to 1 then this object won't be hidden, so skip it
                if (fadeObjectOptions != null && fadeObjectOptions.OverrideFinalAlpha && fadeObjectOptions.FinalAlpha == 1)
                {
                    continue;
                }

                hiddenObject = new FadeObject {
                    GameObject = go, TransparencyLevel = 1.0f
                };

                //
                hiddenObject.Options = fadeObjectOptions;

                // Add to hidden objects
                HiddenObjects.Add(hiddenObject);
                go.AddComponent <NotifyFadeSystem>();
            }
        }

        // Unhide the objects that are not hidden anymore
        HiddenObjects.RemoveAll(x =>
        {
            float fadeOutSeconds = x.Options != null && x.Options.OverrideFadeOutSeconds ? x.Options.FadeOutSeconds : FadeOutSeconds;
            float fadeInSeconds  = x.Options != null && x.Options.OverrideFadeInSeconds ? x.Options.FadeInSeconds : FadeInSeconds;

            foreach (GameObject go in objectsInWay)
            {
                if (go == x.GameObject)
                {
                    // Change the transparency of already hidden items
                    float maximumFade = x.Options != null && x.Options.OverrideFinalAlpha ? x.Options.FinalAlpha : FinalAlpha;
                    if (x.TransparencyLevel > maximumFade)
                    {
                        x.TransparencyLevel -= Time.deltaTime * (1.0f / fadeOutSeconds);

                        if (x.TransparencyLevel <= maximumFade)
                        {
                            x.TransparencyLevel = maximumFade;
                        }

                        foreach (Material m in x.GameObject.GetComponent <Renderer>().materials)
                        {
                            m.color = new Color(m.color.r, m.color.g, m.color.b, x.TransparencyLevel);
                        }

                        // Reached the intended level of fade, disable the renderer if the alpha is 0
                        if (x.TransparencyLevel == maximumFade && x.TransparencyLevel == 0)
                        {
                            x.GameObject.GetComponent <Renderer>().enabled = false;
                        }
                    }

                    return(false);
                }
            }

            // Bring the object up to full transparency before removing it from the fade list
            if (x.TransparencyLevel < 1.0f)
            {
                // Renable the renderer if the transparency level was 0
                if (x.TransparencyLevel == 0)
                {
                    x.GameObject.GetComponent <Renderer>().enabled = true;
                }

                x.TransparencyLevel += Time.deltaTime * (1.0f / fadeInSeconds);
                if (x.TransparencyLevel > 1)
                {
                    x.TransparencyLevel = 1;
                }

                foreach (Material m in x.GameObject.GetComponent <Renderer>().materials)
                {
                    m.color = new Color(m.color.r, m.color.g, m.color.b, x.TransparencyLevel);
                }

                return(false);
            }

            // Remove the FadedObject monobehaviour
            Destroy(x.GameObject.GetComponent <NotifyFadeSystem>());

            return(true);
        });
    }
        private void Update()
        {
            if (IsPaused)
            {
                return;
            }

            float percentage = timeValue / RevolutionSpeed;

            for (int i = 0; i < Orbs.Length; ++i)
            {
                GameObject orb           = Orbs[i];
                float      orbPercentage = percentage - AngleSpace / 360 * i;
                if (orbPercentage < 0)
                {
                    orbPercentage = 1 + orbPercentage;
                }

                if (SmoothEaseInOut)
                {
                    float linearSmoothing = 1 * (orbPercentage * (1 - SmoothRatio));
                    orbPercentage = QuartEaseInOut(0, 1, orbPercentage) * SmoothRatio + linearSmoothing;
                }
                angle = 0 - (orbPercentage) * 360;

                if (startingLoader)
                {
                    if (orbPercentage >= 0 && orbPercentage < 0.5f)
                    {
                        if (i == startingIndex)
                        {
                            orb.SetActive(true);
                            if (i >= Orbs.Length - 1)
                            {
                                startingLoader = false;
                            }
                            startingIndex += 1;
                        }
                    }
                }

                orb.transform.Rotate(Axis, angle);
                rotatedPositionVector       = Quaternion.AngleAxis(angle, Axis) * positionVector * Radius;
                orb.transform.localPosition = CenterPoint + rotatedPositionVector;

                if (checkLoopPause != loopPause)
                {
                    if (loopPause && orbPercentage > 0.25f)
                    {
                        if (i == fadeIndex)
                        {
                            FadeObject fade = orb.GetComponent <FadeObject>();
                            fade.FadeOut(false);
                            if (i >= Orbs.Length - 1)
                            {
                                checkLoopPause = loopPause;
                            }
                            fadeIndex += 1;
                        }
                    }

                    if (!loopPause && orbPercentage > 0.5f)
                    {
                        if (i == fadeIndex)
                        {
                            FadeObject fade = orb.GetComponent <FadeObject>();
                            fade.FadeIn(false);
                            if (i >= Orbs.Length - 1)
                            {
                                checkLoopPause = loopPause;
                            }
                            fadeIndex += 1;
                        }
                    }
                }
            }

            timeValue += Time.deltaTime;
            if (!loopPause)
            {
                if (timeValue >= RevolutionSpeed)
                {
                    timeValue = timeValue - RevolutionSpeed;

                    revolutionsCount += 1;

                    if (revolutionsCount >= Revolutions && Revolutions > 0)
                    {
                        loopPause        = true;
                        fadeIndex        = 0;
                        revolutionsCount = 0;
                        loadingAnimation.gameObject.SetActive(false);
                    }
                }
            }
            else
            {
                if (timeValue >= RevolutionSpeed)
                {
                    timeValue         = 0;
                    revolutionsCount += 1;
                    if (revolutionsCount >= Revolutions * 0.25f)
                    {
                        fadeIndex        = 0;
                        loopPause        = false;
                        revolutionsCount = 0;
                    }
                }
            }
        }
Exemplo n.º 25
0
 void Awake()
 {
     fadeController = GetComponent <FadeObject>();
 }
Exemplo n.º 26
0
        public GameOverPage(
            IScreenTransformationMatrixProvider matrixScaleProvider,
            AssetsLoader assets,
            ISettingsRepository settingsRepository,
            int thisGameNumberOfVegetablesEaten,
            int thisGameNumberOfMeters,
            int thisGameNumberOfFarts,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _font                = assets.Font;
            _background          = assets.OtherSprites["gameoverBackground"];
            _matrixScaleProvider = matrixScaleProvider;

            _gameOverTextDrawingInfos = new DrawingInfos()
            {
                Position = new Vector2()
                {
                    X = matrixScaleProvider.VirtualWidth / 2f, Y = 100f
                },
                Origin = _font.GetTextCenter(_gameOverText)
            };
            _gameOverScalingObject = new ScalingObject(1f, 1.2f, 1.0f);

            var bestFarts           = settingsRepository.GetOrSetInt(GameScores.BestFartsScoreKey, default(int));
            var bestNumberOfMeters  = settingsRepository.GetOrSetInt(GameScores.BestNumberOfMetersScoreKey, default(int));
            var bestVegetablesEaten = settingsRepository.GetOrSetInt(GameScores.BestVegetablesEatenScoreKey, default(int));

            var bestNumberOfVegetablesEatenRecord = false;

            if (thisGameNumberOfVegetablesEaten > bestVegetablesEaten)
            {
                settingsRepository.SetInt(GameScores.BestVegetablesEatenScoreKey, thisGameNumberOfVegetablesEaten);
                bestNumberOfVegetablesEatenRecord = true;
            }

            var bestAliveTimeRecord = false;

            if (thisGameNumberOfMeters > bestNumberOfMeters)
            {
                settingsRepository.SetInt(GameScores.BestNumberOfMetersScoreKey, thisGameNumberOfMeters);
                bestAliveTimeRecord = true;
            }

            var bestNumberOfFartsRecord = false;

            if (thisGameNumberOfFarts > bestFarts)
            {
                settingsRepository.SetInt(GameScores.BestFartsScoreKey, thisGameNumberOfFarts);
                bestNumberOfFartsRecord = true;
            }

            const float textsScale = 0.4f;

            _scoreInfos = new List <ScoreRecordText>()
            {
                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumberOfMetersString)}{thisGameNumberOfMeters}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 200f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestAliveTimeRecord ? "       " : "Record!"),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumbersOfFartsString)}{thisGameNumberOfFarts}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 125f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestNumberOfFartsRecord ? "       " : "Record!"),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumberOfVegetablesEaten)}{thisGameNumberOfVegetablesEaten}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 162f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestNumberOfVegetablesEatenRecord ? "       " : "Record!"),
            };

            _nTexts        = _scoreInfos.Count;
            _currentTextId = 0;
            _fadeObject    = new FadeObject(TimeSpan.FromMilliseconds(200), Color.White);
            _fadeObject.FadeInCompleted += _textFadeObject_FadeInCompleted;
            _fadeObject.FadeIn();
        }
Exemplo n.º 27
0
        /// <summary>
        /// Animate the loader
        /// </summary>
        void Update()
        {
            if (IsPaused)
            {
                return;
            }

            float percentage = mTime / RevolutionSpeed;

            for (int i = 0; i < Orbs.Length; ++i)
            {
                GameObject orb = Orbs[i];

                // get the revolution completion percentage
                float orbPercentage = percentage - AngleSpace / 360 * i;
                if (orbPercentage < 0)
                {
                    orbPercentage = 1 + orbPercentage;
                }

                if (SmoothEaseInOut)
                {
                    float linearSmoothing = 1 * (orbPercentage * (1 - SmoothRatio));
                    orbPercentage = QuartEaseInOut(0, 1, orbPercentage) * SmoothRatio + linearSmoothing;
                }

                // set the angle
                mAngle = 0 - (orbPercentage) * 360;

                if (mStartingLoader)
                {
                    if (orbPercentage >= 0 && orbPercentage < 0.5f)
                    {
                        if (i == mStartingIndex)
                        {
                            orb.SetActive(true);
                            if (i >= Orbs.Length - 1)
                            {
                                mStartingLoader = false;
                            }
                            mStartingIndex += 1;
                        }
                    }
                }

                // apply the values
                orb.transform.Rotate(Axis, mAngle);
                mRotatedPositionVector      = Quaternion.AngleAxis(mAngle, Axis) * mPositionVector * Radius;
                orb.transform.localPosition = CenterPoint + mRotatedPositionVector;

                // check for looping and handle loop counts
                if (mCheckLoopPause != mLoopPause)
                {
                    if (mLoopPause && orbPercentage > 0.25f)
                    {
                        if (i == mFadeIndex)
                        {
                            FadeObject fade = orb.GetComponent <FadeObject>();
                            fade.FadeOut(false);
                            if (i >= Orbs.Length - 1)
                            {
                                mCheckLoopPause = mLoopPause;
                            }
                            mFadeIndex += 1;
                        }
                    }

                    if (!mLoopPause && orbPercentage > 0.5f)
                    {
                        if (i == mFadeIndex)
                        {
                            FadeObject fade = orb.GetComponent <FadeObject>();
                            fade.FadeIn(false);
                            if (i >= Orbs.Length - 1)
                            {
                                mCheckLoopPause = mLoopPause;
                            }
                            mFadeIndex += 1;
                        }
                    }
                }
            }

            mTime += Time.deltaTime;
            if (!mLoopPause)
            {
                if (mTime >= RevolutionSpeed)
                {
                    mTime = mTime - RevolutionSpeed;

                    mRevolutionsCount += 1;

                    if (mRevolutionsCount >= Revolutions && Revolutions > 0)
                    {
                        mLoopPause        = true;
                        mFadeIndex        = 0;
                        mRevolutionsCount = 0;
                        StopLoader();
                    }
                }
            }
            else
            {
                if (mTime >= RevolutionSpeed)
                {
                    mTime              = 0;
                    mRevolutionsCount += 1;
                    if (mRevolutionsCount >= Revolutions * 0.25f)
                    {
                        mFadeIndex        = 0;
                        mLoopPause        = false;
                        mRevolutionsCount = 0;
                    }
                }
            }
        }
Exemplo n.º 28
0
 private void Update()
 {
     if (fadeObjects.Count > 0)
     {
         FadeObject fadeObject = null;
         for (int i = fadeObjects.Count - 1; i >= 0; i--)
         {
             fadeObject = fadeObjects[i];
             if (fadeObject.runEnd)
             {
                 fadeObjects.Remove(fadeObject);
             }
             else
             {
                 if (fadeObject.fadeType == FadeType.FadeIn)
                 {
                     if (fadeObject.alpha < 1)
                     {
                         fadeObject.alpha += Time.deltaTime / fadeObject.timeInSecond * 1;
                         if (fadeObject.material != null)
                         {
                             fadeObject.material.color = new Color(fadeObject.material.color.r, fadeObject.material.color.g, fadeObject.material.color.b, fadeObject.alpha);
                         }
                         else if (fadeObject.materials != null && fadeObject.materials.Length > 0)
                         {
                             foreach (Material m in fadeObject.materials)
                             {
                                 m.color = new Color(m.color.r, m.color.g, m.color.b, fadeObject.alpha);
                             }
                         }
                         else if (fadeObject.image != null)
                         {
                             fadeObject.image.color = new Color(fadeObject.image.color.r, fadeObject.image.color.g, fadeObject.image.color.b, fadeObject.alpha);
                         }
                         else if (fadeObject.text != null)
                         {
                             fadeObject.text.color = new Color(fadeObject.text.color.r, fadeObject.text.color.g, fadeObject.text.color.b, fadeObject.alpha);
                         }
                     }
                     else
                     {
                         fadeObject.runEnd = true;
                     }
                 }
                 else if (fadeObject.fadeType == FadeType.FadeOut)
                 {
                     if (fadeObject.alpha > 0)
                     {
                         fadeObject.alpha -= Time.deltaTime / fadeObject.timeInSecond * 1;
                         if (fadeObject.material != null)
                         {
                             fadeObject.material.color = new Color(fadeObject.material.color.r, fadeObject.material.color.g, fadeObject.material.color.b, fadeObject.alpha);
                         }
                         else if (fadeObject.materials != null && fadeObject.materials.Length > 0)
                         {
                             foreach (Material m in fadeObject.materials)
                             {
                                 m.color = new Color(m.color.r, m.color.g, m.color.b, fadeObject.alpha);
                             }
                         }
                         else if (fadeObject.image != null)
                         {
                             fadeObject.image.color = new Color(fadeObject.image.color.r, fadeObject.image.color.g, fadeObject.image.color.b, fadeObject.alpha);
                         }
                         else if (fadeObject.text != null)
                         {
                             fadeObject.text.color = new Color(fadeObject.text.color.r, fadeObject.text.color.g, fadeObject.text.color.b, fadeObject.alpha);
                         }
                     }
                     else
                     {
                         if (fadeObject.endReactive)
                         {
                             if (fadeObject.gameObject != null)
                             {
                                 fadeObject.gameObject.SetActive(false);
                             }
                         }
                         fadeObject.runEnd = true;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 29
0
    private IEnumerator SetupAnswers(float fadeDuration, QuestionContainer question, AnimationCurve usedCurve)
    {
        float             time              = 0f;
        bool              halfReached       = false;
        bool              onSecondHalfenter = true;
        float             value             = 0f;
        FadeObject        answerSliderFade  = answerSlider.GetComponent <FadeObject>();
        List <FadeObject> answerFade        = new List <FadeObject>();

        foreach (var button in answerButtons)
        {
            answerFade.Add(button.GetComponent <FadeObject>());
        }

        while (time < fadeDuration)
        {
            time += Time.deltaTime;
            value = usedCurve.Evaluate(time / fadeDuration);
            //Switch on Halftime
            if (!halfReached && time > fadeDuration / 2f)
            {
                halfReached = true;
            }

            //First Half
            if (!halfReached)
            {
                //Slider
                if (answerSlider.activeSelf)
                {
                    answerSliderFade.SetOpacity(value);
                }
                else
                {
                    foreach (var answer in answerFade)
                    {
                        answer.SetOpacity(value);
                    }
                }
            }
            //Second Half
            else
            {
                //End First Half Deactivation
                if (onSecondHalfenter)
                {
                    //Remove old Buttons
                    foreach (var item in answerButtons)
                    {
                        Destroy(item);
                    }
                    answerButtons.Clear();
                    answerFade.Clear();

                    //Check for Sliders
                    if (answerSlider.activeSelf && !question.hasSlider)
                    {
                        answerSliderFade.SetOpacity(0);
                        answerSlider.SetActive(false);
                    }

                    //Add New Buttons
                    Transform selectedRow;

                    int count = question.answers.Length;
                    for (int i = 0; i < count; i++)
                    {
                        selectedRow = GetRow(question.answers.Length, i);

                        var button = Instantiate(answerButtonPrefab, selectedRow);
                        int index  = i;
                        button.GetComponent <Button>().onClick.AddListener(delegate { OnAnswerClicked(index); });
                        button.GetComponentInChildren <Text>().text = question.answers[i].answer;
                        button.GetComponent <ButtonHighlighter>().Init();
                        button.GetComponent <ButtonHighlighter>().SelectButton(false);
                        button.GetComponent <FadeObject>().Init();
                        button.GetComponent <FadeObject>().SetOpacity(0f);
                        answerFade.Add(button.GetComponent <FadeObject>());
                        answerButtons.Add(button);
                    }
                    onSecondHalfenter = false;
                }

                //Slider
                if (question.hasSlider)
                {
                    if (!answerSlider.activeSelf)
                    {
                        answerSlider.SetActive(true);
                    }
                    answerSliderFade.SetOpacity(value);
                }

                //Multi Choice
                else
                {
                    foreach (var answer in answerFade)
                    {
                        answer.SetOpacity(value);
                    }
                }
            }
            yield return(null);
        }
    }