Пример #1
0
        public IEnumerator TestRemoveImmediate()
        {
            var cacher = new DummyCacher();
            var agent  = new CacherAgent <string, DummyCacherData>(cacher);

            Assert.AreEqual(cacher, agent.Cacher);

            agent.UseDelayedRemove = false;
            agent.RemoveDelay      = 0f;
            Assert.IsNull(agent.Listener);
            Assert.IsFalse(cacher.IsCached("A"));

            agent.Request("A");
            Assert.IsFalse(cacher.IsCached("A"));
            Assert.IsNull(agent.Listener.Value);
            yield return(new WaitForSecondsRealtime(1.5f));

            var value = agent.Listener.Value;

            Assert.IsTrue(cacher.IsCached("A"));
            Assert.IsNotNull(value);
            Assert.IsFalse(value.IsDestroyed);

            agent.Remove();
            Assert.IsFalse(cacher.IsCached("A"));
            Assert.IsNull(agent.Listener);
            Assert.IsTrue(value.IsDestroyed);
        }
Пример #2
0
 /// <summary>
 /// Loads the background asset for current map.
 /// </summary>
 private void LoadBackground()
 {
     if (bindableMap.Value != null)
     {
         backgroundAgent.Request(bindableMap.Value);
     }
 }
Пример #3
0
 /// <summary>
 /// Loads the music asset for current map.
 /// </summary>
 private void LoadMusic()
 {
     if (bindableMap.Value != null)
     {
         musicAgent.Request(bindableMap.Value);
     }
 }
Пример #4
0
        /// <summary>
        /// Makes the specified mapset the previewing mapset.
        /// </summary>
        public void SetPreview(OnlineMapset mapset)
        {
            bool isPreviewing = mapset == previewingMapset.Value;

            ResetPreviewingMapset();

            if (!isPreviewing && mapset != null && !string.IsNullOrEmpty(mapset.PreviewAudio))
            {
                previewingMapset.Value = mapset;
                musicAgent.Request(mapset.PreviewAudio);
            }
        }
Пример #5
0
        protected override void Update()
        {
            base.Update();

            // Load background.
            if (isBackgroundWait)
            {
                bgWaitTime -= Time.deltaTime;
                if (bgWaitTime <= 0f)
                {
                    bgWaitTime       = BackgroundLoadWait;
                    isBackgroundWait = false;

                    if (Mapset != null)
                    {
                        backgroundAgent.Request(Mapset.Maps[0]);
                    }
                }
            }

            if (!isAnimating)
            {
                return;
            }

            // Advance
            aniTime += Time.deltaTime * AnimationSpeed;

            // Stop animation.
            if (aniTime >= 1f)
            {
                aniTime     = 1f;
                isAnimating = false;
            }

            // Determine target transition values.
            var background = backgroundAgent.Listener?.Value;

            float highlightAlpha, containerWidth;
            Color glowColor, thumbColor;

            if (!isFocused)
            {
                highlightAlpha = UnfocusedHighlightAlpha;
                containerWidth = UnfocusedWidth;
                glowColor      = UnfocusedGlowColor;
                thumbColor     = UnfocusedThumbColor;
            }
            else
            {
                highlightAlpha = FocusedHighlightAlpha;
                containerWidth = FocusedWidth;
                glowColor      = background != null ? background.Highlight : DefaultGlowColor;
                glowColor.a    = FocusedGlowAlpha;
                thumbColor     = FocusedThumbColor;
            }
            thumbColor.a = thumbImage.Texture == null ? 0f : 1f;

            // Toggle shadow
            titleShadow.enabled   = isFocused;
            artistShadow.enabled  = isFocused;
            creatorShadow.enabled = isFocused;

            // Animate components.
            highlight.Alpha  = Mathf.Lerp(highlight.Alpha, highlightAlpha, aniTime);
            container.Width  = Mathf.Lerp(container.Width, containerWidth, aniTime);
            glow.Color       = Color.Lerp(glow.Color, glowColor, aniTime);
            thumbImage.Color = Color.Lerp(thumbImage.Color, thumbColor, aniTime);

            // Keep position at 0.
            // TODO: This seems more of a hack. This should be handled in a better way in future.
            X = 0f;
        }
Пример #6
0
        public IEnumerator TestRequest()
        {
            var cacher = new DummyCacher();
            var agent  = new CacherAgent <string, DummyCacherData>(cacher);

            Assert.AreEqual(cacher, agent.Cacher);

            agent.UseDelayedRemove = false;
            agent.RemoveDelay      = 0f;

            Assert.IsNull(agent.Listener);
            Assert.IsFalse(cacher.IsCached("A"));

            // Request data A.
            agent.Request("A");
            Assert.IsFalse(cacher.IsCached("A"));
            Assert.IsNotNull(agent.Listener);

            float limit = 2f;

            while (!cacher.IsCached("A"))
            {
                Debug.Log("Progress: " + agent.Listener.Progress);
                limit -= Time.deltaTime;
                if (limit <= 0)
                {
                    Assert.Fail("Request should've finished by now!");
                }
                yield return(null);
            }
            Assert.IsTrue(cacher.IsCached("A"));
            Assert.AreEqual(1f, agent.Listener.Progress);
            Assert.IsNotNull(agent.Listener.Value);
            Assert.AreEqual("A", agent.Listener.Key);
            Assert.AreEqual("A", agent.Listener.Value.Key);
            Assert.IsFalse(agent.Listener.Value.IsDestroyed);

            // Request data B.
            agent.Request("B");
            Assert.IsFalse(cacher.IsCached("B"));
            Assert.AreEqual(0f, agent.Listener.Progress);
            Assert.AreEqual("B", agent.Listener.Key);
            Assert.IsNull(agent.Listener.Value);

            limit = 2f;
            while (!cacher.IsCached("B"))
            {
                Debug.Log("Progress: " + agent.Listener.Progress);
                limit -= Time.deltaTime;
                if (limit <= 0)
                {
                    Assert.Fail("Request should've finished by now!");
                }
                yield return(null);
            }
            Assert.IsTrue(cacher.IsCached("B"));
            Assert.AreEqual(1f, agent.Listener.Progress);
            Assert.IsNotNull(agent.Listener.Value);
            Assert.AreEqual("B", agent.Listener.Key);
            Assert.AreEqual("B", agent.Listener.Value.Key);
            Assert.IsFalse(agent.Listener.Value.IsDestroyed);
        }