コード例 #1
0
    private static IEnumerator ReplaceMeasure(Transform measure, bool isBonusLevel)
    {
        uint level = LevelsCompleted - 1;

        SpriteRenderer sr = measure.GetComponentInChildren <SpriteRenderer>();

        float startWidth  = (sr.sprite.texture.width / (100f)) * (measure.localScale.x * sr.transform.localScale.x);
        float startHeight = (sr.sprite.texture.height / (100f)) * (measure.localScale.y * sr.transform.localScale.y);

        Vector2 startSize     = new Vector2(startWidth, startHeight);
        Vector3 startPosition = sr.gameObject.transform.position;

        // Swap out old sprite renderer for new one
        Texture2D newText;

        switch (Version)
        {
        case GameVersion.T.Integrated:
            newText = Instance.LevelList[level].measure;
            break;

        case GameVersion.T.NotIntegrated:
            float meanSize = (startSize.x + startSize.y) / 2;
            startSize = new Vector2(meanSize, meanSize);     // Comic tiles are square
            newText   = Instance.LevelList[level].comic;
            break;

        default:
            Debug.Log("Invalid Version");
            newText = Instance.LevelList[level].comic;
            break;
        }

        GameObject     newGo = SpriteUtil.AddSprite(newText, startSize, startPosition, "Temp", Instance.transform.parent);
        SpriteRenderer newSr = newGo.GetComponent <SpriteRenderer>();

        float t;
        float currentTime = 0f;
        float moveTime    = Instance.TextureSwapTime;

        while (currentTime <= moveTime)
        {
            t           = currentTime / moveTime;
            sr.color    = new Color(1f, 1f, 1f, 1f - t);
            newSr.color = new Color(1f, 1f, 1f, t);
            yield return(new WaitForEndOfFrame());

            currentTime += Time.deltaTime;
        }

        Destroy(measure.gameObject);
        newSr.color = new Color(1f, 1f, 1f, 1f);

        Instance.StartCoroutine(ShrinkIntoPlace(level, newSr, newGo, startSize, isBonusLevel));

        if (!isBonusLevel)
        {
            Instance.StartCoroutine(PlayMusic());
        }
    }
コード例 #2
0
    private List <GameObject> FillWithTextures(GameObject obj, Texture2D[] textures)
    {
        BoxCollider2D     box = obj.GetComponent <BoxCollider2D>();
        List <GameObject> ret = new List <GameObject>();

        float xmin = box.bounds.center.x - box.bounds.extents.x;
        float xmax = box.bounds.center.x + box.bounds.extents.x;
        float ymin = box.bounds.center.y - box.bounds.extents.y;
        float ymax = box.bounds.center.y + box.bounds.extents.y;

        float xInc   = (xmax - xmin) / 2;
        float xLeft  = xmin;
        float margin = 0.1f;

        float yInc    = (ymax - ymin) / 2;
        float yBottom = ymin;

        if (textures.Length < 4)
        {
            // "Centering"
            ymin += 0.5f * yInc;
        }

        bool movingRight = true;

        foreach (Texture2D t in textures)
        {
            float      xRight    = xLeft + xInc;
            float      yTop      = yBottom + yInc;
            float      midX      = (xRight + xLeft) / 2;
            float      midY      = (yTop + yBottom) / 2;
            Vector2    size      = new Vector2((1f - margin) * (xRight - xLeft), (1f - margin) * (yTop - yBottom));
            Vector3    pos       = new Vector3(midX, midY, this.transform.position.z - TextureOffset);
            GameObject spriteObj = SpriteUtil.AddSprite(t, size, pos, t.name, obj, true);
            spriteObj.GetComponent <SpriteRenderer>().sortingLayerName = "Bonus";
            spriteObj.GetComponent <SpriteRenderer>().sortingOrder     = 5;
            ret.Add(spriteObj);

            if (movingRight)
            {
                // On iterations 0 and 2, move to the right
                xLeft      += xInc;
                movingRight = false;
            }
            else
            {
                // On iteration 1, move left and down
                xLeft      -= xInc;
                yBottom    += yInc;
                movingRight = true;
            }
        }

        return(ret);
    }
コード例 #3
0
    private static void AddLevelListItem(uint i, LevelListItem item)
    {
        uint    row, col;
        Vector3 center, comicOffset, measureOffset, headerOffset;
        Vector3 comicBgPos, measureBgPos, comicTilePos, measureTilePos, headerPos;
        Vector2 comicBgSize, measureBgSize, comicTileSize, measureTileSize, totalSize;

        row = i / Instance.LevelsPerLine;
        col = i % Instance.LevelsPerLine;

        comicBgSize     = ComicBgSize();
        comicTileSize   = ComicTileSize(comicBgSize);
        measureBgSize   = MeasureBgSize(row);
        measureTileSize = MeasureTileSize(measureBgSize);
        totalSize       = TotalSize(row);

        center        = LLICenterPosition(row, col);
        comicOffset   = ComicOffset(totalSize, comicBgSize);
        measureOffset = MeasureOffset(totalSize, measureBgSize);
        headerOffset  = HeaderOffset(totalSize, comicBgSize);

        comicBgPos     = center + comicOffset + BgOffset;
        comicTilePos   = center + comicOffset;
        measureBgPos   = center + measureOffset + BgOffset;
        measureTilePos = center + measureOffset;
        headerPos      = center + headerOffset;

        GameObject parent = new GameObject(string.Format("Level {0}", i + 1));

        parent.transform.parent   = Instance.transform;
        parent.transform.position = center;
        Objects[i].parent         = parent;

        Objects[i].comicBg = SpriteUtil.AddSprite(Instance.ComicBackground, comicBgSize, comicBgPos,
                                                  string.Format("Comic Background {0}", i + 1), parent);

        Objects[i].comicTile = SpriteUtil.AddSprite(ComicTexture(item, i), comicTileSize, comicTilePos,
                                                    string.Format("Comic Tile {0}", i + 1), parent);

        Objects[i].measureBg = SpriteUtil.AddSprite(Instance.MeasureBackground, measureBgSize, measureBgPos,
                                                    string.Format("Measure Background {0}", i + 1), parent);

        Objects[i].measureTile = SpriteUtil.AddSprite(MeasureTexture(item, i), measureTileSize, measureTilePos,
                                                      string.Format("Measure Tile {0}", i + 1), parent);

        Objects[i].header = AddHeader(parent, i + 1, headerPos);

        GameObject audioObject = new GameObject(string.Format("Audio Source {0}", i + 1));

        audioObject.transform.parent = parent.transform;

        AudioSource audioSource = audioObject.AddComponent <AudioSource>();

        Objects[i].audioSource = audioSource;
        AudioClip clip;

        if (MeasureIsLocked(i))
        {
            clip = Instance.LockedClip;
        }
        else
        {
            clip = item.clip;
        }
        Objects[i].audioPlayer = new AudioPlayer(clip, audioSource);
    }