Exemple #1
0
    public void OnItmClick(PuzzleCellBlock objBlock)
    {
        if (currentBlock != null)
        {
            Destroy(currentBlock.gameObject);
        }

        GameObject obj = Instantiate(objBlock.gameObject, Vector3.zero, Quaternion.identity) as GameObject;

        obj.transform.SetParent(transform);
        obj.transform.localPosition = Vector3.zero;
        obj.transform.localScale    = Vector3.one;
        PuzzleCellBlock pzCellBlock = obj.GetComponent <PuzzleCellBlock> ();

        foreach (Transform child in obj.transform)
        {
            PuzzleCell          puzzleCell = child.gameObject.GetComponent <PuzzleCell> ();
            PuzzleCell.CellType cellType   = objBlock.cells.Find(k => k.transform.name == child.name).type;
            pzCellBlock.cells.Add(new PuzzleCellBlock.PuzzleCellBlockType(cellType, child.GetComponent <RectTransform> ()));
        }
        CanvasGroup canvasGroup = obj.AddComponent <CanvasGroup> ();

        canvasGroup.interactable   = false;
        canvasGroup.blocksRaycasts = false;
        currentBlock = obj.GetComponent <RectTransform> ();
    }
Exemple #2
0
    public void OnTargetClick()
    {
        if (currentBlock == null)
        {
            return;
        }
        PuzzleCellBlock   block         = currentBlock.GetComponent <PuzzleCellBlock> ();
        List <PuzzleCell> cellsOnTarget = new List <PuzzleCell> ();

        foreach (PuzzleCellBlock.PuzzleCellBlockType bCell in block.cells)
        {
            float      dist       = Mathf.Infinity;
            PuzzleCell findedCell = null;
            foreach (PuzzleCell puzzleCell in cells)
            {
                if (cellsOnTarget.Contains(puzzleCell))
                {
                    continue;
                }
                float val = Vector2.Distance(bCell.transform.position, puzzleCell.rectTransform.position);
                if (val < dist)
                {
                    dist       = val;
                    findedCell = puzzleCell;
                }
            }

            if (findedCell != null && findedCell.typeCell == bCell.type && findedCell.IsActive &&
                allowInsert(findedCell.rectTransform.eulerAngles.z, bCell.transform.eulerAngles.z, reverseTypes [findedCell.typeCell]))
            {
                cellsOnTarget.Add(findedCell);
            }
            else
            {
                Debug.Log("Inappropriate block");
                return;
            }
        }

        for (int i = 0; i < cellsOnTarget.Count; i++)
        {
            cellsOnTarget [i].GetComponent <Image> ().color = cellColor;
            cellsOnTarget [i].IsActive = false;
        }
        Destroy(currentBlock.gameObject);
    }