Esempio n. 1
0
    /// <summary>
    /// Removes a specific instance of a StasisBubble within the list of stasisBubble
    /// </summary>
    /// <returns><c>true</c>, if stasis bubble was removed, <c>false</c> otherwise.</returns>
    public static bool removeStasisBubble(StasisBubble bubble)
    {
        // Error cases:
        // No stasis bubbles in play, bubble is null, or the list does not contain the instance of bubble
        if (!canRemoveStasisBubble() || bubble == null || !stasisBubbles.Contains(bubble))
        {
            // Remove stasis event (failure)
            if (inst.stasisRemoved != null)
            {
                inst.stasisRemoved(false);
            }

            return(false);
        }

        // Update stasis bubble indexes for bubbles after the one being removed
        bool foundBubble = false;

        for (int i = 0; i < stasisBubbles.Count; i++)
        {
            if (stasisBubbles[i] == null)
            {
                continue;
            }
            if (stasisBubbles[i] == bubble)
            {
                foundBubble = true;
                continue;
            }

            if (foundBubble)
            {
                stasisBubbles[i].stasisIndex--;
            }
        }

        // Decrement numStasis
        inst.m_numStasis -= 1;

        if (inst.stasisUIRemoveParticles != null)
        {
            inst.stasisUIRemoveParticles[inst.m_numStasis].Play();
        }

        // Remove the bubble from the LevelStateManager's List
        stasisBubbles.Remove(bubble);

        // Call the bubble's custom destroy function
        bubble.DestroyBubble();

        // Remove stasis event (success)
        if (inst.stasisRemoved != null)
        {
            inst.stasisRemoved(true);
        }

        return(true);
    }