Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        piecePrefabDict = new Dictionary <PieceType, GameObject>();

        for (int i = 0; i < piecePrefabs.Length; i++)
        {
            if (!piecePrefabDict.ContainsKey(piecePrefabs[i].type))
            {
                piecePrefabDict.Add(piecePrefabs[i].type, piecePrefabs[i].prefab);
            }
        }

        backgroundPieces = new BackgroundPiece[xDim, yDim];
        for (int x = 0; x < xDim; x++)
        {
            for (int y = 0; y < yDim; y++)
            {
                GameObject newObject = (GameObject)Instantiate(backgroundPrefab, GetWorldPosition(x, y), Quaternion.identity);
                backgroundPieces[x, y] = newObject.GetComponent <BackgroundPiece>();
                backgroundPieces[x, y].Init(x, y, this);
                backgroundPieces[x, y].transform.parent = transform;
            }
        }

        pieces = new GamePiece[xDim, yDim];
        for (int x = 0; x < xDim; x++)
        {
            for (int y = 0; y < yDim; y++)
            {
                SpawnNewPiece(x, y, PieceType.EMPTY);
            }
        }
    }
Ejemplo n.º 2
0
    public void highlightBackground(BackgroundPiece aPiece)
    {
        // find which piece this is

        SpriteRenderer aRender  = aPiece.GetComponent <SpriteRenderer>();
        Color          newColor = new Color(1.0f, 0.0f, 0.0f, 0.5f);

        aRender.color = newColor;
    }
Ejemplo n.º 3
0
    IEnumerator LoadBackgroundAsync(BackgroundPiece piece)
    {
        piece.loading = true;
        var bundleRequest = AssetBundle.LoadFromFileAsync(Application.streamingAssetsPath + "/background/backgroundsplit-" + piece.x + "-" + piece.y + ".normal");

        yield return(bundleRequest);

        var bundle = bundleRequest.assetBundle;

        if (bundle == null)
        {
            Debug.Log("Fail to Load Bundle");
            yield break;
        }
        var bgTextureRequest = bundle.LoadAssetAsync <Texture2D>(piece.resName);

        yield return(bgTextureRequest);

        var        bgTexture        = bgTextureRequest.asset as Texture2D;
        Sprite     sprite           = Sprite.Create(bgTexture, new Rect(0, 0, bgTexture.width, bgTexture.height), new Vector2(0.5f, 0.5f));
        GameObject backgroundObject = availableBackground.Pop();

        backgroundObject.GetComponent <SpriteRenderer>().sprite = sprite;
        bgTexture = null;

        float initPosX = piece.initialX / 100.0f;
        int   xCount   = Mathf.FloorToInt(cameraTransform.position.x * 100 / backgroundWidth);

        initPosX = initPosX + backgroundWidth / 100.0f * xCount;
        if (initPosX < cameraTransform.position.x - cameraSize.x / 100.0f)
        {
            initPosX += backgroundWidth / 100.0f;
        }
        if (initPosX > cameraTransform.position.x + cameraSize.x / 100.0f)
        {
            initPosX -= backgroundWidth / 100.0f;
        }
        backgroundObject.transform.position = new Vector3(initPosX, piece.initialY / 100.0f, 0);
        bundle.Unload(false);
        piece.shown = true;
        Resources.UnloadUnusedAssets();
    }