Exemple #1
0
    /// <summary> Recycles or creates a falling ring as specified </summary>
    /// <param name="_pos"> Starting position </param>
    /// <param name="_scale"> Scale </param>
    /// <param name="_color"> Colour </param>
    public void SpawnFallingRing(Vector3 _pos, float _scale, Color _color)
    {
        GameObject  gameObj     = RecyclePool.RetrieveOrCreate(RecyclePool.PoolTypes.FallingRing, fallingRingPrefab);
        FallingRing fallingRing = gameObj.GetComponent <FallingRing>();

        fallingRing.Init(_pos, _scale, _color);
        fallingRings.Add(fallingRing);
    }
        [TestProperty("Ignore", "True")] // TODO 19581880: Re-enable after investigating and fixing the test failures.
#endif
        public void ValidateDataTemplateSelectorAsItemTemplate()
        {
            RunOnUIThread.Execute(() =>
            {
                var dataTemplateOdd = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
                            <TextBlock Text='{Binding}' Height='30' />
                        </DataTemplate>");
                var dataTemplateEven = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
                            <TextBlock Text='{Binding}' Height='40' />
                        </DataTemplate>");
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var selector           = new MySelector()
                {
                    TemplateOdd  = dataTemplateOdd,
                    TemplateEven = dataTemplateEven
                };

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    elementFactory: selector,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                Content.UpdateLayout();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                    Verify.AreEqual(i % 2 == 0 ? 40 : 30, element.Height);
                }

                repeater.ItemsSource = null;
                Content.UpdateLayout();

                // All the created items should be in the recycle pool now.
                var oddPool     = RecyclePool.GetPoolInstance(dataTemplateOdd);
                var oddElements = GetAllElementsFromPool(oddPool);
                Verify.AreEqual(5, oddElements.Count);
                foreach (var element in oddElements)
                {
                    Verify.AreEqual(30, ((TextBlock)element).Height);
                }

                var evenPool     = RecyclePool.GetPoolInstance(dataTemplateEven);
                var evenElements = GetAllElementsFromPool(evenPool);
                Verify.AreEqual(5, evenElements.Count);
                foreach (var element in evenElements)
                {
                    Verify.AreEqual(40, ((TextBlock)element).Height);
                }
            });
        }
 /// <summary> Called once per frame </summary>
 void Update()
 {
     color.a -= Time.deltaTime / fadeTime;
     if (color.a <= 0.0f)
     {
         RecyclePool.Recycle(RecyclePool.PoolTypes.BlockDisappear, gameObject);
     }
     else
     {
         material.color = color;
     }
 }
Exemple #4
0
    /// <summary> Destroys all towers and resets game state </summary>
    public void QuitGame()
    {
        for (int i = 0; i < players.Length; ++i)
        {
            players[i].Destroy();
        }

        players = null;
        Environment.instance.ClearAllEffects();
        RecyclePool.ClearAllPools();

        SetGameState(GameStates.Menu);
    }
Exemple #5
0
    /// <summary> Recycles all spawned items </summary>
    public void ClearAllEffects()
    {
        for (int i = 0; i < fallingRings.Count; ++i)
        {
            RecyclePool.Recycle(RecyclePool.PoolTypes.FallingRing, fallingRings[i].gameObject);
        }
        fallingRings.Clear();

        for (int i = 0; i < shockwaves.Count; ++i)
        {
            RecyclePool.Recycle(RecyclePool.PoolTypes.Shockwave, shockwaves[i].gameObject);
        }
        shockwaves.Clear();
    }
Exemple #6
0
    /// <summary> Creates (or reuses) a shockwave GameObject </summary>
    /// <param name="_position"> Centre position </param>
    /// <param name="_color"> Ripple's colour </param>
    public void StartRipple(Vector3 _position, Color _color)
    {
        GameObject gameObj = RecyclePool.RetrieveOrCreate(RecyclePool.PoolTypes.Shockwave, shockwavePrefab);

        // Set position & rotation
        gameObj.transform.parent     = myTrans;
        gameObj.transform.position   = _position;
        gameObj.transform.localScale = Vector3.zero;

        // (Re)start popup animation
        Shockwave shockwaveScript = gameObj.GetComponent <Shockwave>();

        shockwaveScript.Init(_color);

        shockwaves.Add(shockwaveScript);
    }
    /// <summary> Creates (or reuses) a disappearing block GameObject </summary>
    /// <param name="_block"> Block from which to create </param>
    public static void StartDisappearing(Block _block, GameObject _disappearPrefab)
    {
        GameObject gameObj = RecyclePool.RetrieveOrCreate(RecyclePool.PoolTypes.BlockDisappear, _disappearPrefab);

        // Match pos/rot/scale of original block
        Transform trans      = gameObj.transform;
        Transform blockTrans = _block.trans;

        trans.parent        = blockTrans.parent;
        trans.localPosition = blockTrans.localPosition;
        trans.localRotation = blockTrans.localRotation;
        trans.localScale    = blockTrans.localScale;

        // (Re)start the disappear anim
        gameObj.GetComponent <BlockDisappear>().ResetAnim();
    }
Exemple #8
0
            public void Reset()
            {
                foreach (var kv in _components)
                {
                    var entry = kv.Value.Entry;
                    while (entry != null)
                    {
                        var current = entry;
                        entry = entry.Next;

                        ComponentPool.Recycle(current);
                    }
                }

                _components.Clear();
                ComponentPool = null;
            }
        private List <UIElement> GetAllElementsFromPool(RecyclePool pool, string key = "")
        {
            List <UIElement> elements  = new List <UIElement>();
            bool             poolEmpty = false;

            while (!poolEmpty)
            {
                var next = pool.TryGetElement(key);
                if (next != null)
                {
                    elements.Add(next);
                }

                poolEmpty = next == null;
            }

            return(elements);
        }
        public void ValidateDataTemplateAsItemTemplate()
        {
            RunOnUIThread.Execute(() =>
            {
                var dataTemplate = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' />
						</DataTemplate>"                        );
                ItemsRepeater repeater = null;
                const int numItems     = 10;

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems).Select(i => i.ToString()),
                    elementFactory: dataTemplate,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                Content.UpdateLayout();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                }

                repeater.ItemsSource = null;
                Content.UpdateLayout();

                // In versions below RS5 we faked the recycling behaivor on data template
                // so we can get to the recycle pool that we addded internally in ItemsRepeater.
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                {
                    // All the created items should be in the recycle pool now.
                    var pool             = RecyclePool.GetPoolInstance(dataTemplate);
                    var recycledElements = GetAllElementsFromPool(pool);
                    Verify.AreEqual(10, recycledElements.Count);
                }
            });
        }
        [TestProperty("Ignore", "True")] // TODO 19581880: Re-enable after investigating and fixing the test failures.
#endif
        public void ValidateDataTemplateAsItemTemplate()
        {
            RunOnUIThread.Execute(() =>
            {
                var dataTemplate = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
                            <TextBlock Text='{Binding}' />
                        </DataTemplate>");
                ItemsRepeater repeater = null;
                const int numItems     = 10;

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems).Select(i => string.Format("{0}", i)),
                    elementFactory: dataTemplate,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                Content.UpdateLayout();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                }

                repeater.ItemsSource = null;
                Content.UpdateLayout();

                // All the created items should be in the recycle pool now.
                var pool             = RecyclePool.GetPoolInstance(dataTemplate);
                var recycledElements = GetAllElementsFromPool(pool);
                Verify.AreEqual(10, recycledElements.Count);
            });
        }
Exemple #12
0
 /// <summary> Called from a shockwave when it finishes growing + fading </summary>
 /// <param name="_shockwave"> Shockwave that just finished </param>
 public void ShockwaveFinished(Shockwave _shockwave)
 {
     RecyclePool.Recycle(RecyclePool.PoolTypes.Shockwave, _shockwave.gameObject);
     shockwaves.Remove(_shockwave);
 }
Exemple #13
0
 /// <summary> Called from the ring when it hits the ground </summary>
 /// <param name="_ring"> Ring that just finished falling </param>
 public void RingFinishedFalling(FallingRing _ring)
 {
     RecyclePool.Recycle(RecyclePool.PoolTypes.FallingRing, _ring.gameObject);
     fallingRings.Remove(_ring);
 }
Exemple #14
0
        public async Task ValidateDataTemplateSelectorAsItemTemplate()
        {
            await RunOnUIThread.ExecuteAsync(async() =>
            {
                var dataTemplateOdd = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='30' />
						</DataTemplate>"                        );
                var dataTemplateEven = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='40' />
						</DataTemplate>"                        );
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var selector           = new MySelector()
                {
                    TemplateOdd  = dataTemplateOdd,
                    TemplateEven = dataTemplateEven
                };

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    elementFactory: selector,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                await UpdateLayoutWithWaitAsync();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                    Verify.AreEqual(i % 2 == 0 ? 40 : 30, element.Height);
                }

                repeater.ItemsSource = null;
                await UpdateLayoutWithWaitAsync();

                // In versions below RS5 we faked the recycling behaivor on data template
                // so we can get to the recycle pool that we addded internally in ItemsRepeater.
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                {
                    // All the created items should be in the recycle pool now.
                    var oddPool     = RecyclePool.GetPoolInstance(dataTemplateOdd);
                    var oddElements = GetAllElementsFromPool(oddPool);
                    Verify.AreEqual(5, oddElements.Count);
                    foreach (var element in oddElements)
                    {
                        Verify.AreEqual(30, ((TextBlock)element).Height);
                    }

                    var evenPool     = RecyclePool.GetPoolInstance(dataTemplateEven);
                    var evenElements = GetAllElementsFromPool(evenPool);
                    Verify.AreEqual(5, evenElements.Count);
                    foreach (var element in evenElements)
                    {
                        Verify.AreEqual(40, ((TextBlock)element).Height);
                    }
                }
            });
        }