コード例 #1
0
ファイル: UIManager.cs プロジェクト: Avatarchik/BlockGame
    public void GiveTip()
    {
        List <GameObject> notPlacedBlocks = new List <GameObject>();

        foreach (GameObject block in GameManager.Instance.activeBlocks)
        {
            if (!block.GetComponent <BlockScript>().bPlaced&& !block.GetComponent <BlockScript>().bTip)
            {
                notPlacedBlocks.Add(block);
            }
        }

        if (notPlacedBlocks.Count == 0)
        {
            return;
        }

        GameObject  randomBlock = notPlacedBlocks[Random.Range(0, notPlacedBlocks.Count)];
        BlockScript bs          = randomBlock.GetComponent <BlockScript>();

        int originalRot = bs.rotIndex;

        while (bs.rotIndex != bs.solutionIndex)
        {
            bs.RotateBlock();
        }

        GameObject tipGO = new GameObject();

        tipGO.name = randomBlock.name;
        tipGO.transform.SetParent(GameObject.Find("Tips").transform);

        foreach (BlockTile bTile in bs.tileList)
        {
            Vector2 tilePos = bs.solutionPos - (bs.rotPos[bs.rotIndex] - bTile.relativePos);

            GameObject tipBlock = Instantiate(Resources.Load("Prefabs/Base Block Square"), new Vector3(tilePos.x, tilePos.y, -1f), Quaternion.identity) as GameObject;
            Destroy(tipBlock.GetComponent <BlockTile>());
            tipBlock.GetComponent <SpriteRenderer>().color            = bs.bColor;
            tipBlock.GetComponent <SpriteRenderer>().sortingLayerName = "grid";
            tipBlock.GetComponent <SpriteRenderer>().sortingOrder     = -1;
            tipBlock.transform.localScale = Vector3.one;
            tipBlock.transform.position   = new Vector3(tilePos.x, tilePos.y, 1);

            tipBlock.transform.SetParent(tipGO.transform);
        }
        bs.bTip = true;

        while (bs.rotIndex != originalRot)
        {
            bs.RotateBlock();
        }
    }