public void UpdateValues(AbstractWinCondition condition)
    {
        if (label == null)
        {
            label = GetComponent <UILabel>();
            if (brothers != null && brothers.Length > 1)
            {
                deactivateOffset = (brothers[0].parent.localPosition.x - brothers[1].parent.localPosition.x) * 0.5f;
            }
        }

        WinDestroyTiles winCondition = (condition as WinDestroyTiles);

        if (!label.enabled)
        {
            UpdateBrothers(deactivateOffset);
        }

        if (winCondition == null || (winCondition as WinDestroyTilesSnow) != null || winCondition.destroyTiles.Length <= destroyTilesIndex)
        {
            myTexture.gameObject.SetActive(false);
            label.enabled = false;
            UpdateBrothers(-deactivateOffset);
            return;
        }

        myTexture.gameObject.SetActive(true);
        label.enabled = true;

        DestroyTilesPair destroyTiles = winCondition.destroyTiles[destroyTilesIndex];

        myTexture.mainTexture = destroyTiles.type.transform.Find("Model").renderer.sharedMaterial.mainTexture;

        string key = "Level" + Match3BoardRenderer.levelIdx + "Destroy" + destroyTilesIndex;

        if (TweaksSystem.Instance.intValues.ContainsKey(key))
        {
            label.text = TweaksSystem.Instance.intValues[key].ToString();
        }
        else
        {
            label.text = destroyTiles.number.ToString();
        }
    }
示例#2
0
    void Start()
    {
        winCondition = (gameLogic.winConditions as WinDestroyTiles);

        if (winCondition == null)
        {
            Destroy(transform.parent.parent.gameObject);
            return;
        }

        if (winCondition.destroyTiles.Length <= destroyTilesIndex)
        {
            if (brothers != null && brothers.Length > 1)
            {
                deactivateOffset = (brothers[0].parent.localPosition.x - brothers[1].parent.localPosition.x) * 0.5f;
                UpdateBrothers(-deactivateOffset);
            }

            Destroy(transform.parent.gameObject);
            return;
        }

        if (targetScore != null)
        {
            targetScore.SetActive(false);
        }

        destroyTiles = winCondition.destroyTiles[destroyTilesIndex];

        myTexture.mainTexture = destroyTiles.type.transform.Find("Model").renderer.sharedMaterial.mainTexture;

        label = GetComponent <UILabel>();

//		Debug.LogWarning("Destroy tiles start: " + label.text);
        StartCoroutine("UpdateValues");

        Match3Tile.OnAnyTileDestroyed      += OnTilesDestroyed;
        SnowTile.OnSnowWinDestroyCondition += OnTilesDestroyed;
    }
	void Start () 
	{
		winCondition = (gameLogic.winConditions as WinDestroyTiles);
		
		if (winCondition == null) {
			Destroy(transform.parent.parent.gameObject);
			return;
		}
		
		if (winCondition.destroyTiles.Length <= destroyTilesIndex) 
		{
			if (brothers != null && brothers.Length > 1) {
				deactivateOffset = (brothers[0].parent.localPosition.x - brothers[1].parent.localPosition.x) * 0.5f;
				UpdateBrothers(-deactivateOffset);
			}
			
			Destroy(transform.parent.gameObject);
			return;
		}
		
		if (targetScore != null) {
			targetScore.SetActive(false);
		}
		
		destroyTiles = winCondition.destroyTiles[destroyTilesIndex];
		
		myTexture.mainTexture = destroyTiles.type.transform.Find("Model").renderer.sharedMaterial.mainTexture;
		
		label = GetComponent<UILabel>();
		
//		Debug.LogWarning("Destroy tiles start: " + label.text);
		StartCoroutine("UpdateValues");
		
		Match3Tile.OnAnyTileDestroyed += OnTilesDestroyed;
		SnowTile.OnSnowWinDestroyCondition += OnTilesDestroyed;
	}
    /// <summary>
    /// Initializes the random generic colors list from the <see cref="RuleEntry"/> class to allow
    /// <see cref="TileSpawnRule"/> classes to correctly pick unique random generic colors each time the level is restarted.
    /// </summary>
    public void InitializeRandomGenericColors()
    {
        // Get the needed colors from the win condition
        List <TileColorType> neededColors = new List <TileColorType>();
        WinDestroyTiles      winDestroy   = winConditions as WinDestroyTiles;

        if (winDestroy)
        {
            foreach (DestroyTilesPair pair in winDestroy.destroyTiles)
            {
                if (pair.type.TileColor != TileColorType.None)
                {
                    neededColors.Add(pair.type.TileColor);
                }
            }
        }

        // Init colors bag with all colors.
        List <TileColorType> allColors = new List <TileColorType>((int)TileColorType.Count - 1);

        for (int i = 1; i < (int)TileColorType.Count; i++)
        {
            if (neededColors.Contains((TileColorType)i))
            {
                allColors.Insert(0, (TileColorType)i);
            }
            else
            {
                allColors.Add((TileColorType)i);
            }
        }


        // Shuffle the colors list.
        for (int i = 0; i < allColors.Count; i++)
        {
            int randomIdx;
            if (i < neededColors.Count)
            {
                randomIdx = Random.Range(0, neededColors.Count);
            }
            else
            {
                randomIdx = Random.Range(neededColors.Count, allColors.Count);
            }
            // Switch current color position to new randomIdx.
            TileColorType curColor = allColors[i];
            allColors[i]         = allColors[randomIdx];
            allColors[randomIdx] = curColor;
        }

        // Initialize the generic colors list
        for (int i = 0; i < (int)GenericColorType.Count; i++)
        {
            RuleEntry.genericColors[i] = allColors[i];
        }

        if (OnRandomGenericColorInitialized != null)
        {
            OnRandomGenericColorInitialized();
        }
    }