예제 #1
0
    public void Create()
    {
        //テクスチャのスライス
        TextureSlicer slice = new TextureSlicer();

        texture = slice.createReadableTexture2D(texture);
        slice.Slice_Sprite(texture, new Vector2Int(1, 1));

        Vector2Int range;   //テクスチャの1マスグリッドのうち連続で透明ではないところの範囲(x, 始点 / y, 終点)
        Sprite     sprite;  //タイル一枚のスプライト
        Vector2Int size;    //rangeのサイズ
        Vector2    offset;  //rangeの位置

        //縦に切るとき
        tiles = new Tile[texture.width];
        //縦一列のうち、透明になっていない範囲を取得
        for (int x = 0; x < texture.width; x++)
        {
            range = new Vector2Int(-1, -1);
            for (int y = 0; y < texture.height; y++)
            {
                if (slice.Is_Tranceparent(texture, new Vector2Int(x, y), 0.01f))
                {
                    if (range.y == -1 && range.x != -1)
                    {
                        range.y = y;
                    }
                }
                else if (range.x == -1)
                {
                    range.x = y;
                }
            }
            //すべて透明の時
            if (range.x == -1)
            {
                range = new Vector2Int(0, 0);
            }
            //すべて透明じゃないとき
            if (range.y == -1)
            {
                range = new Vector2Int(0, texture.height);
            }

            sprite   = slice.Slice_Sprite(texture, new Vector2Int(1, texture.height))[x];
            size     = new Vector2Int(1, range.y - range.x);
            offset   = new Vector2(x, range.x + size.y / 2.0f) - center;
            tiles[x] = new Tile(this, sprite, offset, size, x);
            tiles[x].Create();
            Attach_Collision(tiles[x]);
        }
    }
예제 #2
0
    //箱を開ける
    private IEnumerator Open_Cor()
    {
        //効果音
        GetComponent <AudioSource>().Play();
        //画像をスライスして、アニメーション再生する
        SpriteRenderer _sprite   = GetComponent <SpriteRenderer>();
        TextureSlicer  tex_Slice = new TextureSlicer();

        Sprite[] sprites     = tex_Slice.Slice_Sprite(option_Box_Texture, new Vector2Int(35, 26));
        int      start_Index = 5 * (int)kind;

        for (int i = start_Index; i < start_Index + 5; i++)
        {
            _sprite.sprite = sprites[i];
            yield return(new WaitForSeconds(0.08f));
        }
        //オプションを出す
        if (kind == Kind.random)
        {
            PlayerManager.Option po = new PlayerManager.Option();
            do
            {
                int r = Random.Range(0, 4);
                switch (r)
                {
                case 0: po = PlayerManager.Option.bee; break;

                case 1: po = PlayerManager.Option.butterfly; break;

                case 2: po = PlayerManager.Option.mantis; break;

                case 3: po = PlayerManager.Option.spider; break;
                }
            } while (po == PlayerManager.Instance.Get_Option());
            transform.GetChild(0).GetComponent <OptionItem>().option = po;
        }
        transform.GetChild(0).gameObject.SetActive(true);
        transform.GetChild(0).SetParent(null);
    }