当前位置: 首页>>代码示例>>C#>>正文


C# Shape.Assign方法代码示例

本文整理汇总了C#中Shape.Assign方法的典型用法代码示例。如果您正苦于以下问题:C# Shape.Assign方法的具体用法?C# Shape.Assign怎么用?C# Shape.Assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shape的用法示例。


在下文中一共展示了Shape.Assign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindMatchesAndCollapse

    private IEnumerator FindMatchesAndCollapse(RaycastHit2D hit2)
    {
        //get the second item that was part of the swipe
        var hitGo2 = hit2.collider.gameObject;
        shapes.Swap(hitGo, hitGo2);

        //move the swapped ones
        hitGo.transform.positionTo(Constants.AnimationDuration, hitGo2.transform.position);
        hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
        yield return new WaitForSeconds(Constants.AnimationDuration);

        //get the matches via the helper methods
        var hitGomatchesInfo = shapes.GetMatches(hitGo);
        var hitGo2matchesInfo = shapes.GetMatches(hitGo2);

        var totalMatches = hitGomatchesInfo.MatchedCandy
            .Union(hitGo2matchesInfo.MatchedCandy).Distinct();

        //if user's swap didn't create at least a 3-match, undo their swap
        if (totalMatches.Count() < Constants.MinimumMatches)
        {
            hitGo.transform.positionTo(Constants.AnimationDuration, hitGo2.transform.position);
            hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
            yield return new WaitForSeconds(Constants.AnimationDuration);

            shapes.UndoSwap();
        }

        //if more than 3 matches and no Bonus is contained in the line, we will award a new Bonus
        bool addBonus = totalMatches.Count() >= Constants.MinimumMatchesForBonus &&
            !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGomatchesInfo.BonusesContained) &&
            !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGo2matchesInfo.BonusesContained);

        Shape hitGoCache = null;
        if (addBonus)
        {
            hitGoCache = new Shape();
            //get the game object that was of the same type
            var sameTypeGo = hitGomatchesInfo.MatchedCandy.Count() > 0 ? hitGo : hitGo2;
            var shape = sameTypeGo.GetComponent<Shape>();
            //cache it
            hitGoCache.Assign(shape.Type, shape.Row, shape.Column);
        }
        int timesRun = 1;
        while (totalMatches.Count() >= Constants.MinimumMatches)
        {
            //increase score
            IncreaseScore((totalMatches.Count() - 2) * Constants.Match3Score);

            if (timesRun >= 2)
                IncreaseScore(Constants.SubsequentMatchScore);

            soundManager.PlayCrincle();

            foreach (var item in totalMatches)
            {
                shapes.Remove(item);
                RemoveFromScene(item);
            }

            //check and instantiate Bonus if needed
            if (addBonus)
                CreateBonus(hitGoCache);

            addBonus = false;

            //get the columns that we had a collapse
            var columns = totalMatches.Select(go => go.GetComponent<Shape>().Column).Distinct();

            //the order the 2 methods below get called is important!!!
            //collapse the ones gone
            var collapsedCandyInfo = shapes.Collapse(columns);
            //create new ones
            var newCandyInfo = CreateNewCandyInSpecificColumns(columns);

            int maxDistance = Mathf.Max(collapsedCandyInfo.MaxDistance, newCandyInfo.MaxDistance);

            MoveAndAnimate(newCandyInfo.AlteredCandy, maxDistance);
            MoveAndAnimate(collapsedCandyInfo.AlteredCandy, maxDistance);



            //will wait for both of the above animations
            yield return new WaitForSeconds(Constants.MoveAnimationMinDuration * maxDistance);

            //search if there are matches with the new/collapsed items
            totalMatches = shapes.GetMatches(collapsedCandyInfo.AlteredCandy).
                Union(shapes.GetMatches(newCandyInfo.AlteredCandy)).Distinct();



            timesRun++;
        }

        state = GameState.None;
        StartCheckForPotentialMatches();
    }
开发者ID:doraoam,项目名称:MatchThreeGame,代码行数:97,代码来源:ShapesManager.cs

示例2: FindMatchesAndCollapse

    private IEnumerator FindMatchesAndCollapse(RaycastHit2D hit2)
    {
        // Get the second item that was part of the swipe
        var hitGo2 = hit2.collider.gameObject;
        shapes.Swap(hitGo, hitGo2);

        // Move the swapped ones
        hitGo.transform.positionTo(Constants.AnimationDuration, hitGo2.transform.position);
        hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
        yield return new WaitForSeconds(Constants.AnimationDuration);

        // Get the matches via the helper methods
        var hitGoMatchesInfo = shapes.GetMatches(hitGo);
        var hitGo2MatchesInfo = shapes.GetMatches(hitGo2);

        var totalMatches = hitGoMatchesInfo.MatchedGlyph.Union(hitGo2MatchesInfo.MatchedGlyph).Distinct();

        // If the swap did not create at least a 3-match, undo the swap
        if (totalMatches.Count() < Constants.MinimumMatches)
        {
            hitGo.transform.positionTo(Constants.AnimationDuration, hitGo2.transform.position);
            hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
            yield return new WaitForSeconds(Constants.AnimationDuration);

            shapes.UndoSwap();
        }

        // If more than 3 matches and no Bonus is contained in the line, award a new Bonus
        bool addBonus = totalMatches.Count() >= Constants.MinimumMatchesForBonus &&
            !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGoMatchesInfo.BonusesContained) &&
            !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGo2MatchesInfo.BonusesContained);

        Shape hitGoCache = null;
        if (addBonus)
        {
            hitGoCache = new Shape();

            // Get the game object that was of the same type
            var sameTypeGo = hitGoMatchesInfo.MatchedGlyph.Count() > 0 ? hitGo : hitGo2;
            var shape = sameTypeGo.GetComponent<Shape>();

            // Cache the game object
            hitGoCache.Assign(shape.Type, shape.Row, shape.Column);
        }

        int timesRun = 1;
        bool validTurn = false;
        while (totalMatches.Count() >= Constants.MinimumMatches)
        {
            // Increase score
            IncreaseScore((totalMatches.Count() - 2) * Constants.Match3Score);

            if (timesRun >= 2)
            {
                IncreaseScore(Constants.SubsequentMatchScore);
            }

            // Set turn as valid
            if (totalMatches.Count() >= 3)
            {
                validTurn = true;
            }

            foreach (var item in totalMatches)
            {
                shapes.Remove(item);
                RemoveFromScene(item);
            }

            // Check and instantiate Bonus if needed
            if (addBonus)
            {
                CreateBonus(hitGoCache);
            }

            addBonus = false;

            // Get the columns that have a collapse
            var columns = totalMatches.Select(go => go.GetComponent<Shape>().Column).Distinct();

            // The order the two methods below get called is important

            // Collapse the ones gone
            var collapsedGlyphInfo = shapes.Collapse(columns);

            // Create new ones
            var newGlyphInfo = CreateNewGlyphsInSpecificColumns(columns);

            int maxDistance = Mathf.Max(collapsedGlyphInfo.MaxDistance, newGlyphInfo.MaxDistance);

            MoveAndAnimate(newGlyphInfo.AlteredGlyph, maxDistance);
            MoveAndAnimate(collapsedGlyphInfo.AlteredGlyph, maxDistance);

            // Wait for both of the above animations
            yield return new WaitForSeconds(Constants.MoveAnimationMinDuration * maxDistance);

            // Search if there are matches with the new/collapsed items
            totalMatches = shapes.GetMatches(collapsedGlyphInfo.AlteredGlyph).
                Union(shapes.GetMatches(newGlyphInfo.AlteredGlyph)).Distinct();

//.........这里部分代码省略.........
开发者ID:Tlmader,项目名称:glyphic-heroes,代码行数:101,代码来源:ShapesManager.cs


注:本文中的Shape.Assign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。