Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

unity3d - Traversing a game reel matrix column by column from left to right

I have a 3x5 matrix that acts as a game reel. First, I search through the game symbols that I am interested in (let's call them wild clones) and then I search through their children (to locate the game object that has the animation) and then I activate those animations.

private IEnumerator EnableWilds(float delayBetweenWildsAppear)
{            
    WildSymbol[] wilds = FindObjectsOfType<WildSymbol>();
    GameObject[] symbols = new GameObject[wilds.Length];
    for (int i = 0; i < wilds.Length; i++)
    {
        symbols[i] = wilds[i].gameObject;
    }

    for (int i = 0; i < symbols.Length; i++)
    {
        if ( symbols[i].name.Contains("(Clone)") )
        {
            int reelIndex   = symbols[i].GetComponentInParent<GameReel>().ReelIndex;
            int indexOnReel = symbols[i].GetComponent<WildSymbol>().IndexOnReel;

            // ??

            for (int j = 0; j < symbols[i].transform.childCount; j++)
            {
                if ( symbols[i].transform.GetChild(j).gameObject.name.Contains("MM_wild") )
                {
                    symbols[i].transform.GetChild(j).gameObject.SetActive(true);
                    yield return new WaitForSeconds(delayBetweenWildsAppear);
                }
            }
        }                
    }
}

I started thinking about how I can activate those wilds starting from the top left corner, and coming down the reel and moving on to the next reel and animating the wilds from top to bottom, etc...

So, I realized I need to get each symbol's reel index (i.e. column number) and index on reel (i.e. position on the reel) so I go Reel1 and then wild clone 1 and 2 and 3, and then Reel2 followed by wild clone 1 and 2 and 3, and so on...

I am trying to do this where I have put a // ?? but at this point, I am a bit lost, conceptually. I cannot figure out how to perform tghis traversal.

Could someone please help me with this?

My game reel 1

My game reel 2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is how I solved it myself, and then simplified it:

private IEnumerator DisableWilds(float delayBetweenWildsDisappear)
{            
    WildSymbol[] wilds = FindObjectsOfType<WildSymbol>();

    wilds = wilds.Where( (item, index) => item.name.Contains("(Clone)")      )
                 .OrderBy( x => x.GetComponent<WildSymbol>().IndexOnReel     )
                 .OrderBy( x => x.GetComponentInParent<GameReel>().ReelIndex )
                 .ToArray();

    for (int i = 0; i < wilds.Length; i++)
    {
        for (int j = 0; j < wilds[i].transform.childCount; j++)
        {
            if (wilds[i].transform.GetChild(j).gameObject.name.Contains("MM_wild"))
            {
                wilds[i].transform.GetChild(j).gameObject.SetActive(false);

                yield return new WaitForSeconds(delayBetweenWildsDisappear);
            }
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...